flexmeasures.data.services.report_templates

Logic for loading prepared report templates.

Report templates are YAML files packaged in flexmeasures/data/templates/reports. Each template describes a ready-made report definition: a reporter class, a complete reporter config and a parameters skeleton in which users fill in their own sensors (replacing the FILL_IN placeholders).

Functions

flexmeasures.data.services.report_templates.describe_placeholders(template: dict) → list[dict]

Describe each placeholder a report template leaves open, so that a form can offer one field per placeholder.

Each description says which part of the template it is in (config or parameters), where in that part it sits (as a path and as the list of keys and indexes leading to it), whether it takes a sensor ID (kind is sensor) or another value (kind is value), and a label for the field. A template can name the label itself, under form.labels, keyed by section and path, which it does where the key alone says too little, such as for the bounds passed to a method as its first argument.

A sensor placeholder also says which sensors fit it, as far as the template’s form block says so, for a form to narrow its sensor search to: a unit the sensor’s unit converts to (under form.units), a dimension its unit has (under form.dimensions), same-unit if its sensor is in the same unit as the other placeholders listed under form.same-unit, and compatible-units if its unit converts to theirs, for those listed under form.compatible-units. In these, [*] stands for any index, which covers inputs a form adds as well, such as parameters.input[*].sensor.

flexmeasures.data.services.report_templates.find_placeholders(obj: Any, root: str = '') → list[str]

List the paths of any unfilled template placeholders in the given (nested) object.

flexmeasures.data.services.report_templates.get_report_template(name: str) → dict | None

Load the packaged report template with the given name, if it exists.

flexmeasures.data.services.report_templates.get_report_template_text(name: str) → str | None

The raw YAML of the packaged report template with the given name, if it exists.

Unlike get_report_template, this preserves the explanatory comments, so users can pipe the result to a file and edit it.

flexmeasures.data.services.report_templates.list_report_templates() → list[dict]

Load all packaged report templates (sorted by name).

flexmeasures.data.services.report_templates.merge_template_parameters(template_parameters: dict, user_parameters: dict, user_provided_timing: bool = False) → dict

Merge user-provided report parameters on top of a template’s parameters skeleton.

Top-level keys provided by the user win. Timing fields are treated as a group: if the user provides any timing field (or user_provided_timing is set, e.g. because timing was given through CLI options), the template’s recommended timing fields are dropped altogether.

flexmeasures.data.services.report_templates.refuse_unfilled_placeholders(config: dict | None, parameters: dict | None) → None

Refuse a report definition in which any template placeholder is still unfilled.

A placeholder left in would fail every run, or be computed with as if it were a value, without saying which value was left out.

Raises:

marshmallow.ValidationError – naming each unfilled placeholder, under the part of the definition it is in.