Prepared report templates - #2300
Open
Flix6x wants to merge 10 commits into
Open
Conversation
Hosts can now discover and use ready-made report definitions (reporter class + complete config + parameters skeleton) instead of authoring YAML from scratch: - Two templates ship in flexmeasures/data/templates/reports: energy-costs (ProfitOrLossReporter) and self-consumption (PandasReporter), each with FILL_IN sensor placeholders and a recommended rolling reporting window for recurring use. - `flexmeasures show report-templates` lists them; `--name <name>` prints the full YAML (with comments) to pipe to a file. - `flexmeasures add report` and `flexmeasures add automation --type reports` accept `--template <name>`, using the template as defaults under any --config/--parameters files and other options (user keys win; user-provided timing fields replace the template's window). - Unfilled placeholders produce a clear validation error listing the fields to fill in. Part of #2288 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
Documentation build overview
155 files changed ·
|
Context: - PR #2300 is stacked on #2297, whose automation, timezone, permission, and CLI validation changes advanced after the template branch diverged. Change: - Merge the updated report-automation branch while preserving prepared-template commands and combining them with the current automation CLI validation and output-scope invariant. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Combining a prepared template with an existing data source silently discarded the template reporter configuration, while non-object override files crashed during dictionary merging. Change: - Make source and template selection mutually exclusive and route report override files through the shared mapping validator so invalid YAML shapes produce actionable CLI errors. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - The template roundtrip did not exercise output-scope enforcement, competing source selection, malformed override files, or reporting periods without production. Change: - Target the automation's actual output asset and add regressions proving ambiguous inputs are rejected, override files require mappings, and zero production leaves self-consumption undefined. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Prepared templates need explicit guidance for competing stored sources and for self-consumption periods where the denominator is zero. Change: - Document that templates cannot accompany an existing source and that zero production yields an undefined, missing self-consumption value. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…plates Context: - Picking up the review changes from #2290 and the automation work below this branch. - Both sides had a check that refuses forecaster options on a schedules automation, in two generations: this branch still guessed from configuration values that differ from their default, while upstream only counts options actually given on the command line. Change: - Kept this branch's report template handling and upstream's stricter check, rather than either side wholesale, which would have dropped one or reverted the other. - Regenerated the OpenAPI specs. Signed-off-by: F.N. Claessen <felix@seita.nl>
…to HEAD Signed-off-by: F.N. Claessen <felix@seita.nl>
…to HEAD Signed-off-by: F.N. Claessen <felix@seita.nl>
…plates Follows the automation type rename that came up the stack: `--type reports` is now `--type reporting`, in the template CLI options, their tests, `flexmeasures show report-templates` and the reporting chapter. Kept both sides of `flexmeasures add automation`: the template resolution and its placeholder check, and the dry-run guard the base added. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Defining a report means writing reporter configuration, and writing it from nothing is the step that
stops people defining reports at all. FlexMeasures now ships prepared report templates: a reporter
class, a complete configuration and a parameters skeleton, ready to fill in and run.
Two templates, packaged under
flexmeasures/data/templates/reports/and shipped in the wheel.energy-costsuses theProfitOrLossReporterto report energy costs over the reporting window, froma power or energy sensor and a consumption price sensor, as positive values.
self-consumptionusesthe
PandasReporterto report the share of produced energy consumed on-site, from a production and aconsumption sensor: the elementwise minimum of the two, averaged per reporting period, over average
production.
Each template is complete except for the sensors. It carries a name, a description, the reporter,
a working configuration, and a parameters skeleton whose sensors are
FILL_INplaceholders. It alsocarries a recommended rolling window —
start-offset: -1D,DB,end-offset: DB— which is what makesa template useful to a recurring report rather than only a one-off.
Discovering them.
flexmeasures show report-templateslists the templates with their reporter anddescription;
--nameprints one in full, as commented YAML, ready to redirect to a file and edit.Using them.
--templateonflexmeasures add reportand onflexmeasures add automation --type reportingloads the template's reporter, configuration andparameters as defaults:
What the user writes always wins, at a deliberate granularity. An explicit
--reporteris keptover the template's. Top-level keys of a
--configor--parametersfile override the template's.Timing fields —
start,endand the offsets, whether in the parameters file or given as CLIoptions — replace the template's recommended window as a group, so a half-overridden window can
never be assembled out of two different intentions.
Placeholders left unfilled abort with a validation error naming the exact fields still holding
FILL_IN, rather than failing later inside the reporter with something less legible. Combining--templatewith--sourceis refused, since the data source already determines the reporter andits configuration, and
--templateon a non-report automation is refused too.documentation/changelog.rstHow to test
See the manual test walkthrough in the PR comments.
Eight tests. Both templates' configurations, and their filled-in parameter skeletons, are validated
against their reporter's own schemas, so a template that drifts from the reporter it names fails here
rather than in a user's terminal.
show report-templatesis checked to list both templates and toprint valid YAML for each. The end-to-end test fills in
self-consumption's sensors, creates theautomation, runs it, and checks the stored daily self-consumption shares. The error paths are covered
too: unfilled placeholders, an unknown template,
--templateon a non-report automation,--templatecombined with
--source, and an override file that is not a mapping. One test pins whatself-consumption means with no production at all, which is undefined rather than zero.
Further improvements
templates are cheap to add once its shape is agreed.
discovery path, and is not attempted here.
flexmeasurespackage — so noMANIFESTor package-data change was needed.Related items
Part of the automations story #2334, and of #2288. Stacked on #2297, which it needs for
--type reporting.Sign-off