Ejemplo n.º 1
0
def test_bareme(x_axis="sali"):
    """
    Use to test and debug bareme mode test-case
    """

    yr = 2012
    # Changes in individualized characteristics
    # salaires: sali
    # retraites: choi
    # intérêts: f2ee intpfl; f2tr intb
    # dividendes: f2da divplf; f2dc divb
    # foncier  f4ba fon (micro foncier f4be)


    maxrev = 500000
    year = 2012
    simulation = ScenarioSimulation()

    # Changes in individualized caracteristics
    # salaires: sali
    # retraites: choi
    # intérêts: f2ee intpfl; f2tr intb
    # dividendes: f2da divplf; f2dc divb
    # foncier  f4ba fon (micro foncier f4be)

    simulation.set_config(year = yr, nmen = 101, x_axis = x_axis, maxrev=maxrev,
                          reforme = False, mode ='bareme', decomp_file="decomp_contrib.xml")
    simulation.set_param()
    # Hack to get rid of missing parameters in 2012
    if yr == 2012:
        complete_2012_param(simulation.P)


    test_case = simulation.scenario

    if SHOW_OPENFISCA:
        app = QApplication(sys.argv)
        win = ApplicationWindow()
        ax = win.mplwidget.axes
        title ="Barème openfisca"
        ax.set_title(title)
        graph_x_axis = simulation.get_varying_revenues(x_axis)
        draw_simulation_bareme(simulation, ax, graph_x_axis = graph_x_axis, legend = True, position = 4)
        win.resize(1400,700)
        win.mplwidget.draw()
        win.show()

    if EXPORT:
        win.mplwidget.print_figure(DESTINATION_DIR + title + '.png')

    if ax:
        del ax
    del simulation
    sys.exit(app.exec_())
Ejemplo n.º 2
0
    def addRow(self):
        noi = len(self._listPerson)
        self._listPerson.append([QLabel('%d' % (noi+1), self),
                                 QDateEdit(self),
                                 QComboBox(self),
                                 QComboBox(self),
                                 QPushButton(self),
                                 QComboBox(self),
                                 QComboBox(self)])
        temp = self._listPerson[-1]

        temp[S.birth].setDisplayFormat(QApplication.translate("Page01", "dd MMM yyyy", None, QApplication.UnicodeUTF8))
        temp[S.birth].setObjectName('Bir%d' % noi)
        temp[S.birth].setCurrentSection(QDateEdit.YearSection)

        temp[S.decpos].setObjectName('Dec%d' % noi)
        temp[S.decpos].addItems(['vous', 'conj', 'pac'])

        temp[S.decnum].setObjectName('Foy%d' % noi)

        temp[S.fampos].setObjectName('Fam%d' % noi)
        temp[S.fampos].addItems(['parent 1', 'parent 2', 'enfant'])

        temp[S.famnum].setObjectName('Fam%d' % noi)

        temp[S.decbtn].setObjectName('But%d' % noi)

        for i in xrange(7):
            self.gridLayout.addWidget(temp[i], noi +2, i)
            self.gridLayout.setAlignment(temp[i], Qt.AlignCenter)


        self.rmv_btn.setEnabled(True)
        if len(self.scenario.indiv) == 9:
            self.add_btn.setEnabled(False)
Ejemplo n.º 3
0
    def addPref(self):
        noi = 0
        self._listPerson.append([
            QLabel('%d' % (noi + 1), self),
            QDateEdit(self),
            QComboBox(self),
            QComboBox(self),
            QPushButton(self),
            QComboBox(self),
            QComboBox(self)
        ])

        temp = self._listPerson[0]

        temp[S.birth].setDisplayFormat(
            QApplication.translate("Page01", "dd MMM yyyy", None,
                                   QApplication.UnicodeUTF8))
        temp[S.birth].setObjectName('Bir%d' % noi)
        temp[S.birth].setCurrentSection(QDateEdit.YearSection)

        temp[S.decpos].setObjectName('Dec%d' % noi)
        temp[S.decpos].addItems(['vous'])
        temp[S.decpos].setEnabled(False)

        temp[S.decnum].setObjectName('Foy%d' % noi)
        temp[S.decnum].setEnabled(False)

        temp[S.fampos].addItems(['parent 1'])
        temp[S.fampos].setObjectName('Fam%d' % noi)
        temp[S.fampos].setEnabled(False)

        temp[S.famnum].setObjectName('Fam%d' % noi)
        temp[S.famnum].setEnabled(False)

        temp[S.decbtn].setObjectName('But%d' % noi)

        for i in xrange(7):
            self.gridLayout.addWidget(temp[i], noi + 2, i)
            self.gridLayout.setAlignment(temp[i], Qt.AlignCenter)

        self.emit(SIGNAL('compoChanged()'))
Ejemplo n.º 4
0
def produce_graph(name="test",
                  apply_reform=False,
                  reforme=False,
                  conj=False,
                  sal_conj=False,
                  kids=0,
                  save_figure=False,
                  destination_dir=None,
                  bareme=True,
                  tax_rates=False,
                  year=2011):

    app = QApplication(sys.argv)
    win = ApplicationWindow()
    ax = win.mplwidget.axes
    simulation = run_simulation(year=year,
                                apply_reform=apply_reform,
                                reforme=reforme,
                                conj=conj,
                                sal_conj=sal_conj,
                                kids=kids)

    if bareme:
        draw_simulation_bareme(simulation, ax, legend=True, position=4)

    if tax_rates:
        draw_simulation_taux(simulation, ax, legend=True)

    win.resize(1400, 700)
    win.mplwidget.draw()
    win.show()

    df = simulation.get_results_dataframe()
    #    print df.to_string()

    if save_figure and destination_dir is not None:
        win.mplwidget.print_figure(os.path.join(destination_dir,
                                                name + '.png'))

    del ax, simulation
Ejemplo n.º 5
0
    def addRow(self):
        noi = len(self._listPerson)
        self._listPerson.append([
            QLabel('%d' % (noi + 1), self),
            QDateEdit(self),
            QComboBox(self),
            QComboBox(self),
            QPushButton(self),
            QComboBox(self),
            QComboBox(self)
        ])
        temp = self._listPerson[-1]

        temp[S.birth].setDisplayFormat(
            QApplication.translate("Page01", "dd MMM yyyy", None,
                                   QApplication.UnicodeUTF8))
        temp[S.birth].setObjectName('Bir%d' % noi)
        temp[S.birth].setCurrentSection(QDateEdit.YearSection)

        temp[S.decpos].setObjectName('Dec%d' % noi)
        temp[S.decpos].addItems(['vous', 'conj', 'pac'])

        temp[S.decnum].setObjectName('Foy%d' % noi)

        temp[S.fampos].setObjectName('Fam%d' % noi)
        temp[S.fampos].addItems(['parent 1', 'parent 2', 'enfant'])

        temp[S.famnum].setObjectName('Fam%d' % noi)

        temp[S.decbtn].setObjectName('But%d' % noi)

        for i in xrange(7):
            self.gridLayout.addWidget(temp[i], noi + 2, i)
            self.gridLayout.setAlignment(temp[i], Qt.AlignCenter)

        self.rmv_btn.setEnabled(True)
        if len(self.scenario.indiv) == 9:
            self.add_btn.setEnabled(False)
Ejemplo n.º 6
0
    def addPref(self):
        noi = 0
        self._listPerson.append([QLabel('%d' % (noi + 1), self),
                                 QDateEdit(self),
                                 QComboBox(self),
                                 QComboBox(self),
                                 QPushButton(self),
                                 QComboBox(self),
                                 QComboBox(self)])

        temp = self._listPerson[0]

        temp[S.birth].setDisplayFormat(QApplication.translate("Page01", "dd MMM yyyy", None, QApplication.UnicodeUTF8))
        temp[S.birth].setObjectName('Bir%d' % noi)
        temp[S.birth].setCurrentSection(QDateEdit.YearSection)

        temp[S.decpos].setObjectName('Dec%d' % noi)
        temp[S.decpos].addItems(['vous'])
        temp[S.decpos].setEnabled(False)

        temp[S.decnum].setObjectName('Foy%d' % noi)
        temp[S.decnum].setEnabled(False)

        temp[S.fampos].addItems(['parent 1'])
        temp[S.fampos].setObjectName('Fam%d' % noi)
        temp[S.fampos].setEnabled(False)

        temp[S.famnum].setObjectName('Fam%d' % noi)
        temp[S.famnum].setEnabled(False)

        temp[S.decbtn].setObjectName('But%d' % noi)

        for i in xrange(7):
            self.gridLayout.addWidget(temp[i], noi + 2, i)
            self.gridLayout.setAlignment(temp[i], Qt.AlignCenter)

        self.emit(SIGNAL('compoChanged()'))
Ejemplo n.º 7
0
def test_case(year):
    """
    Use to test individual test-case for debugging
    """

    app = QApplication(sys.argv)
    win = ApplicationWindow()

    yr = year

    simulation = ScenarioSimulation()
    simulation.set_config(year=yr,
                          nmen=1,
                          reforme=False,
                          mode='castype',
                          decomp_file="decomp_contrib.xml")
    simulation.set_param()

    # Hack to get rid of missing parameters in 2012
    if yr == 2012:
        complete_2012_param(simulation.P)

    test_case = simulation.scenario

    # Changes in individualized caracteristics
    #TRAITEMENTS, SALAIRES, PPE, PENSIONS ET RENTES
    # salaires (case 1AJ)
    test_case.indiv[0].update({"sali": 0})

    # préretraites, chômage (case 1AP)
    test_case.indiv[0].update({"choi": 0})

    # pensions (case 1AS)
    test_case.indiv[0].update({"rsti": 0})

    # Changes in non-individualized items of the declaration
    # REVENUS DES VALEURS ET CAPITAUX MOBILIERS
    # intérêts
    # f2ee intpfl (pdts de placement soumis aux prélèvements obligatoires autres que 2DA et 2DH
    # f2tr intb (intérêts et autres revenus assimilés)
    test_case.declar[0].update({"f2ts": 0})
    test_case.declar[0].update({"f2tr": 0})

    # dividendes
    # f2da divplf (revenus des actions et parts soumis au prélèvement libératoire à 21 %
    # f2dc divb (revenus des actions et parts ouvrant droit à abattement)

    test_case.declar[0].update({"f2da": 0})
    test_case.declar[0].update({"f2dh": 0})

    test_case.declar[0].update({"f2dc": 0})

    # REVENUS FONCIERS
    # foncier  f4ba  (micro foncier f4be)
    test_case.declar[0].update({"f4ba": 0})

    #PLUS-VALUES DE CESSION DE VALEURS MOBILIERES, DROITS SOCIAUX ET GAINS ASSIMILéS
    # plus-values TODO: F3VG

    test_case.declar[0].update({"f3vg": 1000000})

    test_case.declar[0].update({"f3vz": 0})

    df = simulation.get_results_dataframe(index_by_code=True)
    rev_cols = [
        "salsuperbrut", "chobrut", "rstbrut", "fon", "rev_cap_bar",
        "rev_cap_lib"
    ]
    prelev_cols = [
        "cotpat_noncontrib", "cotsal_noncontrib", "csgsald", "csgsali",
        "crdssal", "cotpat_noncontrib", "cotsal_noncontrib", "csgsald",
        "csgsali", "crdssal", "csgchod", "csgchoi", "crdscho", "csgrstd",
        "csgrsti", "crdsrst", "prelsoc_cap_bar", "prelsoc_cap_lib",
        "csg_cap_bar", "csg_cap_lib", "crds_cap_bar", "crds_cap_lib",
        "imp_lib", "ppe", "irpp"
    ]

    rev_df = df.loc[rev_cols]
    rev = rev_df.sum(axis=0)
    prelev_df = df.loc[prelev_cols]
    prelev = prelev_df.sum(axis=0)

    print -prelev / rev
    print rev
    #    print prelev_df, rev, -prelev
    ax = win.mplwidget.axes
    if SHOW_OPENFISCA:
        title = "Mon titre"
        ax.set_title(title)
        draw_simulation_waterfall(simulation, ax)
        win.resize(1400, 700)
        win.mplwidget.draw()
        win.show()
        sys.exit(app.exec_())

    if EXPORT:
        win.mplwidget.print_figure(DESTINATION_DIR + title + '.png')

    del ax, simulation
Ejemplo n.º 8
0
def test_bareme(x_axis="sali"):
    """
    Use to test and debug bareme mode test-case
    """

    yr = 2012
    # Changes in individualized characteristics
    # salaires: sali
    # retraites: choi
    # intérêts: f2ee intpfl; f2tr intb
    # dividendes: f2da divplf; f2dc divb
    # foncier  f4ba fon (micro foncier f4be)

    maxrev = 500000
    year = 2012
    simulation = ScenarioSimulation()

    # Changes in individualized caracteristics
    # salaires: sali
    # retraites: choi
    # intérêts: f2ee intpfl; f2tr intb
    # dividendes: f2da divplf; f2dc divb
    # foncier  f4ba fon (micro foncier f4be)

    simulation.set_config(year=yr,
                          nmen=101,
                          x_axis=x_axis,
                          maxrev=maxrev,
                          reforme=False,
                          mode='bareme',
                          decomp_file="decomp_contrib.xml")
    simulation.set_param()
    # Hack to get rid of missing parameters in 2012
    if yr == 2012:
        complete_2012_param(simulation.P)

    test_case = simulation.scenario

    if SHOW_OPENFISCA:
        app = QApplication(sys.argv)
        win = ApplicationWindow()
        ax = win.mplwidget.axes
        title = "Barème openfisca"
        ax.set_title(title)
        graph_x_axis = simulation.get_varying_revenues(x_axis)
        draw_simulation_bareme(simulation,
                               ax,
                               graph_x_axis=graph_x_axis,
                               legend=True,
                               position=4)
        win.resize(1400, 700)
        win.mplwidget.draw()
        win.show()

    if EXPORT:
        win.mplwidget.print_figure(DESTINATION_DIR + title + '.png')

    if ax:
        del ax
    del simulation
    sys.exit(app.exec_())
Ejemplo n.º 9
0
from openfisca_qt.widgets.matplotlibwidget import MatplotlibWidget


class ApplicationWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.mplwidget = MatplotlibWidget(self)
        self.mplwidget.setFocus()
        self.setCentralWidget(self.mplwidget)


destination_dir = "c:/users/utilisateur/documents/test_enfant/"

if __name__ == '__main__':

    app = QApplication(sys.argv)
    win = ApplicationWindow()

    yr = 2010

    marginal = True

    for n_enf_final in range(1, 5):
        if n_enf_final == 1:
            title = str(n_enf_final) + ' enfant'
            if marginal:
                title = str(n_enf_final) + 'er enfant'
        else:
            title = str(n_enf_final) + ' enfants'
            if marginal:
                title = str(n_enf_final) + 'e enfant'
Ejemplo n.º 10
0
def test_case(year):
    """
    Use to test individual test-case for debugging
    """

    app = QApplication(sys.argv)
    win = ApplicationWindow()

    yr = year


    simulation = ScenarioSimulation()
    simulation.set_config(year = yr, nmen = 1, reforme = False, mode ='castype', decomp_file="decomp_contrib.xml")
    simulation.set_param()

    # Hack to get rid of missing parameters in 2012
    if yr == 2012:
        complete_2012_param(simulation.P)

    test_case = simulation.scenario

    # Changes in individualized caracteristics
    #TRAITEMENTS, SALAIRES, PPE, PENSIONS ET RENTES
    # salaires (case 1AJ)
    test_case.indiv[0].update({"sali":0})

    # préretraites, chômage (case 1AP)
    test_case.indiv[0].update({"choi":0})

    # pensions (case 1AS)
    test_case.indiv[0].update({"rsti":0})

    # Changes in non-individualized items of the declaration
    # REVENUS DES VALEURS ET CAPITAUX MOBILIERS
    # intérêts
    # f2ee intpfl (pdts de placement soumis aux prélèvements obligatoires autres que 2DA et 2DH
    # f2tr intb (intérêts et autres revenus assimilés)
    test_case.declar[0].update({"f2ts":0})
    test_case.declar[0].update({"f2tr":0})

    # dividendes
    # f2da divplf (revenus des actions et parts soumis au prélèvement libératoire à 21 %
    # f2dc divb (revenus des actions et parts ouvrant droit à abattement)

    test_case.declar[0].update({"f2da":0})
    test_case.declar[0].update({"f2dh":0})

    test_case.declar[0].update({"f2dc":0})

    # REVENUS FONCIERS
    # foncier  f4ba  (micro foncier f4be)
    test_case.declar[0].update({"f4ba":0})


    #PLUS-VALUES DE CESSION DE VALEURS MOBILIERES, DROITS SOCIAUX ET GAINS ASSIMILéS
    # plus-values TODO: F3VG

    test_case.declar[0].update({"f3vg":1000000})


    test_case.declar[0].update({"f3vz":0})



    df = simulation.get_results_dataframe(index_by_code=True)
    rev_cols = ["salsuperbrut", "chobrut", "rstbrut",  "fon", "rev_cap_bar", "rev_cap_lib"]
    prelev_cols = ["cotpat_noncontrib", "cotsal_noncontrib", "csgsald", "csgsali", "crdssal", "cotpat_noncontrib",
              "cotsal_noncontrib", "csgsald", "csgsali", "crdssal",
              "csgchod", "csgchoi", "crdscho",
              "csgrstd", "csgrsti", "crdsrst",
              "prelsoc_cap_bar", "prelsoc_cap_lib", "csg_cap_bar", "csg_cap_lib",
              "crds_cap_bar",  "crds_cap_lib", "imp_lib", "ppe", "irpp" ]

    rev_df = df.loc[rev_cols]
    rev = rev_df.sum(axis=0)
    prelev_df = df.loc[prelev_cols]
    prelev = prelev_df.sum(axis=0)

    print -prelev/rev
    print rev
#    print prelev_df, rev, -prelev
    ax = win.mplwidget.axes
    if SHOW_OPENFISCA:
        title ="Mon titre"
        ax.set_title(title)
        draw_simulation_waterfall(simulation, ax)
        win.resize(1400,700)
        win.mplwidget.draw()
        win.show()
        sys.exit(app.exec_())

    if EXPORT:
        win.mplwidget.print_figure(DESTINATION_DIR + title + '.png')

    del ax, simulation
Ejemplo n.º 11
0

class ApplicationWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.mplwidget = MatplotlibWidget(self)
        self.mplwidget.setFocus()
        self.setCentralWidget(self.mplwidget)


if __name__ == '__main__':

    SAVE = False
    SHOW = True
    destination_dir = u"c:/users/utilisateur/Desktop/Simula"
    app = QApplication(sys.argv)
    win = ApplicationWindow()
    win = ApplicationWindow()

    ax = win.mplwidget.axes

    year = 2011

    simulation = ScenarioSimulation()
    simulation.set_config(year = year, nmen = 101,
                    x_axis = 'sali', maxrev = 50000,
                    mode ='bareme', same_rev_couple = False)
    simulation.set_param()

#    draw_simulation_bareme(simulation, ax, legend = True, position = 4)
    draw_simulation_taux(simulation, ax, legend=True)