Skip to content

fix: classify detailed readings as offpeak/peak on insert - #627

Open
Germwalker wants to merge 1 commit into
MyElectricalData:mainfrom
Germwalker:fix/detail-measure-type-classification
Open

fix: classify detailed readings as offpeak/peak on insert#627
Germwalker wants to merge 1 commit into
MyElectricalData:mainfrom
Germwalker:fix/detail-measure-type-classification

Conversation

@Germwalker

Copy link
Copy Markdown

Symptom

consumption_detail.measure_type (and production_detail.measure_type) is always an empty
string, for every row, on a stock 0.13.4 install. Any statistic or export based on detailed
(30-minute) readings that needs to split offpeak from peak reports 0 for the offpeak side.

Root cause

In Detail.parse_datas() (src/models/query_detail.py, around lines 126-144), the whole
block that computes measure_type from self.offpeak_hours and is_between() is commented
out, and a few lines below, insert_detail() is called with measure_type="" hard-coded.
Both dependencies the commented block needs are present and otherwise unused in this file:
self.offpeak_hours is built in __init__ (lines ~53-60) and is_between() is defined below
in the same module (~line 276). Nothing else in the file relies on the current disabled
state.

Open question — was this intentional?

Nothing in the code, comments, or commit history explains why this block is disabled — it
is already commented out in the 0.13.4 release, with no accompanying note. Before this is
merged: was this intentionally disabled, e.g. because of a known correctness issue with
is_between(), a performance concern on large imports, or something else not visible from the
diff alone? If so, this PR should be closed rather than merged. If it was simply dead code
that nobody got around to removing or re-enabling, then restoring it looks like the right fix
— happy to adjust based on your answer.

Fix

Restore the measure_type computation exactly as written (only reformatted to match the
project's quote style), and pass the computed value to insert_detail() instead of the
hard-coded "".

Proof (measured on real data)

Same 2.7-year dataset as the companion PR (offpeak hours propagation): 35272 rows in
consumption_detail, all with measure_type="" before this fix. After enabling both this fix
and the contract offpeak-hours propagation together, 35112 rows reclassify to HC/HP
correctly, and the offpeak/peak split (2025, one 15 kVA point) goes from HC=0 EUR /
HP=1396.17 EUR to HC=281.02 EUR / HP=1028.43 EUR.

Scope

One file, src/models/query_detail.py, 19 lines touched (all inside the existing block).
No other file touched.

Detail.parse_datas() computed measure_type for every detailed reading
(consumption/production, 30-min granularity) with is_between() against
self.offpeak_hours, but the whole computation was commented out and
insert_detail() was called with measure_type="" hard-coded. Both
is_between() (below in the same file) and self.offpeak_hours (built in
__init__) are otherwise unused, so nothing else depends on the current
disabled state.

Consequence: consumption_detail.measure_type (and
production_detail.measure_type) is always "", so Stat.get_mesure_type(),
which reads this column, cannot split any detailed reading into
offpeak/peak, and every offpeak/peak simulation based on detailed data
reports 0 EUR for the offpeak share regardless of the contract's
offpeak hours.

Nothing in the history or comments explains why this block was
disabled - it is already commented out in the 0.13.4 release, with no
accompanying note. Was this intentionally disabled, e.g. because of a
known correctness issue with is_between() or performance concerns on
large imports? If so this PR should be closed; if not, re-enabling the
existing code look like the fix.

Fix: restore the measure_type computation and pass the real value to
insert_detail() instead of the hard-coded "".
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.

1 participant