flexmeasures.data.services.reporting
Logic for queueing and running reporting jobs.
Functions
- flexmeasures.data.services.reporting.compute_and_save_report(reporter: Reporter, parameters: dict, permitted_output_sensor_ids: set[int] | None = None, automation_id: int | None = None) tuple[list[dict], list[dict]]
Compute a report, check it as compute_report does, and save it, as the synchronous CLI and the background worker both do.
It is saved the way every data generator’s results are, by save_generator_results: within a savepoint, so a report that fails halfway leaves none of its results staged, and without committing, which is left to the caller.
- Returns:
the computed results, and per result a summary of what was saved: the sensor id, the number of beliefs computed (“n_computed”), which counts every belief the report returned, and the number of beliefs saved (“n_rows”), which leaves out NaN values and beliefs that were already on record.
- flexmeasures.data.services.reporting.compute_report(reporter: Reporter, parameters: dict, permitted_output_sensor_ids: set[int] | None = None, automation_id: int | None = None) list[dict]
Compute a report, and refuse it if it would record on a sensor outside the permitted ones.
The outputs are judged before they are handed back, so that no caller receives results for unchecked sensors, also one that only shows them, as a dry run does.
- Parameters:
reporter – the reporter computing the report.
parameters – the reporter parameters to compute with.
permitted_output_sensor_ids – if given, every computed result must record on one of these sensors, or a GeneratorWritesUncheckedSensor error is raised. Pass None where no such check applies (e.g. the CLI).
automation_id – named in the GeneratorWritesUncheckedSensor error, if raised.
- flexmeasures.data.services.reporting.count_persistable_values(data) int
Count computed values that will not be dropped as NaN before persistence.
This does not account for valid values that
save_to_dbmay skip because they are unchanged.
- flexmeasures.data.services.reporting.create_reporting_job(reporter: Reporter, queue: str = 'reporting') Job
Queue a job that computes a report and stores its results.
- flexmeasures.data.services.reporting.run_report_job(data_source_id: int, parameters: dict) dict
Compute and store a report in a reporting worker.
The job’s result lists, under “outputs”, one entry per output sensor: the sensor (by ID), the number of beliefs computed (“num-computed-beliefs”) and the number of beliefs recorded (“num-recorded-beliefs”).
If the report was triggered by an automation, the end of the report window is recorded upon success, so the automation’s next default window starts where this one ended. A failed report job therefore leaves no permanent gap in the reported periods.