Skip to content

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

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

Flix6x wants to merge 30 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-38.

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>
@read-the-docs-community

read-the-docs-community Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
📖 214 files changed · 12 added · 148 modified · 54 deleted

Preview · build overview · flexmeasures · built Dec. 5, 2026, 11:24 a.m. UTC

…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

@Flix6x Flix6x self-assigned this Dec 2, 2026

@Flix6x Flix6x left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review of #2805 (with #2803 below it), at d270088.

What holds. chart_data now loads exactly what each chart type draws: for default, charge-point-sessions and both legacy names, the sensors in the data are the sensors the Vega-Lite chart filters on, and chart?include-data=true inlines the same set. An unknown chart-type gets a 422 naming the registered types (before, it silently returned every sensor), an empty one counts as none, and a plugin's chart type loads its own layout. The new tests fail on #2803 alone (10 of them) and pass here; flexmeasures/api/v3_0, flexmeasures/ui and the chart type tests all pass.

Before merging

  1. Read the Docs fails on this PR and on #2803: documentation/changelog.rst holds the v1.1.0 section twice (since #2803's merge of main, 03becfe), so the labels v1.1.0-add-report-warning and v1.1.0-roles-warning are defined twice.
  2. #2803 conflicts with main (both changelogs, customisation.rst, generic_assets.py, time_series.py, fast-chart.js), and this PR adds test_fast_chart.py to that. The API changelog entries sit in v3.0-35 | XX, 2026, while main's open section is v3.0-38 (and the PR description says v3.0-41).

We'll take care of both: merge main into #2803 (keeping the v1.1.0 section once and moving the API changelog entries to v3.0-38), then #2803 into this PR, and correct the version in the description.

For plugin authors. A chart type's layout decides what chart_data loads, and its builder what the Vega-Lite chart draws, and nothing ties the two: a plugin whose layout leaves out a graph its builder draws gets that graph empty. We'll push one line to this PR, in the AssetChartType docstring and in customisation.rst: the layout must hold every sensor the builder draws. That holds until #2795's renderer-neutral layouts make it structural.

Seen on the way (not from this PR). An asset without sensors_to_show gets suggested graphs in the old top-level sensors form, which the Vega-Lite builder skips, so its chart has no graphs while chart data loads the two sensors. We'll fix that in a separate PR off main: a missing sensors_to_show draws the suggested graphs again, and an explicit empty list means no graphs.

@Flix6x Flix6x added the enhancement New feature or request label Dec 2, 2026
Flix6x and others added 4 commits December 2, 2026 15:34
…in main

Move this PR's API changelog entries along into main's open section, v3.0-38.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
Chart data is loaded for the layout's sensors only, so a graph a plugin's
builder draws outside its layout comes up empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…in main's sessions tests by public name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
The replay and one-pass tests main brought in (#2882) render asset charts
without opts.chargePointChart, which an asset chart needs since this PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x

Flix6x commented Dec 2, 2026 •

Copy link
Copy Markdown
Member Author

Follow-ups of the review of #2805, one line per action:

  1. Layout must hold every sensor the builder draws: said in the AssetChartType docstring and in the plugin docs (customisation.rst), with a test, in d821360 (d8213607c).
  2. Assignee Flix6x and labels enhancement, UI, API, Plugin support added to Give chart types public names, in registries that plugins can add to #2803 and Let asset chart data rest on the registry of chart types #2805.
  3. Main merged into Give chart types public names, in registries that plugins can add to #2803 (6b7ca22, 6b7ca22a2) with the v1.1.0 changelog section kept once and the API changelog entry moved to v3.0-38. Then Give chart types public names, in registries that plugins can add to #2803 merged into Let asset chart data rest on the registry of chart types #2805 (4977b25, 4977b258d), with its API entries moved to v3.0-38 too. After the merge, main's new fast-chart tests needed the public chart type name and the Charge Points chart names: ae63c29 (ae63c29fb) and 09d615b (09d615b7a). The Let asset chart data rest on the registry of chart types #2805 description now says v3.0-38. CI and Read the Docs are green on both.
  4. New PR off main, so assets without sensors_to_show get their suggested graphs drawn and [] means no graphs: Draw the suggested graphs for an asset without sensors_to_show, and let [] mean no graphs #2953 (CI green, not merged, as the follow-up says).
  5. Merge: not done. Give chart types public names, in registries that plugins can add to #2803 is blocked because it needs an approving review (REVIEW_REQUIRED, and the author can't approve it), and Let asset chart data rest on the registry of chart types #2805 waits for Give chart types public names, in registries that plugins can add to #2803. What's left: once someone approves Give chart types public names, in registries that plugins can add to #2803, squash-merge it, retarget Let asset chart data rest on the registry of chart types #2805 to main, merge main into Let asset chart data rest on the registry of chart types #2805 and squash-merge it.
  6. and 7. claude-tools: the end screen now refreshes when follow-ups.md changes, "Update tools" is offered in a worktree too (or the end screen says why not), and other tabs say they close when the demo ends: SeitaBV/claude-tools#42 (merged).

test_each_chart_type_draws_the_graphs_and_sensors_of_its_layout already checks
that the built-in chart types' layouts hold what their builders draw; a test of
the docstring's words only makes rewording it harder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>

@Flix6x Flix6x left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked #2805 at 09d615b and #2803 at ae63c29, after the follow-ups of the review. The merges kept both sides of every conflict, except the fast chart's session hover helper, which main had removed along with the series it served; each PR's own diff is otherwise unchanged, apart from the changelog entries (now in v1.2.0 and v3.0-38, with the v1.1.0 section once) and main's new fast chart tests, which now use the public chart type names and pass the Charge Points chart's names. The chart type, API and UI tests pass, the fast chart tests with the real ECharts too.

One more commit drops the test of the layout note's wording, since the fresh-db test already checks each built-in chart type's layout against what it draws. Once CI is green with that commit, we merge this PR into #2803, merge main into #2803 again, and merge the stack.

…in main again

Keep both New features entries in the changelog: this PR's chart data entry and
main's #2713 entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants