flexmeasures.data.models.charts.chart_types
The registries of chart types: the one place that lists the charts an asset or a sensor can be drawn as.
Each chart type has a public, kebab-case name, which API users pass as chart-type.
It also says which assets or sensors it applies to, and which function builds its Vega-Lite specs.
An asset chart type also says which graphs it draws (its layout).
A layout is a list of graphs, each a dictionary in the format of a validated sensors_to_show entry:
a title and a list of plots holding the graph’s sensors.
Functions
- flexmeasures.data.models.charts.chart_types.charge_point_sessions_layout(sensors_to_show: list[dict]) list[dict]
The charging sessions, followed by the graphs drawn below them.
The sessions graph holds the charging-session timestamps found in any graph. Below it come the Prices graph and, of the Power flow by type graph, the charge points power (see charge_point_companion_graph).
- flexmeasures.data.models.charts.chart_types.default_layout(sensors_to_show: list[dict]) list[dict]
A graph per entry in the asset’s sensors_to_show, except the graph of charging-session timestamps.
Those timestamps are not plottable quantities, so only the Charge Points chart draws them.
- flexmeasures.data.models.charts.chart_types.get_asset_chart_type(name: str, accept_legacy_name: bool = True) AssetChartType
Look up an asset chart type by its name.
- Parameters:
name – the public name of the chart type, or (if accepted) its legacy name.
accept_legacy_name – whether to also accept the name of the chart type’s builder.
- Returns:
the chart type.
- Raises:
UnknownAssetChartType – if no chart type goes by that name.
- flexmeasures.data.models.charts.chart_types.get_sensor_chart_type(name: str, accept_legacy_name: bool = True) SensorChartType
Look up a sensor chart type by its name.
- Parameters:
name – the public name of the chart type, or (if accepted) its legacy name.
accept_legacy_name – whether to also accept the name the chart endpoint took before the chart types had public names.
- Returns:
the chart type.
- Raises:
UnknownSensorChartType – if no chart type goes by that name.
- flexmeasures.data.models.charts.chart_types.has_charge_points(asset: GenericAsset) bool
Whether the asset has a charge point among its children, as the asset page checks before offering the Charge Points chart.
- flexmeasures.data.models.charts.chart_types.register_asset_chart_type(chart_type: AssetChartType) AssetChartType
Add a chart type to the registry of asset chart types.
Plugins call this when they are set up (e.g. in their
__init__), after which the chart API accepts the chart type’s name and the asset page offers it on the assets it applies to. To avoid clashing with chart types FlexMeasures may add later, prefix the name with the plugin’s name (e.g."my-plugin-heat-pumps").- Parameters:
chart_type – the chart type to register.
- Returns:
the registered chart type.
- Raises:
ValueError – if its name or legacy name is already taken, as a name or legacy name of a registered chart type.
- flexmeasures.data.models.charts.chart_types.register_sensor_chart_type(chart_type: SensorChartType) SensorChartType
Add a chart type to the registry of sensor chart types.
Plugins call this when they are set up (e.g. in their
__init__), after which the sensor chart endpoint accepts the chart type’s name and the sensor page offers it on the sensors it applies to. To avoid clashing with chart types FlexMeasures may add later, prefix the name with the plugin’s name (e.g."my-plugin-duration-curve").- Parameters:
chart_type – the chart type to register.
- Returns:
the registered chart type.
- Raises:
ValueError – if its name or legacy name is already taken, as a name or legacy name of a registered chart type.
Classes
- class flexmeasures.data.models.charts.chart_types.AssetChartType(name: str, label: str, description: str, applies_to: Callable[['GenericAsset'], bool], layout: Callable[[list[dict]], list[dict]], builder: Callable[..., dict], legacy_name: str | None = None)
A chart an asset can be drawn as.
Plugins can add their own, using register_asset_chart_type. These fields are provisional: they may still change before plugins can rely on them.
- Parameters:
name – the public, kebab-case name, as API users pass it in
chart-type.label – the name shown in the UI.
description – what the chart shows, for the API documentation.
applies_to – whether the chart type is meant for this asset.
layout – the graphs the chart draws, given the asset’s validated
sensors_to_show.builder – the function that builds the chart’s Vega-Lite specs from the asset’s validated
sensors_to_show.legacy_name – the name of the builder, which the chart endpoint took before the chart types had public names.
- class flexmeasures.data.models.charts.chart_types.ChartType
What the asset and sensor chart types have in common: a public name, an optional legacy name, and a builder of Vega-Lite specs.
- class flexmeasures.data.models.charts.chart_types.ChartTypeRegistry(kind: str, unknown_error: type[UnknownChartType])
The chart types of one kind (asset or sensor chart types), by their public names.
It also maps the legacy names, which the chart endpoints took before the chart types had public names, to those public names.
- __init__(kind: str, unknown_error: type[UnknownChartType])
Set up an empty registry.
- Parameters:
kind – what the chart types draw, as named in messages (e.g. “asset”).
unknown_error – the error to raise for a name that is not in the registry.
- get(name: str, accept_legacy_name: bool = True) ChartTypeT
Look up a chart type by its name.
- Parameters:
name – the public name of the chart type, or (if accepted) its legacy name.
accept_legacy_name – whether to also accept the legacy name.
- Returns:
the chart type.
- Raises:
UnknownChartType – (in fact, the registry’s unknown_error) if no chart type goes by that name.
- register(chart_type: ChartTypeT) ChartTypeT
Add a chart type to the registry.
- Parameters:
chart_type – the chart type to register.
- Returns:
the registered chart type.
- Raises:
ValueError – if its name or legacy name is already taken, as a name or legacy name of a registered chart type.
- class flexmeasures.data.models.charts.chart_types.SensorChartType(name: str, label: str, description: str, applies_to: Callable[['Sensor'], bool], builder: Callable[..., dict], legacy_name: str | None = None)
A chart a sensor can be drawn as.
Plugins can add their own, using register_sensor_chart_type. These fields are provisional: they may still change before plugins can rely on them.
- Parameters:
name – the public, kebab-case name, as the sensor chart endpoint takes it in
chart-type.label – the name shown in the UI.
description – what the chart shows.
applies_to – whether the chart type is meant for this sensor.
builder – the function that builds the chart’s Vega-Lite specs, from the sensor, the window of events (
event_starts_afterandevent_ends_before) and further chart settings.legacy_name – the name the chart endpoint took before the chart types had public names.
Exceptions
- exception flexmeasures.data.models.charts.chart_types.UnknownAssetChartType
Raised for a name that is not in the registry of asset chart types.
- exception flexmeasures.data.models.charts.chart_types.UnknownChartType
Raised for a name that is not in a registry of chart types.
- exception flexmeasures.data.models.charts.chart_types.UnknownSensorChartType
Raised for a name that is not in the registry of sensor chart types.