class UrbansimConstantDataset(Dataset):

    def __init__(self, **kwargs):
        self.constants_dict = Constants(**kwargs)
        data = {}
        for attr, value in self.constants_dict.iteritems():
            if isscalar(value):
                new_value = array([value])
                data[attr] = new_value
        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(table_name = 'urbansim_constants', # whatever name
                        table_data = data)
        Dataset.__init__(self, in_storage = storage, 
                           in_table_name='urbansim_constants',
                           id_name = [], dataset_name='urbansim_constant')
        
    def summary(self, output=logger):
        output.write("UrbanSim constant dataset")

    def __getitem__(self, name):
        if name in self.get_known_attribute_names():
            return self.get_attribute(name)[0]
        return self.constants_dict[name]
    
    def __setitem__(self, name, value):
        if name in self.get_known_attribute_names():
            self.modify_attribute(name=name, data=array([value]), index=array([0], dtype='int32'))
        self.constants_dict[name] = value
    
    def get_income_range_for_type(self, income_type):
        return self.constants_dict.get_income_range_for_type(income_type)
class UrbansimConstantDataset(Dataset):
    def __init__(self, **kwargs):
        self.constants_dict = Constants(**kwargs)
        data = {}
        for attr, value in self.constants_dict.iteritems():
            if isscalar(value):
                new_value = array([value])
                data[attr] = new_value
        storage = StorageFactory().get_storage('dict_storage')
        storage.write_table(
            table_name='urbansim_constants',  # whatever name
            table_data=data)
        Dataset.__init__(self,
                         in_storage=storage,
                         in_table_name='urbansim_constants',
                         id_name=[],
                         dataset_name='urbansim_constant')

    def summary(self, output=logger):
        output.write("UrbanSim constant dataset")

    def __getitem__(self, name):
        if name in self.get_known_attribute_names():
            return self.get_attribute(name)[0]
        return self.constants_dict[name]

    def __setitem__(self, name, value):
        if name in self.get_known_attribute_names():
            self.modify_attribute(name=name,
                                  data=array([value]),
                                  index=array([0], dtype='int32'))
        self.constants_dict[name] = value

    def get_income_range_for_type(self, income_type):
        return self.constants_dict.get_income_range_for_type(income_type)
 def __init__(self, **kwargs):
     self.constants_dict = Constants(**kwargs)
     data = {}
     for attr, value in self.constants_dict.iteritems():
         if isscalar(value):
             new_value = array([value])
             data[attr] = new_value
     storage = StorageFactory().get_storage('dict_storage')
     storage.write_table(
         table_name='urbansim_constants',  # whatever name
         table_data=data)
     Dataset.__init__(self,
                      in_storage=storage,
                      in_table_name='urbansim_constants',
                      id_name=[],
                      dataset_name='urbansim_constant')
Ejemplo n.º 4
0
 def __init__(self, **kwargs):
     self.constants_dict = Constants(**kwargs)
     data = {}
     for attr, value in self.constants_dict.iteritems():
         if isscalar(value):
             new_value = array([value])
             data[attr] = new_value
     storage = StorageFactory().get_storage("dict_storage")
     storage.write_table(table_name="urbansim_constants", table_data=data)  # whatever name
     Dataset.__init__(
         self, in_storage=storage, in_table_name="urbansim_constants", id_name=[], dataset_name="urbansim_constant"
     )