Skip to content

Let asset chart data rest on the registry of chart types - #2805

Open
Flix6x wants to merge 24 commits into
chart-type-registryfrom
2802-chart-data-on-registry
Open

Flix6x wants to merge 24 commits into
chart-type-registryfrom
2802-chart-data-on-registry

Conversation

@Flix6x

@Flix6x Flix6x commented Nov 3, 2026

Copy link
Copy Markdown
Member

Closes #2802.

Stacked on #2803 (the registry of asset and sensor chart types); this PR targets chart-type-registry and will be retargeted to main once #2803 merges.

What changes

  • GET /api/v3_0/assets/<id>/chart_data takes the registry's public chart type names as chart-type (default, charge-point-sessions, and any a plugin registers), validated as on GET /api/v3_0/assets/<id>/chart: an unknown name gets a 422. The names the asset page sent in v1.1.0 (chart_for_multiple_sensors, chart_for_chargepoint_sessions) are still accepted, and an empty value counts as no chart type. The parameter is now documented in the OpenAPI specs.
  • GenericAsset.chart_sensors takes the sensors per chart type from the chart type's layout in the registry, so the separate rules (and charge_point_chart_sensors) are gone: what chart data loads is what the chart draws, also for plugin chart types.
  • asset.chart(include_data=True), and so GET /api/v3_0/assets/<id>/chart?include-data=true and the chart's CSV export, inlines only the data of the chart type's own sensors, as chart_data does.
  • The fast (ECharts) chart gets the Charge Points chart's names (now CHARGE_POINT_CHART_NAMES in chart_types.py) from the page, and throws without them on an asset chart, rather than drawing the wrong graphs.
  • Changelog entries in v1.2.0, and API changelog entries in v3.0-41.

The branch was built on #2790 before it was squash-merged; it records #2790's final head as merged (tree unchanged) and then merges the local branch, so the diff against chart-type-registry holds only these changes.

How to test

  • pytest flexmeasures/api/v3_0/tests/test_asset_chart_data_fresh_db.py flexmeasures/data/tests/test_chart_types.py flexmeasures/ui/tests/js/test_fast_chart.py
  • On an asset with charge points, switch between the Default and Charge Points charts with the fast chart on and off: each loads only its own sensors (see the chart-type on the chart_data requests).
  • GET /api/v3_0/assets/<id>/chart_data?chart-type=charge-point-sessions&... returns the session sensors, the charge points power and the prices; chart-type=nope gets a 422.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf

Ahmad-Wahid and others added 22 commits October 31, 2026 21:50
On an asset with charge points, the Default chart and the Charge Points chart
shared one chart data request, which loaded every sensor in sensors_to_show.
The Default chart skips the "Charge Point sessions" graph, so its session
sensors were loaded and thrown away, and the Charge Points chart likewise
loaded everything to draw a few graphs.

GET /assets/<id>/chart_data now accepts chart-type and returns only the data
of the sensors that chart type draws (GenericAsset.chart_sensors). Without it,
it returns every sensor's data, as before. The asset page sends the selected
chart type, and loads that chart's data when the user switches charts; the
chart data cache no longer reuses records loaded for another chart type.

Closes #2789.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
… graph titles

Switching between the asset charts reloaded the data without stopping a replay,
which would keep drawing the previous chart type's data; and stopping a replay
redraws the Vega-Lite chart, so the reload now waits for it.

The "Prices" and "Power flow by type" titles were spelled out again in
GenericAsset.chart_sensors; both now come from belief_charts.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Co-authored-by: Ahmad-Wahid <59763365+Ahmad-Wahid@users.noreply.github.com>
… case of their titles

The Vega-Lite Charge Points chart capitalizes graph titles before matching them,
but chart_sensors compared the raw titles,
so a graph titled "prices" or "power flow by type" was drawn without its data.
One helper in belief_charts.py now decides which sensors of a graph the chart draws,
used by both chart_for_chargepoint_sessions and chart_sensors.
The power-flow filter now also matches the capitalized title,
and no longer mutates the caller's sensors_to_show.
The fast chart matches companion titles the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Per testing.instructions.md, modules using fresh_db end in _fresh_db.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
The field is new, so no older client sends chart_type,
and legacy aliases are for renamed fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Also say that the Charge Points chart lists its session sensors first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…nstants

fast-chart.js and graphs.html kept their own copies of the graph titles and the power sensor name.
They now get them from CHARGE_POINT_CHART_NAMES in belief_charts.py, through a Jinja global,
so renaming one no longer needs edits in three places.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Brings in the registry of asset chart types (issue #2795), on which chart_data's chart-type is to build.
Conflicts resolved as follows:
chart_sensors keeps its rules, but takes the public chart type names, which the asset page now sends (legacy names are mapped);
belief_charts.py keeps the registry's helpers next to CHARGE_POINT_CHART_NAMES and charge_point_chart_sensors;
and the registry's fast chart test hands the fast chart the Charge Points chart's names, which it needs since #2790.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…, and refuse unknown chart types

GenericAsset.chart_sensors now takes the sensors from the chart type's layout in the registry of asset chart types,
instead of matching graph titles itself, so what chart_data loads and what the chart endpoint draws come from one place.
chart_data checks its chart-type against the registry, and takes the same values as the chart endpoint:
"default" and "charge-point-sessions", and the deprecated legacy names, under chart-type or its snake_case alias.
Anything else gets a 422.
Without chart-type, or with an empty one (which main ignored), chart_data still returns every sensor in sensors_to_show.

The tests use the charge_hub_fresh_db fixture from flexmeasures/conftest.py, which this module's own fixture had become a copy of.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
… of asset chart types

CHARGE_POINT_CHART_NAMES moves from belief_charts.py to chart_types.py, next to the layout of the Charge Points chart that it describes.
The fast chart still lays out the graphs itself by these names, as before; taking the layout from the server is left for later (issue #2795).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…ic names

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…'s names

Without them, it drew an untitled sessions chart, or a default chart showing the session timestamps.
includes/graphs.html always passes them, so a missing set is a mistake in the caller;
throwing makes it show in the console and in tests, instead of in a subtly wrong chart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…hart with its data

GenericAsset.chart(include_data=True), which the CLI uses to save a chart, now takes the sensors from the chart type's layout, as chart_data does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…d the fast chart's lowercase titles fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…nly what it draws

Also, flexmeasures show chart writes an image, so it holds no data to narrow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…e only

Its values are the names of the chart functions, which public chart type names replace in v1.2.0 (#2795),
so the official API makes no promise about it yet: the OpenAPI specs leave it out, as they do beliefs-after,
and the API changelog no longer announces it. The endpoint still accepts it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
66efc23

The tree is unchanged: main's squash commit holds the same changes.
This gives the merge of the local branch built on #2790 a merge base that already has #2790's commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
… registry of chart types

Brings in the local branch built on #2790 and an earlier state of the registry (issue #2802):
chart_data's chart-type takes the registry's public chart type names (and plugin ones), validated as on the chart endpoint, still accepts the legacy names, and reads an empty value as absent;
GenericAsset.chart_sensors takes its sensors from the chart type's layout, so charge_point_chart_sensors and its own rules are dropped;
an asset chart with its data inlines only the data of the chart type's sensors;
and the fast chart takes the Charge Points chart's names from the page (now kept in chart_types.py), and fails loudly without them.

Conflicts resolved as follows:
the branch's side for the models, chart_data's field and its tests, which all build on the registry now;
the sensor page's belief tooltip keeps the public 'bar-chart' name, which the registry introduced since;
test_fast_chart.py keeps the registry's sensor chart type tests next to the branch's new ones;
and the changelog entries move to the v1.2.0 and v3.0-41 sections, leaving #2790's own v1.1.0 entry as it was merged.

chart-type on chart_data is now documented: AssetChartDataOpenAPISchema no longer excludes it, and its test checks it is in the published specs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x Flix6x added this to the 1.2.0 milestone Nov 3, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…ection renumbered to v3.0-35

Conflict resolved in documentation/api/change_log.rst: the base's entry on asset chart types loses its sentence on the 422 for an unknown chart-type (v3.0-34 already ships that), and this PR's two entries follow it.
The section heading arrives as v3.0-35 from the base, so this branch carries no v3.0-41 any more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x

Flix6x commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Merged the updated base (#2803) into this branch in d270088, which brings in main as well as the API section renumbered to v3.0-35 (v1.1.0 shipped with v3.0-34, see #2818).

The one conflict was in the API change log: this PR's two entries now follow the base's entry on asset chart types, under v3.0-35. Nothing on this branch refers to v3.0-41 any more. The chart type and chart data tests (Python and JS, 182) pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UBBvKZkzbfEPKctwTN8SDf

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants