Skip to content

Prepared report templates#2300

Draft
Flix6x wants to merge 2 commits into
feat/2288-report-automationsfrom
feat/2288-report-templates
Draft

Prepared report templates#2300
Flix6x wants to merge 2 commits into
feat/2288-report-automationsfrom
feat/2288-report-templates

Conversation

@Flix6x

@Flix6x Flix6x commented Jul 11, 2026

Copy link
Copy Markdown
Member

Description

Part of the "Reports as automations" story of #2288: hosts can now discover and use prepared report templates — ready-made report definitions (reporter class + complete config + parameters skeleton) — instead of authoring reporter YAML from scratch.

What's included

Packaged templates (flexmeasures/data/templates/reports/, shipped in the wheel):

  • energy-costs (ProfitOrLossReporter): energy costs over the reporting window, from a power/energy sensor and a consumption price sensor (costs reported as positive values, via loss_is_positive).
  • self-consumption (PandasReporter): share of produced energy consumed on-site, from a production and a consumption sensor (elementwise min(production, consumption) averaged per reporting period, divided by average production).

Each template contains name, description, reporter, a complete config, and a parameters skeleton with FILL_IN sensor placeholders, plus a recommended rolling reporting window (start-offset: -1D,DB / end-offset: DB) for recurring use.

CLI:

  • flexmeasures show report-templates lists the templates (name, reporter, description); --name <name> prints the full commented YAML, ready to pipe to a file.
  • flexmeasures add report --template <name> and flexmeasures add automation --type reports --template <name> load the template's reporter/config/parameters as defaults. User input wins: an explicit --reporter is kept, top-level keys of --config/--parameters files override the template's, and user-provided timing fields (start/end/offsets, in the parameters or as CLI options) replace the template's recommended window as a group.
  • Placeholders left unfilled abort with a clear validation error listing the exact fields to fill in.
  • Offset fields (start-offset/end-offset) inside a parameters file now also work for flexmeasures add report (as fallbacks for the CLI options), matching how report automations store their rolling window.

Tests (flexmeasures/cli/tests/test_report_templates.py, 5 tests):

  • Both templates' configs and (filled-in) parameter skeletons load cleanly against their reporter's schemas.
  • show report-templates lists both templates and prints valid YAML per template.
  • add automation --type reports --template self-consumption with a parameters file that fills the sensors creates a working automation: running it queues a reporting job, and a worker computes and stores the expected daily self-consumption shares.
  • Unfilled placeholders, unknown templates and --template on non-report automations produce clear errors.

Docs: new "Report templates" section in documentation/features/reporting.rst, CLI changelog bullets, and a show report-templates row in the commands overview.

Packaging note: verified that the YAML templates are included in the built wheel (hatchling ships all files under the flexmeasures package); no MANIFEST/package-data changes needed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX

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
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.

1 participant