flexmeasures.data.services.asset_grouping

Convenience functions and class for accessing generic assets in groups. For example, group by asset type or by location.

Functions

flexmeasures.data.services.asset_grouping.get_asset_group_queries(group_by_type: bool = True, group_by_account: bool = False, group_by_location: bool = False, custom_aggregate_type_groups: dict[str, list[str]] | None = None) dict[str, Select]

An asset group is defined by Asset queries, which this function can generate.

Each query has a name (for the asset group it represents). These queries still need an executive call, like all(), count() or first().

This function limits the assets to be queried to the current user’s account, if the user is not an admin.

Note: Make sure the current user has the “read” permission on their account (on GenericAsset.__class__?? See https://github.com/FlexMeasures/flexmeasures/issues/200) or is an admin.

Parameters:
  • group_by_type – If True, groups will be made for assets with the same type. We prefer pluralised group names here. Defaults to True.

  • group_by_account – If True, groups will be made for assets within the same account. This makes sense for admins, as they can query across accounts.

  • group_by_location – If True, groups will be made for assets at the same location. Naming of the location currently supports charge points (for EVSEs).

  • custom_aggregate_type_groups – dict of asset type groupings (mapping group names to names of asset types). See also the setting FLEXMEASURES_ASSET_TYPE_GROUPS.

Classes

class flexmeasures.data.services.asset_grouping.AssetGroup(name: str, asset_query: Select | None = None)

This class represents a group of assets of the same type, offering some convenience functions for displaying their properties.

When initialised with an asset type name, the group will contain all assets of the given type that are accessible to the current user’s account.

When initialised with a query for GenericAssets, as well, the group will list the assets returned by that query. This can be useful in combination with get_asset_group_queries, see above.

TODO: On a conceptual level, we can model two functionally useful ways of grouping assets: - AggregatedAsset if it groups assets of only 1 type, - GeneralizedAsset if it groups assets of multiple types There might be specialised subclasses, as well, for certain groups, like a market and consumers.

__init__(name: str, asset_query: Select | None = None)

The asset group name is either the name of an asset group or an individual asset.

property display_name: str

Attempt to get a beautiful name to show if possible.

property hover_label: str | None

Attempt to get a hover label to show if possible.

is_eligible_for_comparing_individual_traces(max_traces: int = 7) bool

Decide whether comparing individual traces for assets in this asset group is a useful feature. The number of assets that can be compared is parametrizable with max_traces. Plot colors are reused if max_traces > 7, and run out if max_traces > 105.

property is_unique_asset: bool

Determines whether the resource represents a unique asset.

property parameterized_name: str

Get a parametrized name for use in javascript.