Repository navigation
feat: Fill in a report template from the New automation form - #2797
Conversation
Verify that retrying a failed partial queueing attempt does not create duplicate jobs. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Convert YAML dates to ISO strings, accept empty files, and report non-object config or parameter files as usage errors. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Test YAML dates and timestamps, empty files, and invalid top-level list values for automation options. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Hide automation names and IDs from asset job responses when the current user cannot read the source automation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Verify inaccessible automation provenance is redacted while authorized callers still receive the full identity. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Show a persistent API error instead of presenting failed automation requests as an empty list. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Check that the automations page renders the warning target and hides the table when loading fails. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Avoid interpreting cron wildcard asterisks as RST italic markup when generating OpenAPI documentation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Verify cron wildcards remain unchanged while ordinary italic markup is still converted. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Document five-field cron expressions, at-most-once queueing attempts, and the automations API endpoint. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Record the automation endpoints, authorization-aware provenance, and five-field runner behavior. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Include the created_via field in the asset jobs OpenAPI example. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Add the trigger method required by the forecasting CLI to the regressor parsing test double. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Bring the forecast automation branch up to date with current main while preserving both branches' CLI, API, documentation, dependency lock, and generated OpenAPI changes. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Require every automation to reference a data generator and prevent deleting a data source while an automation still depends on it, matching the retention policy for belief and annotation sources. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Verify referenced generators cannot be deleted, generator references cannot be cleared, and automation API fixtures always use valid generators. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Allow forecast output only on the automation asset or its descendants and revalidate that relationship before every scheduled run, including explicit sensor-to-save targets. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Cover same-asset, child, grandchild, ancestor, and unrelated output targets, explicit sensor-to-save behavior, and runtime revalidation after an asset is moved. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Document output-sensor scope, runtime relationship checks, and the requirement to retain a generator while its automation exists. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Join the automation and main Alembic branches so installations have a single database upgrade target. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - PR #2293 is stacked on the reviewed forecast automation branch. Change: - Merge the reviewed parent and preserve schedule automation behavior across the five semantic conflicts. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Schedule automations do not use a data generator, but the reviewed forecast automation schema required one. Change: - Make the foreign key nullable while retaining a database check that forecasts always have a generator. - Add a forward migration without weakening data-source deletion semantics. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Review uncovered untested forecast-only options, invalid durations, and DST start calculation. Change: - Add CLI and trigger-preparation regressions while retaining forecast sensor validation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Persistence, inherited flex configuration, descendant statistics, and job counts lacked realistic coverage. Change: - Move automation service tests under the fresh-database fixture and add end-to-end schedule regressions. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - API provenance was not asserted across asset and sensor schedule jobs. Change: - Verify API trigger metadata on sequential descendants, wrap-up jobs, and sensor jobs. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - The asset automation page tests still targeted the former single table. Change: - Assert type-specific tables, error rendering, filters, and hidden-tab column adjustment. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Minimal asset schedules lost stored defaults, invalid timing could execute, provenance was incomplete, and descendant jobs were miscounted. Change: - Validate and floor fixed durations safely, inherit stored flex configuration, preserve provenance, and count the jobs actually dispatched. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Schedule automation creation silently accepted forecaster settings that could never affect scheduling. Change: - Detect supplied forecast-only options and return a user-facing usage error. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - DataTables initialized in the hidden schedule tab could render with stale column widths. Change: - Add tab accessibility state and adjust initialized table columns when a tab becomes visible. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - The feature guide linked only to the API root and omitted fixed-start and duration constraints. Change: - Document canonical fields, runtime start behavior, timing validation, and generator-free schedule automations. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…rom GET /api/v3_0/sensors Units are free text, so the units in use are checked once each, and the sensors filtered on those that fit. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A template's form block lists the unit or dimension a sensor field takes, and the fields whose sensors share a unit; the placeholder descriptions carry this, for the New automation form to narrow its sensor searches to. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…g unit A field searches for the unit or dimension its template says it takes, and a field sharing a unit with others follows the sensor picked for one of them; an input added to a sum takes what the template's own inputs take. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
… placeholder Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…heck Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
|
All five are in. The template key test lets |
nhoening
left a comment
There was a problem hiding this comment.
Review of #2797 — fill in a report template from the New automation form
Reviewed live in demo session 20261204-100112-flexmeasures-2797-a-report-template-in-t
(script demo.script, base http://localhost:5097, toy battery asset 6).
PR: #2797 (branch feat/2642-report-template-ui, stacked on #2300, closes #2642).
What the PR does
#2300 added prepared report templates, but using one meant exporting the YAML, looking up sensor IDs
elsewhere and replacing every FILL_IN by hand. #2797 lets the New automation form do that:
GET /api/v3_0/report-templatesand/report-templates/<name>list the packaged templates and
describe eachFILL_INplaceholder (section,path,location,kindsensor/value,label,
and which sensors fit it) —flexmeasures/api/v3_0/report_templates.py,
flexmeasures/data/services/report_templates.py.- With type
reporting, the form offers the templates by name in words, one field per placeholder:
a sensor search for sensor placeholders (the asset's own sensors first, narrowed to fitting units
through the newcompatible-unit/unit-dimensionfilters onGET /api/v3_0/sensors,
flexmeasures/api/v3_0/sensors.py+unit_fitsinflexmeasures/utils/unit_utils.py), a plain
labelled input for value placeholders. Create is refused while a field is empty, naming it, and
the API refuses a reporting automation with anyFILL_INleft, naming each per section
(refuse_unfilled_placeholders, called from_prepare_builtin_automationin
flexmeasures/data/services/automations.py). - The template's rolling window is pre-filled, the name is filled in from the template, and
Edit as JSON instead copies the filled-in template into the raw fields. The form presentation
lives in the template's ownform:block (summary,labels,units,same-unit,
add_inputs/input_weights), which the CLI ignores. - Type defaults in the form: the tab's type, per-type example placeholders in the empty fields, and
closing the form keeps the draft.
Seen working in the demo
On the toy battery (asset 6, sensors Production 500 kW, Consumption 200 kW, hourly, 3 days;
Self-consumption share, dimensionless, daily): New automation → reporting → self-consumption
laid out the three sensor searches, each listing this asset's sensors first; picking Production,
Consumption and Self-consumption share and pressing Create posted a reporting automation whose
parameters are the template with the three FILL_IN filled in and the window -1D,DB to DB.
Running it once (fm jobs run-automation --automation 1) succeeded live during the demo (the reviewer ran it
directly after the cli steps, which replay the rehearsal log): automation run 1 is succeeded, and the output
sensor Self-consumption share (12) holds the computed share 0.4 — 200 of 500 kW — at event_start
2026-12-03 00:00 Europe/Amsterdam (2026-12-02 23:00 UTC), i.e. exactly the previous day, the -1D,DB to DB
window the template pre-filled.
Requested changes
- No Create-time unit check across
same-unitplaceholders. The sensor searches are narrowed per
placeholder (unit_fits: a sensor inkWhalso "fits"kW, since a flow and its stock convert knowing
the resolution), and while picking through the form asame-unitfield follows the exact unit already
picked in its group (e.g. inself-consumption.yaml,parameters.input[0].sensorand
parameters.input[1].sensor). But nothing re-checks at Create time that same-unit placeholders ended up
in the same unit — a path that bypasses the search (the JSON view, a reopened draft) can still submit
mismatched units, which then only misbehave at run time in the elementwiseclip/div.
Decided in the demo (note n8): Create should refuse these, naming the fields (like it already refuses an
empty field); unparseable value placeholders (e.g.valid-rangebounds, cf.is_parseable_quantityin
flexmeasures/utils/unit_utils.py) should be refused the same way. - Value placeholders are typed by hand, and the template's config is not editable inline (only
via Edit as JSON instead). The labels ("Lowest valid value") help, but nothing validates a value
placeholder's format while typing (e.g. thevalid-rangebounds must parse as a quantity —
is_parseable_quantityexists inflexmeasures/utils/unit_utils.pyand could be reused). Please
validate value placeholders client-side before Create, or say why hand-typed is the intended split. - No help on the timing fields. The Start/End offset inputs (
#automationTemplateTiming) have no tooltip or
link, and the offset-chain syntax (-1D,DB= pandas offset aliases plus FlexMeasures'DB/HBday/hour-begin
steps, applied byapply_offset_chain()inflexmeasures/utils/time_utils.py) is not common knowledge.
We fix this ourselves after the demo (recorded in the follow-ups: a tooltip/help icon on both fields linking to
the "Timing each run" section of the automations docs,
https://flexmeasures.readthedocs.io/en/latest/features/automations.html#automation-timing, and the pandas offset
aliases, https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases, pushed to the
PR branchfeat/2642-report-template-ui). - The explanatory comments in the template YAML are lost when loaded (e.g. "The sensor recording
produced power/energy (positive values)." inself-consumption.yaml), andself-consumption,
daily-energyandregulariseresample to a fixed1D/15minthat must match the output
sensor's resolution, which the form cannot edit. Both are listed in the PR's own "Further
improvements"; please either move the comments intoform.labels/help text and let the form set
the resample resolution, or track them as follow-up issues so they don't get lost.
Suggestions (not blocking)
- Edit as JSON instead is one-way by design (
#automationTemplateToJsoncopies the filled-in template into
the raw fields and clears the template selection); the only way back to the template fields is re-picking
the template, which lays them out afresh. Decided in the demo (note n8): fine for now, but the button should
carry a tooltip saying the switch is one-way, so users can make a better choice. We can add that tooltip
ourselves and push it to the PR branch after the demo (offered during the demo). - The
placeholdersdescriptions are a good API; consider also exposing the template'sform.summary
in the listing response so clients need not load each template to show the hover text.
Notes from the demo (session 20261204-100112-flexmeasures-2797-a-report-template-in-t)
- n1 (step 19): where the template asks for the same unit —
form.same-unit/form.unitsin
self-consumption.yaml, exposed per placeholder byGET /api/v3_0/report-templates/<name>and applied
live by the narrowed sensor search (sensorUnitFilter). - n2/n3 (step 23): tooltip with docs link on the timing fields — agreed, recorded as a follow-up we push
ourselves (item 3 above). - n4 (step 31): config and parameters are both stored in the DB —
automation.parameters(JSONB) plus the
generatordata_sourcelinked viagenerator_id. - n5/n6 (step 34): the cli steps replay the rehearsal log, so the live run had not happened yet; the reviewer
ran the automation directly and the report was then validated live (0.4 on the output sensor). - n7/n8 (step 35, checkpoint): "same-unit placeholders" explained; decision — Create should also refuse
invalid values across same-unit placeholders; JSON view one-way accepted, with a tooltip saying so.
Context: - Review of PR #2797 (demo note n3) found the Start/End offset fields of a report template in the New automation form carry no help, though the offset-chain syntax is not common knowledge Change: - Add a help icon to both timing labels in asset_automations.html, whose tooltip explains the offset chain (pandas offset aliases such as -1D, plus the FlexMeasures-added DB day-begin and HB hour-begin steps, applied left to right by apply_offset_chain()) and links to the "Timing each run" section of the automations docs and to the pandas offset aliases - Cover it with a browser check in test_automation_new_form.py, and add a changelog entry Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
|
Follow-ups from the review demo (session 20261204-100112-flexmeasures-2797-a-report-template-in-t):
Nothing from the follow-ups list is left undone. |
…gelog entry - The tooltip's docs link is https://flexmeasures.readthedocs.io/latest/... (the /en/latest form 404s). - Delete test_the_template_timing_fields_explain_the_offset_chain_and_link_to_its_docs entirely. - Remove the second changelog entry for PR #2797; the PR keeps its single entry. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…late-ui Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> # Conflicts: # documentation/api/change_log.rst # flexmeasures/ui/templates/assets/asset_automations.html
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
…t under each field
nhoening
left a comment
There was a problem hiding this comment.
One thing deserves attention - the draft of the filled-in form is a JS variable (and not stored in localStorage or similar.
Navigating away from the Automations page entirely (or reloading it) can mean the draft is lost, because it's only in memory — it's never written to localStorage/sessionStorage or the server. So if you start filling in a template, click to the asset's Data page (or refresh, or leave and come back), the form starts afresh.
I believe that could be an easy fix - if not, at least document this danger.
The draft lived only in the page's memory, so a reload or a visit to another page of the asset lost what was typed into the New automation form. It is now kept per asset in session storage, saved when the page is left or the form is closed, and laid out again once the report templates are loaded, including a template's picked sensors, added inputs and weights. Clear form and Create forget it. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
|
The draft now outlasts a reload or a visit to another page: it's kept per asset in session storage, template, picked sensors, added inputs and weights included, and Clear form or Create drops it. |
Description
#2300 adds prepared report templates, but using one meant exporting the YAML, looking up sensor IDs elsewhere and replacing every
FILL_INby hand.This PR lets the New automation form do that. For example, on the Reporting tab, New automation → Self consumption shows three sensor searches (production, consumption, output) and the window
-1D,DBtoDB. Picking the three sensors and pressing Create gives a working daily self-consumption report.Report templates in the form
GET /api/v3_0/report-templates(and/report-templates/<name>) lists the templates, with aplaceholderslist describing eachFILL_IN: its section, location,kind(sensororvalue) and a label.reporting, a Report template list offers the templates by name in words (Aggregate sensors, Dynamic tariff, Self consumption, …). Hovering over one shows what it does in a sentence, e.g. Dynamic tariff: "Your energy price: the day-ahead price plus taxes, a supplier surcharge and VAT."valid-range, get a plain input with a label that says what to fill in ("Lowest valid value", not "0").weights.FILL_INleft as well, per section, e.g.config: Replace the 'FILL_IN' template placeholder at transformations[0].args[0].form:(asummary,labels, andadd_inputs/input_weightsfor Aggregate sensors). The CLI ignores it.Type defaults in the New automation form
New automation starts with the type of the tab in front: the Reporting tab starts a report, the Scheduling tab a schedule. A plugin-defined type's tab, which the form cannot create, falls back to
forecasting, as before.The empty data generator, config and parameters fields show each type's own example. With
reportingthey showed a forecast's (TrainPredictPipeline, aCustomLGBMconfig,{"sensor": 2092}); now aPandasReporterwith input and output sensors and a previous-day window.schedulingshows a next-day window, and a plugin type shows none. These are placeholders only: nothing is sent unless typed.Closing the form keeps what was typed, so New automation reopens the draft, with its type, rather than emptying it, even from another tab. Clear form starts afresh with the tab's type. Choosing only a type does not make a draft, and a copy only becomes one once something in it is changed.
Docs: the template flow in the reporting docs, the tab type and draft in the automations docs.
Look and feel
Template list, with the summary on hover:
Self consumption, with its sensors picked:
Sensor search, with the asset's own sensors first:
Aggregate sensors, with an added input weighted -1:
How to test
Or by hand: open an asset's Automations page, go to the Reporting tab, press New automation, choose Self consumption, pick the three sensors and create it. Run now fills the output sensor with the share of production consumed on-site. Then try Aggregate sensors with an added input weighted -1, and close the form half-filled and reopen it from another tab.
Further improvements
form.labelsor a help text would let the form show them.self-consumption,daily-energyandregulariseresample to a fixed1Dor15min, and ask you to edit that to match the output sensor's resolution. The form can't do that yet.Related Items
Stacked on #2300.
closes #2642
Sign-off