New load forecast code#4101
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new days_previous_auto mode that replaces the fixed days_previous averaging with a weighted “bucketed” historical load forecast built from all available history (up to a capped window), and updates docs/tests accordingly.
Changes:
- Added
days_previous_autoconfig option plus a new weighted historical load forecast implementation (compute_load_forecast_history) and wiring to enable it during sensor fetch. - Refactored load filtering to apply car/iBoost filtering per-day before weighted averaging, and added new unit tests for the new forecast mode and filtering logic.
- Updated documentation and repo guidance (AGENTS.md), and expanded cspell dictionary.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/apps-yaml.md | Documents the new days_previous_auto weighted historical load forecast behavior and weighting factors. |
| apps/predbat/unit_test.py | Registers new test modules in the test runner. |
| apps/predbat/tests/test_single_debug.py | Makes expected-vs-actual plan comparison value-based instead of raw JSON string comparison. |
| apps/predbat/tests/test_load_forecast_history.py | Adds coverage for weighted historical forecast logic and holiday reconstruction behavior. |
| apps/predbat/tests/test_filtered_load_minute.py | Adds coverage for per-window/per-day filtering and averaging behavior. |
| apps/predbat/predbat.py | Initializes the new load_forecast_history flag in reset. |
| apps/predbat/fetch.py | Implements the weighted-bucket historical forecast, holiday history reconstruction, and refactors load filtering. |
| apps/predbat/const.py | Adds LOAD_FORECAST_HISTORY_MAX_DAYS constant (30-day cap). |
| apps/predbat/config.py | Adds schema entry for days_previous_auto. |
| AGENTS.md | Adds repository guidance for agents (tests, pre-commit, architecture notes). |
| .cspell/custom-dictionary-workspace.txt | Adds “backtest” and “holdout” to spell-check dictionary. |
…pred into fix/load_forecast_new
…pred into fix/load_forecast_new
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
Adds a new weighted-bucket historical load forecast (enabled with
days_previous_auto), and fixes how car‑charging hold is applied in the legacydays_previousaveraging.New: weighted-bucket load forecast (
days_previous_auto)Set
days_previous_auto: Trueinapps.yamlto switch house‑load prediction from the fixeddays_previousaveraging to a weighted‑bucket forecast. This is more robust when there are gaps in the load history or when usage patterns change (e.g. returning from holiday), because it no longer depends on a small number of specific days all being present and representative.max(days_previous)(or 7 days ifdays_previousis not set), capped at 30 days.weekday × holiday × age:1.0same weekday as the slot;0.7if different but both weekday or both weekend;0.5cross (weekday vs weekend).×0.5when the holiday‑mode state at the moment the sample was recorded does not match today's. Historical holiday state is reconstructed from the recordedholiday_days_lefthistory (viaminute_data) and matched per 5‑minute bucket so a mid‑day change of holiday mode is handled correctly.0.9for yesterday, reducing by0.03/day down to a floor of0.1.load_forecast+load_forecast_only).load_mltakes precedence if both are enabled.Fix: car‑charging hold applied per day before averaging
The legacy
days_previouspath averaged the selected days first and only then applied the car‑charging‑hold threshold. A single day's EV charge therefore got diluted below the threshold by the other (lower‑load) days and leaked into the house‑load forecast (e.g. an evening forecast spiking to ~3 kWh when no individual recent day was that high).get_filtered_load_minutenow applies the car/iBoost subtraction and the car‑charging‑hold threshold to each previous day individually and only then weighted‑averages them (newget_filtered_load_windowhelper). This matches the per‑sample behaviour of the new weighted‑bucket forecast.Other changes
load_today_comparisonthat read minutes beforeminutes_nowget the right values) and correctly handles midnight crossings — each slot samples whole, distinct days at the slot's time‑of‑day.--debug) and thedebug_casesregression suite now exercise the same recompute path (newredoflag /--noredo), and the plan comparison is value‑based rather than a raw JSON string compare (robust to numpy‑vs‑python float repr).Tests & docs
test_load_forecast_history.py: weekday/age weighting, per‑bucket holiday weighting, zero‑bucket exclusion, short/gappy history,days_previous_autoactivation, per‑day car‑charging hold, and cumulative‑from‑midnight / midnight crossing.test_filtered_load_minute.py:get_filtered_load_window/get_filtered_load_minute(raw, car/iBoost subtraction, hold threshold, historical weighted averaging, base load).docs/apps-yaml.md: documentsdays_previous_auto.