Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/stream-resync"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Slice 5 of 5 (stacked on #59). Closes #5 and #42. The energy is already real-time (slice 4); this bounds its long-term accuracy against the server's authoritative hourly buckets.
What
When the stream owns the live total, each new server
QUANTITY/HOURbucket for a completed UTC hour RECONCILES the total instead of accumulating:The existing
bucket_dt > last_bucket_tshigh-water-mark guard ensures each completed+published hour reconciles exactly once and the current in-progress hour is never touched. When the stream is not active, buckets accumulate intototal_wh(unchanged fallback).Self-healing / gap recovery
If the stream missed a whole hour,
live_by_hourlacks it →drift = server_val - 0 = server_valfills the gap from the authoritative bucket.Spike finding (validates the design)
A live spike across two hour rollovers (14:00 and 15:00 UTC) observed zero QUANTITY measurements on the stream — the WebSocket feed pushes only FLOW (power) + STATE (switch), never energy buckets. So the REST QUANTITY/HOUR poll is the only source of authoritative energy, and this REST re-sync is necessary (the stream cannot provide it).
Bucket-labeling assumption
Server
bucket_dtassumed START-of-hour (matches the live accumulator's sample-hour key). Documented in the method docstring; one-line fix if real data proves END-labeled.Known follow-ups (Minor, for a later fix PR)
live_total_whwrite-back can clobber event-loop deltas arriving during the QUANTITY HTTP fetch (<0.1%/yr, self-healed at next reconciliation). Fix: apply only the reconciliation drift as+=instead of overwriting.live_by_hourgrows unbounded (one entry/hour). Add pruning of hours older than the high-water mark.Tests
6 tests (T1-T6) with exact reconciliation arithmetic + repurposed slice-4 test. 69/69 passing, ruff + mypy clean.
Stacking
Base:
feat/stream-energy(PR #59). Rebase down the stack tomainas each merges.Landed in
mainvia the linear stack fast-forward (commit9d016f7). This slice is part of the streaming feature merged as #56…#62 — closing (its commits are already inmain).Pull request closed