Re: [UrbanSim-Users] writing specifications and coefficients to a baseyear database

From: Brian Miles <Brian.Miles_at_uvm.edu>
Date: Thu, 15 Nov 2007 16:57:20 -0500

Hi Hana,

Thanks for the pointer. Since the format of the trapperkeeper data
store differs from how UrbanSim expects specifications and variables
to be stored, I decided to pull the data out of the trapperkeeper
store and just call the constructors for Coefficients and
EquationSpecification. Once the objects are built this way, the code
you provided for writing datasets to the baseyear worked perfectly.

Thanks,

Brian

On Nov 14, 2007, at 1:17 PM, Hana Sevcikova wrote:

> Brian,
>
> If I understand correctly, what you want to do, the easiest way is
> to create two sql-based storage objects - one for loading (say
> trapperkeeper_storage), the other one for storing (say
> baseyear_storage). Then you can do:
>
> coefficients = Coefficients()
> coefficients.load(in_storage=trapperkeeper_storage,
> in_table_name='my_coefficients_table')
> coefficients.write(out_storage=baseyear_storage,
> out_table_name="<MODEL_NAME>_coefficients")
>
> (The same with specification)
>
> To create the storage objects, you can use the MysqlStorage class
> below, e.g.
>
> trapperkeeper_storage = MysqlStorage().get('trapperkeeper_database')
> baseyear_storage = MysqlStorage().get('baseyear_database')
>
> I hope it helps.
>
> Hana
>
>
> from opus_core.storage_factory import StorageFactory
> from opus_core.database_management.database_server import
> DatabaseServer
> from opus_core.database_management.database_server_configuration
> import DatabaseServerConfiguration
>
> class MysqlStorage:
> def get(self, database):
> db_config = DatabaseServerConfiguration(
> host_name = os.environ['MYSQLHOSTNAME'],
> user_name = os.environ['MYSQLUSERNAME'],
> password = os.environ['MYSQLPASSWORD']
> )
> db_server = DatabaseServer(db_config)
> db = db_server.get_database(database)
>
> storage = StorageFactory().get_storage(
> 'sql_storage',
> storage_location = db)
> return storage
>
> Brian Miles wrote:
>> Hello,
>> I'm updating our estimation management tool <http://trondheim.cs.washington.edu/cgi-bin/trac.cgi/wiki/EstimationTrapperKeeper
>> > to be able to write specifications and coefficients to the
>> baseyear database.
>> What I want to be able to do is to write arbitrary estimation
>> results (stored in my trapperkeeper database) to the
>> "<MODEL_NAME>_specification" and the "<MODEL_NAME>_coefficients"
>> tables.
>> Is there a relatively easy way to write to these tables through
>> Opus's dataset/storage APIs?
>> I've been looking at what's done in
>> urbansim.estimation.Estimator::save_results and
>> urbansim.models.LandPriceModel.Test and am thinking that I might
>> be able to:
>> 1. build dict_storage-based Storage object(s) to put the data in
>> 2. get connection to the sql-based baseyear as a Storage object
>> 3. Build opus_core.Coefficients and
>> opus_core.EquationSpecification datasets using the data in
>> dict_storage
>> 4. Tell the Coefficients and EquationSpecification objects to
>> write themselves to the baseyear storage
>> Does this seem like "the right way" to do what I want to do? Are
>> the Coefficients and EquationSpecification classes the right
>> datasets to use?
>> Any suggestions or pointers to relevant example code would be
>> appreciated.
>> Thanks,
>> Brian
>> _______________________________________________
>> Users mailing list
>> Users_at_urbansim.org
>> http://www.urbansim.org/mailman/listinfo/users
Received on Thu Nov 15 2007 - 13:57:34 PST

This archive was generated by hypermail 2.2.0 : Thu Nov 15 2007 - 13:57:35 PST