Repository navigation
Commit 42a4df5
Plan history: show the latest finished slot, and stop the false 'stale' warning (#5414)
* fix(plan history): rebuild once per completed slot, and judge staleness by each view's own refresh interval
The plan page's History view is built by calculate_yesterday() from what actually happened, at most once every 59
minutes. The live Plan view starts at the current slot, so the slots finished since the last rebuild showed in
neither view: at 21:35 the History stopped at 20:30 and the Plan started at 21:30. And the page judged every view
against the live plan's 15-minute stale limit, so on the History view it warned "Plan data is stale" for about
45 minutes of every hour although nothing was wrong.
- calculate_yesterday() now rebuilds once per completed plan slot (plan_interval_minutes), on the first re-plan at
least one run (5 minutes) after the slot ends, so the boundary run's own cost_today write is recorded before
its history is read back. A rebuild takes 0.4-0.9 s on a live install; at the default 30-minute slots that is
48 a day instead of 24 (before #2913 it ran on every re-plan, about 144).
- Each dataset the page shows carries refresh_minutes, the longest Predbat should take to republish it (the live
plan: calculate_plan_every; the plan history: a slot, the run it waits and a re-plan interval). The page warns
a run after that, never under 15 minutes, against the data the current view shows, and hides the warning when
the view has no data. At the defaults: Plan 15 minutes (as before), History 50.
Trade-offs, kept: with calculate_plan_every at or above the slot length, re-plans can fall on slot boundaries
and the rebuild then happens there; cost_yesterday and savings_yesterday_* roll over at the first re-plan after
00:05 rather than at 00:00; cost_yesterday/savings_yesterday_predbat, with their large html/json attributes, are
written twice as often.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(plan history): use RUN_EVERY, not PREDICT_STEP, for the one-run wait
history_slot() and history_refresh_minutes() wait one run past a slot boundary, and their docstrings
call that run PREDICT_STEP. One run is RUN_EVERY in const.py; PREDICT_STEP is the prediction step. Both
are 5 today, so nothing changes now, but if either changed the wait would quietly be wrong.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(plan history): keep the repeated hour at the autumn clock change as separate slots
history_slot() keyed slots by local date and wall-clock slot only, so the
first and second 01:35 on the night the clocks go back collapsed to one key.
With an hourly re-plan the second run was skipped and the History view went
two hours without a rebuild, past its advertised refresh interval.
Add the UTC offset to the key, and step back the one run in UTC rather than
on the wall clock, so the step lands on the right side of the change (pytz
keeps the old offset on wall-clock arithmetic; zoneinfo drops fold).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(plan history): rebuild on the midnight re-plan again
The one-run wait counts the 00:00 run towards the last slot of the day
before, so when the previous rebuild was already in that slot the forced
midnight re-plan skipped it. With an hourly re-plan, cost_yesterday and the
savings_yesterday sensors went on showing the day before yesterday until
01:00; main rebuilt at 00:00 because the date had changed.
Rebuild whenever the local date has changed as well as when the slot has.
Also correct a test comment that still called the schedule hourly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 0dbcce3 commit 42a4df5
7 files changed
Lines changed: 303 additions & 89 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
1939 | 1939 | | |
1940 | 1940 | | |
1941 | 1941 | | |
| 1942 | + | |
| 1943 | + | |
1942 | 1944 | | |
1943 | 1945 | | |
1944 | 1946 | | |
| |||
3193 | 3195 | | |
3194 | 3196 | | |
3195 | 3197 | | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
| 3213 | + | |
| 3214 | + | |
| 3215 | + | |
| 3216 | + | |
3196 | 3217 | | |
3197 | 3218 | | |
3198 | 3219 | | |
3199 | 3220 | | |
3200 | 3221 | | |
3201 | | - | |
3202 | | - | |
3203 | | - | |
3204 | | - | |
3205 | | - | |
3206 | | - | |
3207 | | - | |
| 3222 | + | |
| 3223 | + | |
| 3224 | + | |
| 3225 | + | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
3208 | 3230 | | |
3209 | 3231 | | |
3210 | 3232 | | |
3211 | 3233 | | |
3212 | 3234 | | |
3213 | 3235 | | |
3214 | 3236 | | |
3215 | | - | |
| 3237 | + | |
3216 | 3238 | | |
3217 | 3239 | | |
3218 | 3240 | | |
| |||
3256 | 3278 | | |
3257 | 3279 | | |
3258 | 3280 | | |
3259 | | - | |
| 3281 | + | |
3260 | 3282 | | |
3261 | 3283 | | |
3262 | 3284 | | |
| |||
3447 | 3469 | | |
3448 | 3470 | | |
3449 | 3471 | | |
| 3472 | + | |
3450 | 3473 | | |
3451 | 3474 | | |
3452 | 3475 | | |
| |||
3577 | 3600 | | |
3578 | 3601 | | |
3579 | 3602 | | |
| 3603 | + | |
3580 | 3604 | | |
3581 | 3605 | | |
3582 | 3606 | | |
| |||
0 commit comments