Repository navigation
RCE on DST days: period labels from PSE's UTC fields - #54
Merged
Merged
Conversation
PSE's `period` text is a correct interval, but its start alone is
misleading on DST days: the fall-back day's first repeated quarter is
"03:00 - 02a:15" (03:00 CEST), the 03:00 CET quarter is
"03a:00 - 03:15", and the spring-forward day has "02:00 - 03:15".
Using that start as the label read the first repeated quarter an hour
late and sorted "03a:00" after "03:45", so on 2026-10-25 the export
bands for 02:00-04:00 were scrambled.
Labels now come from dtime_utc/period_utc converted to Warsaw time
('02a:00'..'02a:45' for the repeated hour), which sort chronologically
as text. rce_storage relabels DST days already in the cache once
(PRAGMA user_version 1), in place, since export_price only reads the
cache. Tests use the real PSE responses for 2026-10-25 and 2026-03-29.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On DST days, the start of PSE's
periodtext doesn't tell you when the quarter starts. The text is a correct interval, but we only used its start as the label:periodperiod_utc02:45 - 03:0002:4503:00 - 02a:1503:0002a:15 - 02a:3002a:1502a:45 - 03a:0002a:4503a:00 - 03:1503a:0003:45✗02:00 - 03:1502:00rce_storage.get_cached_pricesorders by the label as text. On 2026-10-25 the export bands sent to Predbat for 02:00-04:00 were scrambled:Every band from 04:00 on was correct (checked against PSE by
dtime_utc). The import tariff was flat all that Sunday, so in practice nothing went wrong.Fix
rce.convert_to_series_15minnow builds the label fromdtime_utc(end of the period) minus theperiod_utclength, converted to Europe/Warsaw. The repeated hour getsHHa:MM(fold=1). Labels are02:45,02a:00, ...,02a:45,03:00. They sort chronologically as text, andexport_price._parse_period_startalready reads them. The existingexport_priceDST tests already assumed this shape. The query also selectsperiod_utc,dtime_utc.rce_storage.init_dbrelabels DST days that are already in the cache, once (PRAGMA user_version0 → 1). This is done in place, not by dropping and re-fetching, becauseexport_priceonly reads the cache. Dropping today would leave Predbat without export prices until midnight. The version is re-checked underBEGIN IMMEDIATE, so two threads can't relabel twice.03:00→02a:00,03a:00→03:00.02:00but no03:00):02:00→03:00.Tests
tests/fixtures/.init_dbdoesn't relabel again; a new DB starts at the current version.main. The full suite passes on Python 3.14 (606 passed)..backupsnapshot of the Pi'srce_prices.db. 2026-10-25 comes out as 100 / 25 contiguous bands. 02:00-03:00 CET = 0.4837 (mean 393.28 × 1.23) and 03:00-04:00 CET = 0.4244 (345.06 × 1.23), both matching PSE.Not in this PR
On the fall-back day, inverter history timestamps still come from the inverter clock (naive, fold=0), so one hour of history is ambiguous. That needs a separate change: stamp samples with the Pi's NTP clock.
🤖 Generated with Claude Code