flexmeasures.ui.views.assets.utils

Functions

flexmeasures.ui.views.assets.utils.add_child_asset(asset: GenericAsset, assets: list) list

Add a child asset to the current assets list. This function is used to add a child asset to the current asset in the list of assets. Args:

asset: The current asset to be used as parent assets: The list of assets

flexmeasures.ui.views.assets.utils.get_allowed_inflexible_sensor_data(account_id: int | None) Dict[int, str]

Return a list of sensors which the user can add as inflexible device sensors. This list is built using sensors with energy or power units within the current account (or among public assets when account_id argument is not specified). For each sensor we get data as sensor_id: asset_name:sensor_name.

# todo: this function seem obsolete

flexmeasures.ui.views.assets.utils.get_allowed_price_sensor_data(account_id: int | None) Dict[int, str]

Return a list of sensors which the user can add as consumption_price_sensor_id or production_price_sensor_id. For each sensor we get data as sensor_id: asset_name:sensor_name.

# todo: this function seem obsolete

flexmeasures.ui.views.assets.utils.get_asset_by_id_or_raise_notfound(asset_id: str) GenericAsset

find an show existing asset or raise NotFound

flexmeasures.ui.views.assets.utils.get_assets_by_account(account_id: int | str | None) list[GenericAsset]
flexmeasures.ui.views.assets.utils.get_list_assets_chart(asset: GenericAsset, base_asset: GenericAsset, parent_depth=0, child_depth=0, look_for_child=False, is_head=False) list[dict]

Recursively builds a tree of assets from a given asset and its parents and children up to a certain depth.

Args:

asset: The asset to start the recursion from base_asset: The asset that is the base of the chart parent_depth: The current depth of the parents hierarchy child_depth: The current depth of the children hierarchy look_for_child: If True, start looking for children of the current asset is_head: If True, the current asset is the head of the chart

Returns:

A list of dictionaries representing the assets in the tree

flexmeasures.ui.views.assets.utils.process_internal_api_response(asset_data: dict, asset_id: int | None = None, make_obj=False) GenericAsset | dict

Turn data from the internal API into something we can use to further populate the UI. Either as an asset object or a dict for form filling.

If we add other data by querying the database, we make sure the asset is not in the session afterwards.

flexmeasures.ui.views.assets.utils.serialize_asset(asset: GenericAsset, is_head=False) dict
flexmeasures.ui.views.assets.utils.user_can_create_assets(account: Account | None = None) bool
flexmeasures.ui.views.assets.utils.user_can_create_children(asset: GenericAsset) bool
flexmeasures.ui.views.assets.utils.user_can_delete(asset: GenericAsset) bool
flexmeasures.ui.views.assets.utils.user_can_update(asset: GenericAsset) bool