Exemplo n.º 1
0
    def _parseRow(self, row_data):
        '''
        Parses a given database row.

        Arguments:
            row_data (bytes): The database row data

        Returns:
            places.databases.entities.DatabaseRow: The parsed database row
        '''
        row = DatabaseRow()

        row.state_id, row.mesoregion_id, row.microregion_id, \
        row.municipality_id, row.district_id, row.subdistrict_id, \
        name = row_data.unpack('2s2s3s5s2s2s')
        row._name = name.replace('\x8c', '\x55')

        self._bindNames(row)

        return row.normalize()
Exemplo n.º 2
0
    def _parseColumns(self, **options):
        '''
        Parses the database columns.

        Arguments:
            options (dict): The parsing options

        Returns:
            list: A list with parsed database columns
        '''
        return DatabaseRow().columns(options.get('localized', True))
Exemplo n.º 3
0
    def _parseColumns(self, **options):
        '''
        Parses the database columns.

        Arguments:
            options (dict): The parsing options

        Returns:
            list: A list with parsed database columns
        '''
        columns = DatabaseRow().columns(options.get('localized', True))
        base_year = int(self._base.year)

        if base_year in (1940, 1950, 1960, 1970, 1980):
            return columns[:2] + columns[6:8]
        elif base_year in (2010, 2011, 2012):
            return columns[:8]

        return columns
Exemplo n.º 4
0
    def _parseRow(self, row_data):
        '''
        Parses a given database row.

        Arguments:
            row_data (list): The database row data

        Returns:
            places.databases.entities.DatabaseRow: The parsed database row
        '''
        row = DatabaseRow()
        normalization_options = {}
        base_year = int(self._base.year)

        if base_year in (1940, 1950, 1960, 1970, 1980):
            (row.state_id, row.state_name) = row_data[:2]
            (row.municipality_id, row.municipality_name) = row_data[3:5]
        elif base_year in (2000, 2004):
            if base_year == 2000:
                row.state_id, row.mesoregion_id, row.microregion_id, \
                row.municipality_id, row.district_id, row.subdistrict_id, \
                row._name = row_data[2:]
                normalization_options = dict(force_str=True)
            elif base_year == 2004:
                level, row.state_id, _id, row.district_id, \
                row.subdistrict_id, row._name = row_data
                level = int(level)

                if level in (5, 6, 7):
                    row.municipality_id = _id
                    row.microregion_id = str(self._lastrow.microregion_id)
                    row.mesoregion_id = str(self._lastrow.mesoregion_id)
                elif level == 8:
                    row.mesoregion_id = _id[:2]
                elif level == 9:
                    row.microregion_id = _id[:3]
                    row.mesoregion_id = str(self._lastrow.mesoregion_id)

                self._lastrow = row

            self._bindNames(row)
        elif base_year in (2003, 2005, 2006, 2007, 2008, 2009, 2013):
            (row.state_id, row.state_name,
             row.mesoregion_id, row.mesoregion_name,
             row.microregion_id, row.microregion_name,
             row.municipality_id, row.municipality_name,
             row.district_id, row.district_name,
             row.subdistrict_id, row.subdistrict_name) = row_data
        elif base_year in (2010, 2011, 2012):
            (row.state_id, row.state_name,
             row.mesoregion_id, row.mesoregion_name,
             row.microregion_id, row.microregion_name,
             row.municipality_id, row.municipality_name) = row_data
        elif base_year == 2014:
            (row.state_id, row.state_name,
             row.mesoregion_id, row.mesoregion_name,
             row.microregion_id, row.microregion_name) = row_data[:6]
            row.municipality_id, row.municipality_name = row_data[7:9]
            row.district_id, row.district_name = row_data[10:12]
            row.subdistrict_id, row.subdistrict_name = row_data[13:15]

        return row.normalize(**normalization_options)
Exemplo n.º 5
0
    def _parseRow(self, row_data):
        '''
        Parses a given database row.

        Arguments:
            row_data (list): The database row data

        Returns:
            places.databases.entities.DatabaseRow: The parsed database row
        '''
        row = DatabaseRow()
        normalization_options = {}
        base_year = int(self._base.year)

        if base_year in (1940, 1950, 1960, 1970, 1980):
            (row.state_id, row.state_name) = row_data[:2]
            (row.municipality_id, row.municipality_name) = row_data[3:5]
        elif base_year in (2000, 2004):
            if base_year == 2000:
                row.state_id, row.mesoregion_id, row.microregion_id, \
                row.municipality_id, row.district_id, row.subdistrict_id, \
                row._name = row_data[2:]
                normalization_options = dict(force_str=True)
            elif base_year == 2004:
                level, row.state_id, _id, row.district_id, \
                row.subdistrict_id, row._name = row_data
                level = int(level)

                if level in (5, 6, 7):
                    row.municipality_id = _id
                    row.microregion_id = str(self._lastrow.microregion_id)
                    row.mesoregion_id = str(self._lastrow.mesoregion_id)
                elif level == 8:
                    row.mesoregion_id = _id[:2]
                elif level == 9:
                    row.microregion_id = _id[:3]
                    row.mesoregion_id = str(self._lastrow.mesoregion_id)

                self._lastrow = row

            self._bindNames(row)
        elif base_year in (2003, 2005, 2006, 2007, 2008, 2009, 2013):
            (row.state_id, row.state_name, row.mesoregion_id,
             row.mesoregion_name, row.microregion_id, row.microregion_name,
             row.municipality_id, row.municipality_name, row.district_id,
             row.district_name, row.subdistrict_id,
             row.subdistrict_name) = row_data
        elif base_year in (2010, 2011, 2012):
            (row.state_id, row.state_name, row.mesoregion_id,
             row.mesoregion_name, row.microregion_id, row.microregion_name,
             row.municipality_id, row.municipality_name) = row_data
        elif base_year == 2014:
            (row.state_id, row.state_name, row.mesoregion_id,
             row.mesoregion_name, row.microregion_id,
             row.microregion_name) = row_data[:6]
            row.municipality_id, row.municipality_name = row_data[7:9]
            row.district_id, row.district_name = row_data[10:12]
            row.subdistrict_id, row.subdistrict_name = row_data[13:15]

        return row.normalize(**normalization_options)