fix(plan): widen forecast_minutes before building yesterday_load_step/yesterday_pv_step - #4419
Merged
springfall2008 merged 3 commits intoAug 3, 2026
Merged
Conversation
…/yesterday_pv_step calculate_yesterday() built these step-data dicts via step_data_history() while self.forecast_minutes was still the live plan's normal horizon. step_data_history() only fills offsets up to forecast_minutes + plan_interval_minutes, but the web plan "History" tab needs a full yesterday (24h) plus today-so-far up to minutes_now - so any offset past the live horizon silently read back as zero Load/PV for the rest of the day (reproduced live: forecast_plan_hours=30, Load kWh read 0 from ~06:00 onward every day, self-healing the next day). The widening fix already existed later in the function, just applied too late - after the step-data dicts were already built too small. Fixes #4418
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an incorrect “History” view calculation path in calculate_yesterday() where yesterday_load_step/yesterday_pv_step could be built with a too-small forecast_minutes horizon, causing load/PV accumulation to silently fall back to zeros later in the day. It widens forecast_minutes earlier (before building the step-data dicts) and adds a regression test targeting the real-world reproduction parameters from issue #4418.
Changes:
- Widen
self.forecast_minutesbefore buildingyesterday_load_step/yesterday_pv_step, then restore it afterward. - Add a regression test that asserts
forecast_minutesis already widened at the firststep_data_history()call (and is restored after). - Document the rationale inline to prevent regressions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
apps/predbat/output.py |
Widen/restore forecast_minutes earlier in calculate_yesterday() so History-mode step data covers “yesterday + today so far”. |
apps/predbat/tests/test_calculate_yesterday.py |
Adds a regression test for issue #4418, validating the widening happens before step-data generation. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
Summary
calculate_yesterday()builtyesterday_load_step/yesterday_pv_stepviastep_data_history()whileself.forecast_minuteswas still the live plan's normal (too-small) horizon, so any offset past it silently read back as zero for the rest of the day.forecast_minutesbefore building those step-data dicts (the widening already existed later in the function, just applied too late), restoring it immediately after.forecast_plan_hours=30,minutes_now=910), verified it fails without the fix and passes with it.Fixes #4418
Test plan
./run_all --quickpassestest_calculate_yesterday.py) fails on the pre-fix code, passes on the fixrun_pre_commitclean