New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move meta data from asset/market/weather classes and types to generic asset (types) #240
Move meta data from asset/market/weather classes and types to generic asset (types) #240
Conversation
- Start having our model_spec_factory get attributes it needs from GenericAsset. - Rename variables, specifically, variables that were annotated as a union of our old sensor models were named generic_asset, which was too easily confused with instances of our GenericAsset class.
…of old sensor model types
… and knowledge horizons
…n and knowledge horizons
Keeping track here of my process and of functionality that has/hasn't moved over: Refactoring:
Moving over old data:
Move over crud functionality / make tests work:
|
…instead have the scheduler check for an applicable market
…needs to be done jointly with moving over asset crud (which we test for) This reverts commit 56ff279.
I suggest we make new project tickets for the outstanding issues, fix what needs to be fixed in the scope of this PR, and merge to a dev branch for project 9 instead of to main. |
Probably a good idea. The other tickets would also live in project 9 right? |
Exactly |
…instead of to GenericAsset attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This is hard work, especially carrying these two models around in terminology inside the codebase at once.
I believe my comments are so small that I can attach the approval already.
device_constraints[0]["min"] = (asset.min_soc_in_mwh - soc_at_start) * ( | ||
timedelta(hours=1) / resolution | ||
device_constraints[0]["min"] = ( | ||
sensor.generic_asset.get_attribute("min_soc_in_mwh") - soc_at_start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will raise if the Sensor
does not have the necessary attributes.
Is there a good way to check? For instance, we could check the GenericAssetType. Or make one quick check if all attributes we require are present...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The planner can work without some of the attributes, such as is_pure_consumer
; others it can set a default for, such as min_soc_in_mwh
with default 0; yet others it cannot realistically work without, such as capacity_in_mw
.
My next PR #242 introduces the has_attribute
method on the Sensor
and GenericAsset
classes, which will be useful for this purpose. I'll make a project ticket to go over the planners and set defaults or raise where needed (see #245).
@@ -81,14 +81,18 @@ def schedule_charging_station( | |||
) - soc_at_start * ( | |||
timedelta(hours=1) / resolution | |||
) # Lacking information about the battery's nominal capacity, we use the highest target value as the maximum state of charge | |||
if asset.is_pure_consumer: | |||
if sensor.generic_asset.get_attribute("is_pure_consumer"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above about checking if required attributes are present.
else: | ||
raise TypeError("Unknown generic asset type.") | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay to return None
here? Are we not failing down the road?
Also, None
does not fit the return typing of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return typing is Optional[Transformation]
, so returning None
seems valid to me. And before this PR, there were also cases where we returned None
within this function.
… asset (types) (#240) Refactoring: - Renamed generic_asset variables to old_sensor wherever the variable was expecting a type Union[Asset, Market, WeatherSensor]. - Forecasting sub-package gets its attributes from GenericAsset or Sensor instead of from old sensor models. - Planning/scheduling sub-package gets its attributes from GenericAsset or Sensor instead of from old sensor models. - API packages gets its attributes from GenericAsset or Sensor instead of from old sensor models. - API package gets and sets metadata on GenericAssets #243 Moving over old data: - Sensor units, event resolutions and knowledge horizons (fnc and par) copied from old sensors (these already had dedicated columns in both the old and new models) in a database migration. One-way transition. - Copy over all old sensor attributes that have no dedicated column in the GenericAsset model (just the display name for Market and WeatherSensor, but a lot of other attributes for Assets). These will be put in the new GenericAsset.attributes column as JSON, or in the new Sensor.attributes column as JSON. - Copy over all old sensor type attributes that have no dedicated column in the GenericAsset model (just seasonalities for Market and WeatherSensor, plus some is_consumer- and can_curtail-like attributes for Assets). Note that I'm moving these to the GenericAsset or Sensor, rather than to the GenericAssetType model. - Copy display name to both GenericAsset and Sensor. Move over crud functionality / make tests work: - Make sure to copy over units, event resolutions, knowledge horizons and other attributes (incl. weather correlations), whenever an Asset gets created, to the already simultaneously created new sensor and generic asset. - Do this for Markets and WeatherSensors, too. - API package gets and sets metadata on GenericAssets #243 - Allow JSON fields to be updated (see here). API package gets and sets metadata on GenericAssets #243 * Create draft PR for #239 * Db migration that copies over attributes from old data models * - In Asset.__init__, copy over attributes to GenericAsset. - Start having our model_spec_factory get attributes it needs from GenericAsset. - Rename variables, specifically, variables that were annotated as a union of our old sensor models were named generic_asset, which was too easily confused with instances of our GenericAsset class. * model_spec_factory now gets its attributes from GenericAsset instead of old sensor model types * More renaming to avoid confusion * Have db migration copy over sensor attributes: unit, event_resolution and knowledge horizons * In Asset.__init__, copy over sensor attributes: unit, event_resolution and knowledge horizons * model_spec_factory now gets event_resolution and name from Sensor * Fix tests * Factor out use of corresponding_generic_asset attribute * Factor out use of corresponding_generic_asset attribute * More renaming * Pass time series class to model configurator explicitly * Finally, model_spec_factory doesn't need the old sensor model anymore * Allow setting the collect function name for TBSeriesSpecs to something custom * In Asset.__init__, copy over additional asset attributes to GenericAsset * Planning subpackage uses sensors instead of assets * Move some simple attributes in the UI package * Refactor to stop explicitly passing the market to the scheduler, and instead have the scheduler check for an applicable market * Revert "Move some simple attributes in the UI package", because this needs to be done jointly with moving over asset crud (which we test for) This reverts commit 56ff279. * Add notes about how each attribute is to be copied from an old class to a new class * Intend to copy display_name to both GenericAsset and Sensor * Introduce Sensor attributes and copy most old model attributes there instead of to GenericAsset attributes * Adjust attribute copying in Asset.__init__ * Implement Sensor method to get an attribute * Give old sensor classes a generic_asset property * Give old sensor classes a get_attribute property * Derive Sensor class lat/lng location from GenericAsset * Get attributes from Sensor rather than from GenericAsset * Set default attributes on generic assets, too * Add clarity to method docstring Co-authored-by: Flix6x <Flix6x@users.noreply.github.com> Co-authored-by: F.N. Claessen <felix@seita.nl>
closes #239