def __init__(self, data_id_key='id'):
        # ToDo remove from being an ordered dict, this shouldn't be necessary
        self.data_id_key = data_id_key
        self.index_levels = OrderedDict()
        self.column_names = OrderedDict()
        self.read_index_levels()
        # creates list of dataframe headers from relational table lookup with database headers
        #  i.e. gau = geography ; self.geography = 'state'.
#        self.df_index_names = [level if hasattr(self, level) else level for level in self.index_levels]
        self.df_index_names = [util.id_to_name(level, getattr(self, level)) if hasattr(self, level) else level for level
                               in self.index_levels]
Beispiel #2
0
 def __init__(self, primary_key='id'):
     # ToDo remove from being an ordered dict, this shouldn't be necessary
     self.primary_key = primary_key
     self.index_levels = OrderedDict()
     self.column_names = OrderedDict()
     self.read_index_levels()
     # creates list of dataframe headers from relational table lookup with database headers
     #  i.e. gau = geography ; self.geography = 'state'.
     self.df_index_names = [level if hasattr(self, level) else level for level in self.index_levels]
     self.df_index_names = [util.id_to_name(level, getattr(self, level)) if hasattr(self, level) else level for level
                            in self.index_levels]
Beispiel #3
0
 def inspect_index_levels(self, headers, read_data):
     """
     creates a dictionary to store level headings (for database lookup) and
     level elements. Stored as attr 'index_level'
     """
     # if read_data is empty, there is nothing to do here
     if read_data:
         elements = [sorted(set(e)) for e in zip(*read_data)]
         # OrderedDict in necessary the way this currently works
         self.column_names = OrderedDict([(index_level, column_name) for index_level, column_name in cfg.index_levels if (column_name in headers) and (column_name not in self.data_id_key) and (elements[headers.index(column_name)] != [None])])
         self.index_levels = OrderedDict([(index_level, elements[headers.index(column_name)]) for index_level, column_name in cfg.index_levels if column_name in self.column_names.values()])
         self.df_index_names = [util.id_to_name(level, getattr(self, level)) if hasattr(self, level) else level for level in self.index_levels]
Beispiel #4
0
    def read_geography_indicies(self):
        geo_key = util.sql_read_table('Geographies', column_names='name')

        for key in geo_key:
            self.geographies[key] = []

        for geography_id, name, id in util.sql_read_table('GeographiesData', column_names=['geography_id', 'name', 'id']):
            geography_name = util.id_to_name('geography_id', geography_id)
            self.geographies[geography_name].append(id)
            self.geography_names[id] = name

        for id, name in util.sql_read_table('TimeZones', column_names=['id', 'name']):
            self.timezone_names[id] = name

        for map_key in util.sql_read_table('GeographyMapKeys', 'name'):
            self.map_keys.append(map_key)