Skip to content

Aggregation reporter: select sensors by asset, name and unit - #2525

Open
Ahmad-Wahid wants to merge 4 commits into
mainfrom
feature/2520-aggregation-reporter
Open

Aggregation reporter: select sensors by asset, name and unit#2525
Ahmad-Wahid wants to merge 4 commits into
mainfrom
feature/2520-aggregation-reporter

Conversation

@Ahmad-Wahid

Copy link
Copy Markdown
Contributor

Description

A site usually wants its sensors as one aggregated signal — all the PV on site, so it can be
forecast and used in flex scheduling. Until now the AggregatorReporter could do that only if every
sensor was named by hand in the report parameters, which does not survive an inverter being added.

The reporter now selects its own sensors, through four new config fields:

  • asset — aggregate the sensors of this asset and of all of its offspring, so pointing at a site asset covers everything below it.
  • sensors — aggregate these sensors, listed by ID.
  • sensor_name_pattern — keep only the sensors whose name matches this regular expression.
  • sensor_units — keep only the sensors recording in one of these units, or in a unit measuring the same quantity, so ["MW"] also keeps a sensor recording in kW, but not one recording in MWh.
method: sum
asset: 3
sensor_name_pattern: "(?i)pv"
sensor_units: ["MW"]

Sensors named in the input parameters still work, and are read as described there; the selected
sensors are added to them. input is therefore no longer required in the parameters — a selection in
the config is enough, and a reporter that selects nothing at all says so, rather than failing later
inside Pandas.

Units and resolutions are reconciled with the output sensor. A discovered sensor cannot be
hand-checked, so values are converted to the unit of the output sensor and read at its resolution.
That is what makes a roof recording 100 kW in quarter-hourly events and a carport recording 0.2 MW in
hourly events add up to 0.3 MW on an hourly MW sensor. Passing a resolution parameter still wins
over the output sensor's, convert_units: false aggregates the raw values, a sensor without a unit is
never converted (an empty unit says nothing about what its values mean, so it draws a warning), and a
sensor whose quantity the output sensor cannot express — a temperature onto a power sensor — is
reported as an error instead of being silently added up.

The output sensor is left out of the aggregation. A report is often recorded on a sensor of the
very asset being aggregated, and reading it back in would fold each run's own previous output into the
next one.

Accountability. The selection lives in the config, not in the parameters, so it is recorded on
the reporter's data source alongside the method and weights, and a changed selection yields a new data
source. input_sensors reports the selected sensors too, so an automation validating what a reporter
reads sees the same sensors the reporter will read.

  • Added changelog item in documentation/changelog.rst

How to test

pytest flexmeasures/data/models/reporting/tests/test_aggregator.py

Eight tests are added, on a fixture whose PV sensors sit on a child and a grandchild asset, record in
kW and MW at quarter-hourly and hourly resolutions, and whose output sensor already holds a previous
report of 99 MW.

Each was verified to fail with the code it covers disabled — the breaks used were: dropping the
name-pattern filter, dropping the units filter, including the output sensor, skipping the unit
conversion, ignoring convert_units, not defaulting the resolution to the output sensor's, dropping
the empty-selection error, not overriding input_sensors, ignoring the sensors list, not walking
asset.offspring, skipping the regex validation, and taking asset as a plain int rather than an
asset. Every new test went red under at least one of them, and the whole set is green with the code in
place.

The 15 pre-existing aggregator tests are untouched and still pass, as do the reporting, schema, CLI
and API report-trigger suites.

Further improvements

Two items of #2520 depend on PRs that have not landed yet, so they are noted rather than done here:

sensor_units matches on dimension rather than on the exact spelling, which is what makes it useful
next to the unit conversion; a caller wanting an exact-spelling filter would need a further option.

Related items

Closes #2520.


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or another incompatible license.

🤖 Generated with Claude Code

Ahmad-Wahid and others added 3 commits September 11, 2026 16:46
Context:
- Issue #2520: a site often wants one aggregated signal (all its PV, say),
  which so far meant naming every sensor in the report parameters by hand.

Change:
- The config gains `asset`, `sensors`, `sensor_name_pattern` and `sensor_units`,
  which select the sensors to aggregate; `asset` covers an asset and its offspring.
- Values are converted to the unit of the output sensor, and read at its resolution,
  so sensors recording in different units and at different resolutions can be aggregated;
  `convert_units` turns the conversion off.
- The output sensor is left out of the aggregation, so a report can be recorded
  on a sensor sitting below the very asset being aggregated.
- `input_sensors` reports the selected sensors too, so the data source stays accountable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
…lection

Context:
- Issue #2520 adds sensor selection, unit conversion and resampling to the
  AggregatorReporter, none of which the existing tests reach.

Change:
- Add a site fixture whose PV sensors sit on a child and a grandchild asset,
  record in kW and MW, and report at quarter-hourly and hourly resolutions,
  with a previous report already on the sensor the aggregate is recorded on.
- Cover selection by asset, by sensor list, by name pattern and by units,
  the unit conversion and its `convert_units` switch, the refusal to aggregate
  a temperature onto a power sensor, an empty selection, an unparsable pattern,
  and the selection landing on the report's data source.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
Context:
- Issue #2520 lets the AggregatorReporter select its own sensors, which the
  reporting feature page did not describe.

Change:
- Describe the `asset`, `sensors`, `sensor_name_pattern` and `sensor_units` config fields,
  the conversion to the output sensor's unit and resolution, and the exclusion of the output sensor.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
@Ahmad-Wahid Ahmad-Wahid self-assigned this Sep 11, 2026
Context:
- PR #2525 lets the AggregatorReporter aggregate everything below an asset.

Change:
- Add a New features entry naming the asset, the narrowing filters
  and the conversion to the output sensor's unit and resolution.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Ahmad-Wahid <ahmedwahid16101@gmail.com>
@read-the-docs-community

Copy link
Copy Markdown

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.

Aggregation reporter

1 participant