flexmeasures.data.models.legacy_migration_utils

This module is part of our data model migration (see https://github.com/SeitaBV/flexmeasures/projects/9). It will become obsolete when Assets, Markets and WeatherSensors can no longer be initialized.

Functions

flexmeasures.data.models.legacy_migration_utils.copy_old_sensor_attributes(old_sensor, old_sensor_type_attributes: list[str], old_sensor_attributes: list[str], old_sensor_type: AssetType | MarketType | WeatherSensorType = None) dict
Parameters:
  • old_sensor – an Asset, Market or WeatherSensor instance

  • old_sensor_type_attributes – names of attributes of the old sensor’s type that should be copied

  • old_sensor_attributes – names of attributes of the old sensor that should be copied

  • old_sensor_type – the old sensor’s type

Returns:

dictionary containing an “attributes” dictionary with attribute names and values

flexmeasures.data.models.legacy_migration_utils.downgrade_value(old_field_name: str, new_value) float | str | dict

Depending on the old field name, some values still need to be turned back into floats.

flexmeasures.data.models.legacy_migration_utils.get_old_model_type(kwargs: dict, old_sensor_type_class: Type[AssetType | MarketType | WeatherSensorType], old_sensor_type_name_key: str, old_sensor_type_key: str) AssetType | MarketType | WeatherSensorType
Parameters:
  • kwargs – keyword arguments used to initialize a new Asset, Market or WeatherSensor

  • old_sensor_type_class – AssetType, MarketType, or WeatherSensorType

  • old_sensor_type_name_key – “asset_type_name”, “market_type_name”, or “weather_sensor_type_name”

  • old_sensor_type_key – “asset_type”, “market_type”, or “sensor_type” (instead of “weather_sensor_type”), i.e. the name of the class attribute for the db.relationship to the type’s class

Returns:

the old sensor’s type

flexmeasures.data.models.legacy_migration_utils.upgrade_value(old_field_name: str, old_value: int | float | dict | bool, sensor=None, asset=None) str | int | float | dict | bool

Depending on the old field name, some values still need to be turned into string quantities.

Exceptions

exception flexmeasures.data.models.legacy_migration_utils.NonDowngradableValueError