fix(measurement): use quality-aware meter energy for load and PV

Additional fixes
Measurement.meter_energy_kwh converts meter energy over the whole period in one read; the 31-day and 10000-interval limits apply to the public energy queries only.
Load intervals a meter does not fully cover are NaN and the load adjustment skips them; load_total_kwh returns an empty array for an empty store and keeps full last intervals.
The load adjustment compares over the period the load meters report, skips a stale load meter period and says when no load meter is configured.
PV calibration, snow feedback and the load adjustment fall back without measurements when a conversion fails, logged as error once per failure streak and consumer.
Measurement.keys_first_datetime and keys_last_datetime find each meter's first and last valid reading in bounded scans, keep each meter's newest reading and return stamps in the configured zone.
Measurement.keys_common_period derives the common meter period for PV calibration and the load adjustment and names the meter that ends it, also when meters share no period.
PV calibration warns once per stale period when a stopped PV meter holds it on old data; snow feedback warns once about a stale feedback meter.
Lasting meter conditions (silent, reset, gap, replaced meter, no shared period) are warned once per condition and consumer through one helper and warned again when they recur.
A replaced meter whose readings touch the new one is reported; a single reading is not; a meter group waiting for its second reading is an info once.
The PV meter resolution is detected from valid readings only (pre-existing), using one shared valid-reading rule in energy.py.
Stale meter stamps are compared with compare_datetimes; new meter tests create durations with datetimeutil.
The unused legacy Measurement._energy_from_meter_readings is removed; its test scenarios cover meter_energy_kwh.
The converter's range error no longer mentions the API's 31-day limit, and its duplicate interval check is gone.
Measurement and prediction docs describe the meter coverage rule, even gap spreading and when the load forecast stays unadjusted.
Tests reset the warn-once state of the shared measurement store and restore the EMS start they change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
Bobby Noelte
2026-11-15 18:30:00 +01:00
co-authored by Claude Opus 5.5
parent 2bfb6eafab
commit f441759dfa
11 changed files with 1161 additions and 301 deletions
+7 -1
View File
@@ -579,7 +579,9 @@ The `LoadAkkudoktorAdjusted` provider retrieves generic load data from the local
it to match the annual energy consumption specified in the
`LoadAkkudoktor.loadakkudoktor_year_energy` configuration option. In addition, the provider refines
the forecast by incorporating available measured load data, ensuring a more realistic and
site-specific consumption profile.
site-specific consumption profile. It compares the last 7 days that every configured load meter
reports; if a load meter has no readings or stopped reporting more than 7 days ago, the forecast
stays unadjusted and a warning names the meter.
Prediction keys:
@@ -905,6 +907,10 @@ keys in `measurement.pv_production_emr_keys` to fit the model against measuremen
Calibration preserves daily energy while optionally correcting the intraday
azimuth shape, clamps correction factors and respects inverter capacity.
Hourly meters are fitted hourly; native quarter-hour meters retain their cadence.
Meters may report at any time stamps: each interval gets the energy interpolated at its
boundaries. With several PV meters only the period all of them report is fitted, and
intervals a meter does not fully cover (a reset, or a gap longer than the channel's
`max_gap_seconds`) are skipped.
Probable outage or curtailment days are excluded by default. Without sufficient
usable measurements the uncalibrated physical model is used.