Exemplo n.º 1
0
    def saveCsv(self):
        output_dir = CONF.get('paths', 'output_dir')
        user_path = os.path.join(output_dir, 'sans-titre.csv')

        fname = QFileDialog.getSaveFileName(self,
                                               u"Exporter la table", user_path, u"CSV (séparateur: point virgule) (*.csv)")
        
        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                now = datetime.now()
                csvfile = open(fname, 'wb')
                writer = UnicodeWriter(csvfile, dialect= csv.excel, delimiter=';')
                writer.writerow([u'OpenFisca'])
                writer.writerow([u'Calculé le %s à %s' % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))])
                writer.writerow([u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')])
                writer.writerow([])
                
                for row in self.data:
                    if not row.desc in ('root'):
                        outlist = [row.desc]
                        for val in row.vals:
                            outlist.append(locale.str(val))
                        writer.writerow(outlist)
                csvfile.close()                
            except Exception, e:
                QMessageBox.critical(
                    self, "Error saving file", str(e),
                    QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 2
0
    def __init__(self, model_description, survey_data = None, scenario = None):
        super(DataTable, self).__init__()

        # Init instance attribute
        self.description = None
        self.scenario = None
        self._isPopulated = False
        self.col_names = []
        self.table = DataFrame()
        self.index = {}
        self._nrows = 0

        self.datesim = CONF.get('simulation', 'datesim')

        self.NMEN = CONF.get('simulation', 'nmen')
        self.MAXREV = CONF.get('simulation', 'maxrev')
        self.XAXIS = CONF.get('simulation', 'xaxis') + 'i'
        
        # Build the description attribute        
        if type(model_description) == type(ModelDescription):
            descr = model_description()
            self.description = Description(descr.columns)
        else:
            raise Exception("model_description should be an ModelDescription inherited class")

        self.col_names = self.description.col_names

        if (survey_data and scenario):
            raise Exception("should provide either survey_data or scenario but not both")
        elif survey_data:
            self.populate_from_survey_data(survey_data)
        elif scenario:
            self.populate_from_scenario(scenario)
Exemplo n.º 3
0
 def set_date(self, date=None):
     if date == None:
         self._date = CONF.get('simulation', 'datesim')
     else:
         self._date = date
         CONF.set('simulation', 'datesim',str(self._date))
     print self._date
Exemplo n.º 4
0
 def set_date(self, date=None):
     if date == None:
         self._date = CONF.get('simulation', 'datesim')
     else:
         self._date = date
         CONF.set('simulation', 'datesim', str(self._date))
     print self._date
Exemplo n.º 5
0
    def save_figure(self, *args):
        filetypes = self.mplwidget.get_supported_filetypes_grouped()
        sorted_filetypes = filetypes.items()
        sorted_filetypes.sort()
        default_filetype = self.mplwidget.get_default_filetype()
        output_dir = CONF.get('paths', 'output_dir')
        start = os.path.join(output_dir, 'image.') + default_filetype
        filters = []
        selectedFilter = None
        for name, exts in sorted_filetypes:
            exts_list = " ".join(['*.%s' % ext for ext in exts])
            filtre = '%s (%s)' % (name, exts_list)
            if default_filetype in exts:
                selectedFilter = filtre
            filters.append(filtre)
        filters = ';;'.join(filters)

        fname = QFileDialog.getSaveFileName(self, "Enregistrer l'image", start,
                                            filters, selectedFilter)

        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                self.mplwidget.print_figure(unicode(fname))
            except Exception, e:
                QMessageBox.critical(self, "Erreur en enregistrant le fichier",
                                     str(e), QMessageBox.Ok,
                                     QMessageBox.NoButton)
Exemplo n.º 6
0
    def save_figure(self, *args):
        filetypes = self.mplwidget.get_supported_filetypes_grouped()
        sorted_filetypes = filetypes.items()
        sorted_filetypes.sort()
        default_filetype = self.mplwidget.get_default_filetype()
        output_dir = CONF.get('paths', 'output_dir')
        start = os.path.join(output_dir, 'image.') + default_filetype
        filters = []
        selectedFilter = None
        for name, exts in sorted_filetypes:
            exts_list = " ".join(['*.%s' % ext for ext in exts])
            filtre = '%s (%s)' % (name, exts_list)
            if default_filetype in exts:
                selectedFilter = filtre
            filters.append(filtre)
        filters = ';;'.join(filters)

        fname = QFileDialog.getSaveFileName(
            self, "Enregistrer l'image", start, filters, selectedFilter)


        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                self.mplwidget.print_figure( unicode(fname) )
            except Exception, e:
                QMessageBox.critical(
                    self, "Erreur en enregistrant le fichier", str(e),
                    QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 7
0
    def save_table(self, table_format=None):

        if table_format is None:
            table_format = CONF.get('paths', 'table')

        output_dir = CONF.get('paths', 'output_dir')
        filename = 'sans-titre.' + table_format
        user_path = os.path.join(output_dir, filename)

        extension = table_format.upper() + "   (*." + table_format + ")"
        fname = QFileDialog.getSaveFileName(self, u"Exporter la table",
                                            user_path, extension)

        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                if table_format == "xls":
                    writer = ExcelWriter(str(fname))
                    df = self.create_dataframe()
                    descr = self.create_description()
                    df.to_excel(writer, "table", index=True, header=False)
                    descr.to_excel(writer,
                                   "description",
                                   index=False,
                                   header=False)
                    writer.save()
                elif table_format == "csv":
                    # TODO: use DataFrame's ?
                    now = datetime.now()
                    csvfile = open(fname, 'wb')
                    writer = UnicodeWriter(csvfile,
                                           dialect=csv.excel,
                                           delimiter=';')

                    for row in self.data:
                        if not row.desc in ('root'):
                            outlist = [row.desc]
                            for val in row.vals:
                                outlist.append(locale.str(val))
                            writer.writerow(outlist)

                    writer.writerow([u'OpenFisca'])
                    writer.writerow([
                        u'Calculé le %s à %s' %
                        (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))
                    ])
                    writer.writerow([
                        u'Système socio-fiscal au %s' %
                        CONF.get('simulation', 'datesim')
                    ])
                    writer.writerow([])

                    csvfile.close()

            except Exception, e:
                QMessageBox.critical(self, "Error saving file", str(e),
                                     QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 8
0
    def set_openfica_root_dir(self, directory = None):
        '''
        Sets the directory where to find the openfisca source and adjust some directories
        TODO à améliorer
        '''
        if directory == None:
#            self.openfica_root_dir = "C:/Users/Utilisateur/My Documents/Aptana Studio 3 Workspace/web/srcopen"
            self.openfica_root_dir = "/home/florent/workspace/openfisca/srcopen/"
        else:
            self.openfica_root_dir = directory    
        
        CONF.set('paths', 'data_dir',os.path.join(self.openfica_root_dir,'data'))
Exemplo n.º 9
0
    def set_config(self, directory = None, nmen=1):
        '''
        Sets the directory where to find the openfisca source and adjust some directories
        '''
        if directory == None:
#   TODO REMOVE         dir = "C:/Users/Utilisateur/My Documents/Aptana Studio 3 Workspace/web/srcopen"
#            dir = "/home/florent/workspace/openfisca/srcopen/"
            cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
            predirectory = os.path.dirname(cmd_folder)
            directory = os.path.join(predirectory,'srcopen')

        CONF.set('paths', 'data_dir',os.path.join(directory,'data'))
        CONF.set('simulation', 'nmen',1)
Exemplo n.º 10
0
 def loadXml(self):
     reformes_dir = CONF.get('paths', 'reformes_dir')
     fileName = QFileDialog.getOpenFileName(self,
                                            u"Ouvrir une réforme", reformes_dir, u"Paramètres OpenFisca (*.ofp)")
     if not fileName == '':
         try: 
             loader = XmlReader(str(fileName))
             CONF.set('simulation', 'datesim',str(loader._date))
             self.initialize()
             self._rootNode.load(loader.tree)
             self.changed()
         except Exception, e:
             QMessageBox.critical(
                 self, "Erreur", u"Impossible de lire le fichier : " + str(e),
                 QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 11
0
    def set_config(self, directory=None, nmen=1):
        '''
        Sets the directory where to find the openfisca source and adjust some directories
        '''
        if directory == None:
            #   TODO REMOVE         dir = "C:/Users/Utilisateur/My Documents/Aptana Studio 3 Workspace/web/srcopen"
            #            dir = "/home/florent/workspace/openfisca/srcopen/"
            cmd_folder = os.path.realpath(
                os.path.abspath(
                    os.path.split(inspect.getfile(inspect.currentframe()))[0]))
            predirectory = os.path.dirname(cmd_folder)
            directory = os.path.join(predirectory, 'srcopen')

        CONF.set('paths', 'data_dir', os.path.join(directory, 'data'))
        CONF.set('simulation', 'nmen', 1)
Exemplo n.º 12
0
    def set_config(self, directory = None, nmen = None):
        '''
        Sets the directory where to find the openfisca source and adjust some directories
        '''
        if directory is None:
            cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
            predirectory = os.path.dirname(cmd_folder)
            directory = os.path.join(predirectory,'srcopen')

        CONF.set('paths', 'data_dir', os.path.join(directory,'data'))

        if nmen is None:
            nmen = 1
        
        CONF.set('simulation', 'nmen', nmen)
Exemplo n.º 13
0
    def updateGraph(self,
                    data,
                    reforme=False,
                    mode='bareme',
                    dataDefault=None):
        self.data = data
        self.dataDefault = dataDefault
        self.data.setLeavesVisible()
        self.reforme = reforme
        self.mode = mode
        data['revdisp'].visible = 1
        if self.mode == 'bareme':  # TODO make this country-totals specific
            for rev in ['salsuperbrut', 'salbrut', 'chobrut', 'rstbrut']:
                try:
                    data[rev].setHidden()
                except:
                    pass

            if reforme:
                data.hideAll()

        x_axis = CONF.get('simulation', 'x_axis')
        self.populate_absBox(x_axis, self.mode)
        # TODO really dirty because we should change name of self.x_axis
        for axe in model.x_axes.itervalues():
            if axe.name == x_axis:
                self.x_axis = axe.typ_tot_default
                break
        self.updateGraph2()
Exemplo n.º 14
0
    def updateTable(self, data, reforme, mode, dataDefault):
        '''
        Updates table
        '''

        if dataDefault is None:
            dataDefault = data

        x_axis = CONF.get('simulation', 'x_axis')
        for axe in model.x_axes.itervalues():
            if axe.name == x_axis:
                x_axis_typ_tot = axe.typ_tot_default
                break

        headers = dataDefault[x_axis_typ_tot]
        n = len(headers.vals)
        self.data = data
        self.outputModel = OutputModel(data, headers, n , self)
        self.treeView.setModel(self.outputModel)
        self.treeView.expandAll()
        self.treeView.setColumnWidth(0, 200)
        if mode == 'bareme':
            for i in range(n):
                self.treeView.resizeColumnToContents(i+1)
        else:
            self.treeView.setColumnWidth(1,100)
Exemplo n.º 15
0
    def updateTable(self, data, reforme, mode, dataDefault):
        '''
        Updates table
        '''

        if dataDefault is None:
            dataDefault = data

        x_axis = CONF.get('simulation', 'x_axis')
        for axe in model.x_axes.itervalues():
            if axe.name == x_axis:
                x_axis_typ_tot = axe.typ_tot_default
                break

        headers = dataDefault[x_axis_typ_tot]
        n = len(headers.vals)
        self.data = data
        self.outputModel = OutputModel(data, headers, n, self)
        self.treeView.setModel(self.outputModel)
        self.treeView.expandAll()
        self.treeView.setColumnWidth(0, 200)
        if mode == 'bareme':
            for i in range(n):
                self.treeView.resizeColumnToContents(i + 1)
        else:
            self.treeView.setColumnWidth(1, 100)
Exemplo n.º 16
0
    def updateGraph(self, data, reforme = False, mode = 'bareme', dataDefault = None):
        self.data = data
        self.dataDefault = dataDefault
        self.data.setLeavesVisible()
        self.reforme = reforme
        self.mode = mode
        data['revdisp'].visible = 1
        if self.mode == 'bareme':    # TODO make this country-totals specific
            for rev in ['salsuperbrut', 'salbrut', 'chobrut', 'rstbrut']:
                try:
                    data[rev].setHidden()
                except:
                    pass

            if reforme:
                data.hideAll()

        x_axis = CONF.get('simulation', 'x_axis')
        self.populate_absBox(x_axis, self.mode)
        # TODO really dirty because we should change name of self.x_axis
        for axe in model.x_axes.itervalues():
            if axe.name == x_axis:
                self.x_axis = axe.typ_tot_default
                break
        self.updateGraph2()
Exemplo n.º 17
0
    def set_config(self, directory=None, nmen=None):
        '''
        Sets the directory where to find the openfisca source and adjust some directories
        '''
        #        if directory is None:
        #            cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
        #            predirectory = os.path.dirname(cmd_folder)
        #            directory = os.path.join(predirectory,'../../srcopen')
        #
        #
        #        CONF.set('paths', 'data_dir', os.path.join(directory,'data'))

        if nmen is None:
            nmen = 1

        CONF.set('simulation', 'nmen', nmen)
Exemplo n.º 18
0
    def save_table(self, table_format = None):

        if table_format is None:
            table_format = CONF.get('paths', 'table')

        output_dir = CONF.get('paths', 'output_dir')
        filename = 'sans-titre.' + table_format
        user_path = os.path.join(output_dir, filename)

        extension = table_format.upper() + "   (*." + table_format + ")"
        fname = QFileDialog.getSaveFileName(self,
                                               u"Exporter la table", user_path, extension)

        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                if table_format == "xls":
                    writer = ExcelWriter(str(fname))
                    df = self.create_dataframe()
                    descr = self.create_description()
                    df.to_excel(writer, "table", index=True, header= False)
                    descr.to_excel(writer, "description", index = False, header=False)
                    writer.save()
                elif table_format =="csv":
                    # TODO: use DataFrame's ?
                    now = datetime.now()
                    csvfile = open(fname, 'wb')
                    writer = UnicodeWriter(csvfile, dialect= csv.excel, delimiter=';')

                    for row in self.data:
                        if not row.desc in ('root'):
                            outlist = [row.desc]
                            for val in row.vals:
                                outlist.append(locale.str(val))
                            writer.writerow(outlist)

                    writer.writerow([u'OpenFisca'])
                    writer.writerow([u'Calculé le %s à %s' % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))])
                    writer.writerow([u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')])
                    writer.writerow([])

                    csvfile.close()

            except Exception, e:
                QMessageBox.critical(
                    self, "Error saving file", str(e),
                    QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 19
0
def gen_output_data(model):
    data_dir = CONF.get("paths", "data_dir")
    totals_fname = os.path.join(data_dir, "totaux.xml")
    _doc = minidom.parse(totals_fname)
    tree = OutNode("root", "root")

    handle_output_xml(_doc, tree, model)
    return tree
Exemplo n.º 20
0
 def loadXml(self):
     reformes_dir = CONF.get('paths', 'reformes_dir')
     fileName = QFileDialog.getOpenFileName(
         self, u"Ouvrir une réforme", reformes_dir,
         u"Paramètres OpenFisca (*.ofp)")
     if not fileName == '':
         try:
             loader = XmlReader(str(fileName))
             CONF.set('simulation', 'datesim', str(loader._date))
             self.initialize()
             self._rootNode.load(loader.tree)
             self.changed()
         except Exception, e:
             QMessageBox.critical(
                 self, "Erreur",
                 u"Impossible de lire le fichier : " + str(e),
                 QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 21
0
def gen_output_data(model):
    data_dir = CONF.get('paths', 'data_dir')
    totals_fname = os.path.join(data_dir,'totaux.xml')
    _doc = minidom.parse(totals_fname)
    tree = OutNode('root', 'root')

    handle_output_xml(_doc, tree, model)
    return tree
Exemplo n.º 22
0
 def saveScenario(self):
     cas_type_dir = CONF.get('paths', 'cas_type_dir')
     default_fileName = os.path.join(cas_type_dir, 'sans-titre')
     fileName = QFileDialog.getSaveFileName(self, u"Sauver un cas type",
                                            default_fileName,
                                            u"Cas type OpenFisca (*.ofct)")
     if not fileName == '':
         self.scenario.saveFile(fileName)
Exemplo n.º 23
0
 def saveScenario(self):
     cas_type_dir = CONF.get('paths', 'cas_type_dir')
     default_fileName = os.path.join(cas_type_dir, 'sans-titre')
     fileName = QFileDialog.getSaveFileName(self,
                                            u"Sauver un cas type", 
                                            default_fileName, 
                                            u"Cas type OpenFisca (*.ofct)")
     if not fileName == '':
         self.scenario.saveFile(fileName)
Exemplo n.º 24
0
    def asXml(self, fileName):
        doc = ElementTree()
        root = Element(tag=self.typeInfo, attrib={"datesim": CONF.get("simulation", "datesim")})

        for i in self._children:
            i._recurseXml(root)

        doc._setroot(root)
        return doc.write(fileName, encoding="utf-8", method="xml")
Exemplo n.º 25
0
 def create_description(self):
     '''
     Creates a description dataframe
     '''
     now = datetime.now()
     descr =  [u'OpenFisca',
                      u'Calculé le %s à %s' % (now.strftime('%d-%m-%Y'), now.strftime('%H:%M')),
                      u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')]
     return DataFrame(descr)
Exemplo n.º 26
0
    def asXml(self, fileName):
        doc = ElementTree()
        root = Element(tag=self.typeInfo,
                       attrib={'datesim': CONF.get('simulation', 'datesim')})

        for i in self._children:
            i._recurseXml(root)

        doc._setroot(root)
        return doc.write(fileName, encoding="utf-8", method="xml")
Exemplo n.º 27
0
 def refresh_population(self):
     '''
     Refresh after population update
     '''
     population_file = CONF.get('paths', 'population_file')
     store_pop = HDFStore(population_file, 'r')
     self.population = store_pop[self._param_widget.population_name]
     store_pop.close()
     population = self.population.reset_index()
     self._population_widget.set_dataframe(population)
     self._population_widget.update_view()
Exemplo n.º 28
0
 def refresh_population(self):
     '''
     Refresh after population update
     '''
     population_file = CONF.get('paths', 'population_file')         
     store_pop = HDFStore(population_file,'r')
     self.population = store_pop[self._param_widget.population_name]
     store_pop.close()
     population = self.population.reset_index()
     self._population_widget.set_dataframe(population)
     self._population_widget.update_view()
Exemplo n.º 29
0
 def apply_settings(self):
     """Apply settings changed in 'Preferences' dialog box"""
     self.XAXIS = CONF.get('simulation', 'xaxis')
     if not self.XAXIS == self.oldXAXIS:
         self.scenario.indiv[0][self.oldXAXIS + 'i']=0
     if self.isLoaded == True:
         self._parametres.initialize()
         self.refresh_bareme()
     if self.calibration_enabled:
         self.action_refresh_calibration.setEnabled(True)
     if self.aggregate_enabled:
         self.action_refresh_aggregate.setEnabled(True)
Exemplo n.º 30
0
 def saveXml(self):
     reformes_dir = CONF.get('paths', 'reformes_dir')
     default_fileName = os.path.join(reformes_dir, 'sans-titre')
     fileName = QFileDialog.getSaveFileName(self,
                                            u"Enregistrer une réforme", default_fileName, u"Paramètres OpenFisca (*.ofp)")
     if fileName:
         try:
             self._rootNode.asXml(fileName)
         except Exception, e:
             QMessageBox.critical(
                 self, "Erreur", u"Impossible d'enregistrer le fichier : " + str(e),
                 QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 31
0
 def create_description(self):
     '''
     Creates a description dataframe
     '''
     now = datetime.now()
     descr = [
         u'OpenFisca',
         u'Calculé le %s à %s' %
         (now.strftime('%d-%m-%Y'), now.strftime('%H:%M')),
         u'Système socio-fiscal au %s' % CONF.get('simulation', 'datesim')
     ]
     return DataFrame(descr)
Exemplo n.º 32
0
 def apply_settings(self):
     """Apply settings changed in 'Preferences' dialog box"""
     self.XAXIS = CONF.get('simulation', 'xaxis')
     if not self.XAXIS == self.oldXAXIS:
         self.scenario.indiv[0][self.oldXAXIS + 'i'] = 0
     if self.isLoaded == True:
         self._parametres.initialize()
         self.refresh_bareme()
     if self.calibration_enabled:
         self.action_calibrate.setEnabled(True)
     if self.aggregate_enabled:
         self.action_refresh_aggregate.setEnabled(True)
Exemplo n.º 33
0
 def saveXml(self):
     reformes_dir = CONF.get('paths', 'reformes_dir')
     default_fileName = os.path.join(reformes_dir, 'sans-titre')
     fileName = QFileDialog.getSaveFileName(
         self, u"Enregistrer une réforme", default_fileName,
         u"Paramètres OpenFisca (*.ofp)")
     if fileName:
         try:
             self._rootNode.asXml(fileName)
         except Exception, e:
             QMessageBox.critical(
                 self, "Erreur",
                 u"Impossible d'enregistrer le fichier : " + str(e),
                 QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 34
0
    def set_param(self):
        '''
        Sets the parameters of the simulation
        '''
        data_dir = CONF.get('paths', 'data_dir')
        fname = os.path.join(data_dir, 'param.xml')
        reader = XmlReader(fname, self._date)
        rootNode = reader.tree

        self.param_default = Tree2Object(rootNode, defaut=True)
        self.param_default.datesim = self._date

        self.param_courant = Tree2Object(rootNode, defaut=False)
        self.param_courant.datesim = self._date
Exemplo n.º 35
0
    def set_param(self):
        '''
        Sets the parameters of the simulation
        '''
        data_dir = CONF.get('paths', 'data_dir')
        fname = os.path.join(data_dir, 'param.xml')
        reader = XmlReader(fname, self._date)
        rootNode = reader.tree
        
        self.param_default = Tree2Object(rootNode, defaut=True)
        self.param_default.datesim = self._date

        self.param_courant = Tree2Object(rootNode, defaut=False)
        self.param_courant.datesim = self._date
Exemplo n.º 36
0
    def saveCsv(self):
        output_dir = CONF.get('paths', 'output_dir')
        user_path = os.path.join(output_dir, 'sans-titre.csv')

        fname = QFileDialog.getSaveFileName(
            self, u"Exporter la table", user_path,
            u"CSV (séparateur: point virgule) (*.csv)")

        if fname:
            CONF.set('paths', 'output_dir', os.path.dirname(str(fname)))
            try:
                now = datetime.now()
                csvfile = open(fname, 'wb')
                writer = UnicodeWriter(csvfile,
                                       dialect=csv.excel,
                                       delimiter=';')
                writer.writerow([u'OpenFisca'])
                writer.writerow([
                    u'Calculé le %s à %s' %
                    (now.strftime('%d-%m-%Y'), now.strftime('%H:%M'))
                ])
                writer.writerow([
                    u'Système socio-fiscal au %s' %
                    CONF.get('simulation', 'datesim')
                ])
                writer.writerow([])

                for row in self.data:
                    if not row.desc in ('root'):
                        outlist = [row.desc]
                        for val in row.vals:
                            outlist.append(locale.str(val))
                        writer.writerow(outlist)
                csvfile.close()
            except Exception, e:
                QMessageBox.critical(self, "Error saving file", str(e),
                                     QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 37
0
    def refresh_cohorts(self):
        '''
        Refresh cohorts
        '''

        year_length = CONF.get('parameters', 'year_length')
        population = self.population
        profiles = self._input_profiles
        cohorts = Cohorts(data=population, columns=['pop'])

        g = self._param_widget.get_grth()
        r = self._param_widget.get_dsct()

        # Prolongation of population scenario

        method = self._param_widget.population_prolong
        cohorts.prolong_population(
            year_length, method=method
        )  #TODO: check if prolong_population name is still relevant
        cohorts.fill(profiles)

        cohorts.gen_dsct(r)
        cohorts.gen_grth(g)

        # Projection of net taxes
        if self._param_widget.taxes_proj == "head_g":
            cohorts.proj_tax(method='per_capita')
        elif self._param_widget.taxes_proj == "global_g":
            cohorts.proj_tax(method='global')

        self._cohorts_widget.set_dataframe(cohorts.reset_index())
        self._cohorts_widget.update_view()

        self._plot_widget.set_dataframe(cohorts)
        self._plot_widget.refresh()

        state = False
        if state is False:
            return

        # Prolongation of state expenses
        if self._param_widget.state_proj == "global_r":
            pass
        elif self._param_widget.state_proj == "global_g":
            pass
        elif self._param_widget.state_proj == "head_r":
            pass
        elif self._param_widget.state_proj == "head_g":
            pass
Exemplo n.º 38
0
    def refresh_cohorts(self):
        '''
        Refresh cohorts
        '''
        
        year_length = CONF.get('parameters', 'year_length')
        population = self.population
        profiles   = self._input_profiles
        cohorts    = Cohorts(data = population, columns = ['pop'])
        
        g = self._param_widget.get_grth()
        r = self._param_widget.get_dsct()
                
        # Prolongation of population scenario
        
        method = self._param_widget.population_prolong
        cohorts.prolong_population(year_length, method = method) #TODO: check if prolong_population name is still relevant
        cohorts.fill(profiles)
        
        cohorts.gen_dsct(r)
        cohorts.gen_grth(g)
        
        # Projection of net taxes
        if self._param_widget.taxes_proj == "head_g":
            cohorts.proj_tax(method = 'per_capita')
        elif self._param_widget.taxes_proj == "global_g":
            cohorts.proj_tax(method = 'global')

        self._cohorts_widget.set_dataframe(cohorts.reset_index())
        self._cohorts_widget.update_view()

        self._plot_widget.set_dataframe(cohorts)
        self._plot_widget.refresh()


        
        state = False
        if state is False:
            return
        
        # Prolongation of state expenses
        if self._param_widget.state_proj == "global_r":
            pass
        elif self._param_widget.state_proj == "global_g":
            pass
        elif self._param_widget.state_proj == "head_r":
            pass
        elif self._param_widget.state_proj == "head_g":
            pass
Exemplo n.º 39
0
 def load_survey_data(self):
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     try:
         # liberate some memory before loading new data
         self.reset_aggregate()
         gc.collect()
         fname = CONF.get('paths', 'survey_data_file')
         self.survey = DataTable(InputTable, survey_data = fname)
         self._dataframe_widget.set_dataframe(self.survey.table)
         return True
     except Exception, e:
         self.aggregate_enabled = False
         QMessageBox.warning(self, u"Impossible de lire les données", 
                             u"OpenFisca n'a pas réussi à lire les données d'enquête et passe en mode barème. L'erreur suivante a été renvoyé:\n%s\n\nVous pouvez charger des nouvelles données d'enquête dans Fichier>Paramètres>Chemins>Données d'enquête"%e)
         return False
Exemplo n.º 40
0
    def __init__(self):
        super(Scenario, self).__init__()
        self.year = CONF.get('simulation', 'datesim').year
        self.indiv = {}
        # indiv est un dict de dict. La clé est le noi de l'individu
        # Exemple :
        # 0: {'quifoy': 'vous', 'noi': 0, 'quifam': 'parent 1', 'noipref': 0, 'noidec': 0, 
        #     'birth': datetime.date(1980, 1, 1), 'quimen': 'pref', 'noichef': 0}
        self.declar = {}
        # declar est un dict de dict. La clé est le noidec.
        self.famille = {}
        self.menage = {0:{'loyer':500,'so':3, 'code_postal':69001, 'zone_apl':2}}

        # on ajoute un individu, déclarant et chef de famille
        self.addIndiv(0, datetime(1975,1,1).date(), 'vous', 'chef')
Exemplo n.º 41
0
 def load_data(self):
     '''
     Loads population and profiles data 
     '''
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     try:
         profiles_file = CONF.get('paths', 'profiles_file')         
         store = HDFStore(profiles_file,'r')
         profiles = store['profiles']
         
     except Exception, e:
         self.population_loaded = False
         QMessageBox.warning(self, u"Impossible de lire les données de population", 
                             u"GA n'a pas réussi à lire les données de population. L'erreur suivante a été renvoyée:\n%s\n\nVous pouvez configuer le chemin vers le fichier de données  Fichier>Paramètres>Chemins>Fichier données population"%e)
         return False
Exemplo n.º 42
0
    def __init__(self):
        super(Scenario, self).__init__()
        self.year = CONF.get("simulation", "datesim").year
        self.indiv = {}
        # indiv est un dict de dict. La clé est le noi de l'individu
        # Exemple :
        # 0: {'quifoy': 'vous', 'noi': 0, 'quifam': 'parent 1', 'noipref': 0, 'noidec': 0,
        #     'birth': datetime.date(1980, 1, 1), 'quimen': 'pref', 'noichef': 0}
        self.declar = {}
        # declar est un dict de dict. La clé est le noidec.
        self.famille = {}
        self.menage = {0: {"loyer": 500, "so": 3, "code_postal": 69001, "zone_apl": 2}}

        # on ajoute un individu, déclarant et chef de famille
        self.addIndiv(0, datetime(1975, 1, 1).date(), "vous", "chef")
Exemplo n.º 43
0
    def __init__(self, model_description, survey_data=None, scenario=None):
        super(DataTable, self).__init__()

        # Init instance attribute
        self.description = None
        self.scenario = None
        self._isPopulated = False
        self.col_names = []
        self.table = DataFrame()
        self.index = {}
        self._nrows = 0

        self.datesim = CONF.get('simulation', 'datesim')

        self.NMEN = CONF.get('simulation', 'nmen')
        self.MAXREV = CONF.get('simulation', 'maxrev')
        self.XAXIS = CONF.get('simulation', 'xaxis') + 'i'

        # Build the description attribute
        if type(model_description) == type(ModelDescription):
            descr = model_description()
            self.description = Description(descr.columns)
        else:
            raise Exception(
                "model_description should be an ModelDescription inherited class"
            )

        self.col_names = self.description.col_names

        if (survey_data and scenario):
            raise Exception(
                "should provide either survey_data or scenario but not both")
        elif survey_data:
            self.populate_from_survey_data(survey_data)
        elif scenario:
            self.populate_from_scenario(scenario)
Exemplo n.º 44
0
 def updateTable(self, data, reforme, mode, dataDefault):
     xaxis = CONF.get('simulation', 'xaxis')
     if dataDefault is None:
         dataDefault = data
     headers = dataDefault[xaxis]
     n = len(headers.vals)
     self.data = data
     self.outputModel = OutputModel(data, headers, n, self)
     self.treeView.setModel(self.outputModel)
     self.treeView.expandAll()
     self.treeView.setColumnWidth(0, 200)
     if mode == 'bareme':
         for i in range(n):
             self.treeView.resizeColumnToContents(i + 1)
     else:
         self.treeView.setColumnWidth(1, 100)
Exemplo n.º 45
0
    def enable_aggregate(self, val = True):
        survey_enabled = CONF.get('paths', 'survey_data/survey_enabled')
        loaded = False
        if val and survey_enabled:
            loaded = self.load_survey_data()

        if loaded:
            # Show widgets and enabled actions
            self.aggregate_enabled = True
            self._aggregate_output.setEnabled(True)
            self._aggregate_output.show()
            self._dataframe_widget.show()
            self.action_refresh_aggregate.setEnabled(True)
            self.action_calibrate.setEnabled(True)
        else:
            self.switch_bareme_only()
Exemplo n.º 46
0
 def updateTable(self, data, reforme, mode, dataDefault):
     xaxis = CONF.get('simulation', 'xaxis')
     if dataDefault is None:
         dataDefault = data
     headers = dataDefault[xaxis]
     n = len(headers.vals)
     self.data = data
     self.outputModel = OutputModel(data, headers, n , self)
     self.treeView.setModel(self.outputModel)
     self.treeView.expandAll()
     self.treeView.setColumnWidth(0, 200)
     if mode == 'bareme':
         for i in range(n):
             self.treeView.resizeColumnToContents(i+1)
     else:
         self.treeView.setColumnWidth(1,100)
Exemplo n.º 47
0
    def enable_aggregate(self, val=True):
        survey_enabled = CONF.get('paths', 'survey_data/survey_enabled')
        loaded = False
        if val and survey_enabled:
            loaded = self.load_survey_data()

        if loaded:
            # Show widgets and enabled actions
            self.aggregate_enabled = True
            self._aggregate_output.setEnabled(True)
            self._aggregate_output.show()
            self._dataframe_widget.show()
            self.action_refresh_aggregate.setEnabled(True)
            self.action_calibrate.setEnabled(True)
        else:
            self.switch_bareme_only()
Exemplo n.º 48
0
    def load_data(self):
        '''
        Loads population and profiles data 
        '''
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        try:
            profiles_file = CONF.get('paths', 'profiles_file')
            store = HDFStore(profiles_file, 'r')
            profiles = store['profiles']

        except Exception, e:
            self.population_loaded = False
            QMessageBox.warning(
                self, u"Impossible de lire les données de population",
                u"GA n'a pas réussi à lire les données de population. L'erreur suivante a été renvoyée:\n%s\n\nVous pouvez configuer le chemin vers le fichier de données  Fichier>Paramètres>Chemins>Fichier données population"
                % e)
            return False
Exemplo n.º 49
0
    def _recurseXml(self, parent):
        if self.isDirty():
            child = SubElement(parent,
                               tag=self.typeInfo,
                               attrib={
                                   'code': self.code,
                                   'description': self.description
                               })

            date = CONF.get('simulation', 'datesim')
            SubElement(child,
                       tag='VALUE',
                       attrib={
                           'valeur': '%f' % self.value,
                           'deb': date,
                           'fin': date
                       })
Exemplo n.º 50
0
    def initialize(self):
        self._date = CONF.get('simulation', 'datesim')
        self._reader = XmlReader(self._file, self._date)
        self._rootNode = self._reader.tree
        self._rootNode.rmv_empty_code()
                
        self._model = PrestationModel(self._rootNode, self)
        self.connect(self._model, SIGNAL('dataChanged(QModelIndex, QModelIndex)'), self.changed)

        self.uiTree.setModel(self._model)
        self.selectionModel = self.uiTree.selectionModel()
        self.uiTree.setColumnWidth(0,230)
        self.uiTree.setColumnWidth(1,70)
        self.uiTree.setColumnWidth(2,70)
        delegate = CustomDelegate(self)
        delegate.insertColumnDelegate(1, ValueColumnDelegate(self))
        delegate.insertColumnDelegate(2, ValueColumnDelegate(self))
        self.uiTree.setItemDelegate(delegate)
Exemplo n.º 51
0
 def load_survey_data(self):
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     try:
         # liberate some memory before loading new data
         self.reset_aggregate()
         gc.collect()
         fname = CONF.get('paths', 'survey_data/file')
         self.survey = DataTable(InputTable, survey_data=fname)
         self._dataframe_widget.set_dataframe(self.survey.table)
         return True
     except Exception, e:
         self.aggregate_enabled = False
         QMessageBox.warning(
             self, u"Impossible de lire les données",
             u"OpenFisca n'a pas réussi à lire les données d'enquête et passe en mode barème. L'erreur suivante a été renvoyé:\n%s\n\nVous pouvez charger des nouvelles données d'enquête dans Fichier>Paramètres>Chemins>Données d'enquête"
             % e)
         self.emit(SIGNAL('baremeOnly()'))
         return False
Exemplo n.º 52
0
 def updateGraph(self, data, reforme = False, mode = 'bareme', dataDefault = None):
     self.data = data
     self.dataDefault = dataDefault
     self.data.setLeavesVisible()
     self.reforme = reforme
     self.mode = mode
     data['revdisp'].visible = 1
     if self.mode == 'bareme':
         data['salsuperbrut'].setHidden()
         data['salbrut'].setHidden()
         data['chobrut'].setHidden()
         data['rstbrut'].setHidden()
         if reforme:
             data.hideAll()
     
     self.xaxis = CONF.get('simulation', 'xaxis')
     self.populate_absBox(self.xaxis, self.mode)
     self.updateGraph2()
Exemplo n.º 53
0
    def _recurseXml(self, parent):
        if self.isDirty():
            child = SubElement(parent, tag=self.typeInfo, attrib={"code": self.code, "description": self.description})

            bareme = self.value
            S = bareme.seuils
            T = bareme.taux
            date = CONF.get("simulation", "datesim")

            for i in range(self.value.getNb()):
                tranche = SubElement(child, tag="TRANCHE", attrib={"code": "tranche%d" % i})

                seuil = SubElement(tranche, tag="SEUIL", attrib={"code": "tranche%d" % i})

                SubElement(seuil, tag="VALUE", attrib={"valeur": "%f" % S[i], "deb": date, "fin": date})

                taux = SubElement(tranche, tag="TAUX")

                SubElement(taux, tag="VALUE", attrib={"valeur": "%f" % T[i], "deb": date, "fin": date})
Exemplo n.º 54
0
    def initialize(self):
        self._date = CONF.get('simulation', 'datesim')
        self._reader = XmlReader(self._file, self._date)
        self._rootNode = self._reader.tree
        self._rootNode.rmv_empty_code()

        self._model = PrestationModel(self._rootNode, self)
        self.connect(self._model,
                     SIGNAL('dataChanged(QModelIndex, QModelIndex)'),
                     self.changed)

        self.uiTree.setModel(self._model)
        self.selectionModel = self.uiTree.selectionModel()
        self.uiTree.setColumnWidth(0, 230)
        self.uiTree.setColumnWidth(1, 70)
        self.uiTree.setColumnWidth(2, 70)
        delegate = CustomDelegate(self)
        delegate.insertColumnDelegate(1, ValueColumnDelegate(self))
        delegate.insertColumnDelegate(2, ValueColumnDelegate(self))
        self.uiTree.setItemDelegate(delegate)
Exemplo n.º 55
0
    def _recurseXml(self, parent):
        if self.isDirty():
            child = SubElement(parent,
                               tag=self.typeInfo,
                               attrib={
                                   'code': self.code,
                                   'description': self.description
                               })

            bareme = self.value
            S = bareme.seuils
            T = bareme.taux
            date = CONF.get('simulation', 'datesim')

            for i in range(self.value.getNb()):
                tranche = SubElement(child,
                                     tag='TRANCHE',
                                     attrib={'code': 'tranche%d' % i})

                seuil = SubElement(tranche,
                                   tag='SEUIL',
                                   attrib={'code': 'tranche%d' % i})

                SubElement(seuil,
                           tag='VALUE',
                           attrib={
                               'valeur': '%f' % S[i],
                               'deb': date,
                               'fin': date
                           })

                taux = SubElement(tranche, tag='TAUX')

                SubElement(taux,
                           tag='VALUE',
                           attrib={
                               'valeur': '%f' % T[i],
                               'deb': date,
                               'fin': date
                           })
Exemplo n.º 56
0
 def openScenario(self):
     cas_type_dir = CONF.get('paths', 'cas_type_dir')
     fileName = QFileDialog.getOpenFileName(self,
                                            u"Ouvrir un cas type", 
                                            cas_type_dir, 
                                            u"Cas type OpenFisca (*.ofct)")
     if not fileName == '':
         n = len(self.scenario.indiv)
         try:
             self.scenario.openFile(fileName)
             while n < self.nbRow():
                 self.addRow()
                 n += 1
             while n > self.nbRow(): 
                 self.rmvRow()
                 n -= 1
             self.emit(SIGNAL('compoChanged()'))
             self.emit(SIGNAL("ok()"))
         except Exception, e:
             QMessageBox.critical(
                 self, "Erreur", u"Erreur lors de l'ouverture du fichier : le fichier n'est pas reconnu",
                 QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 57
0
    def updateGraph(self,
                    data,
                    reforme=False,
                    mode='bareme',
                    dataDefault=None):
        self.data = data
        self.dataDefault = dataDefault
        self.data.setLeavesVisible()
        self.reforme = reforme
        self.mode = mode
        data['revdisp'].visible = 1
        if self.mode == 'bareme':
            data['salsuperbrut'].setHidden()
            data['salbrut'].setHidden()
            data['chobrut'].setHidden()
            data['rstbrut'].setHidden()
            if reforme:
                data.hideAll()

        self.xaxis = CONF.get('simulation', 'xaxis')
        self.populate_absBox(self.xaxis, self.mode)
        self.updateGraph2()
Exemplo n.º 58
0
 def openScenario(self):
     cas_type_dir = CONF.get('paths', 'cas_type_dir')
     fileName = QFileDialog.getOpenFileName(self, u"Ouvrir un cas type",
                                            cas_type_dir,
                                            u"Cas type OpenFisca (*.ofct)")
     if not fileName == '':
         n = len(self.scenario.indiv)
         try:
             self.scenario.openFile(fileName)
             while n < self.nbRow():
                 self.addRow()
                 n += 1
             while n > self.nbRow():
                 self.rmvRow()
                 n -= 1
             self.emit(SIGNAL('compoChanged()'))
             self.emit(SIGNAL("ok()"))
         except Exception, e:
             QMessageBox.critical(
                 self, "Erreur",
                 u"Erreur lors de l'ouverture du fichier : le fichier n'est pas reconnu",
                 QMessageBox.Ok, QMessageBox.NoButton)
Exemplo n.º 59
0
 def modeCasType(self):
     self.mode = 'castype'
     CONF.set('simulation', 'nmen', 1)
     self.changed_bareme()