UDST / urbansim_templates

Building blocks for simulation models
https://udst.github.io/urbansim_templates
BSD 3-Clause "New" or "Revised" License
20 stars 13 forks source link

Add a data table template class #104

Open apdjustino opened 5 years ago

apdjustino commented 5 years ago

As mentioned in issue #94, we need to have a template class that will define and register a table into Orca. The idea is for the user to be able to specify the table from a yaml spec, and all registered tables in Orca can also be written to a yaml.

A yaml specified table will support different data sources, where the user can specify the type of the source and any additional detail that are specific to different data sources. The table template should also include a calculated_columns property that is an array of columnType classes that will represent calculated columns.

smmaurer commented 5 years ago

Generic TemplateGroup class?

What do you think about creating a generic TemplateGroup class, either to help with this or potentially as the full solution?

The TemplateGroup would bundle together an arbitrary set of other template objects. It would handle loading them all into ModelManager/Orca, saving them all to a single yaml file, and functionality for adding/removing/editing the individual objects.

So a user could create a group containing a table plus the derived columns needed for model simulation, and then maybe a separate group for indicator columns. This would keep the yaml files organized while maintaining a lot of flexibility.

For common use cases, we could provide some kind of wizard for automatically building particular types of groups, either in Python or just in the web ui.

Related examples

Earlier we built a template called SegmentedLargeMultinomialLogitStep that automatically creates multiple LargeMultinomialLogitStep models corresponding to categories of choosers. See PR #45 and segmented_large_multinomial_logit.py.

Having a generic TemplateGroup would help simplify this kind of thing too. I think we'd still need an explicit template for segmented models, to provide the logic for identifying segments and building sub-models, but some of the data management could come out.

We ended up including some neat functionality in the segmented model template, like having a defaults object that automatically updates all the sub-models when its properties are changed. But this added a lot of complexity to the code and i'm not sure it's worth it.