Skip to content

New load forecast code#4101

Merged
springfall2008 merged 12 commits into
mainfrom
fix/load_forecast_new
Jun 21, 2026
Merged

New load forecast code#4101
springfall2008 merged 12 commits into
mainfrom
fix/load_forecast_new

Conversation

@springfall2008

@springfall2008 springfall2008 commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a new weighted-bucket historical load forecast (enabled with days_previous_auto), and fixes how car‑charging hold is applied in the legacy days_previous averaging.

New: weighted-bucket load forecast (days_previous_auto)

Set days_previous_auto: True in apps.yaml to switch house‑load prediction from the fixed days_previous averaging 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.

  • Uses all available history within the search window, with no padding when fewer days exist. The window is taken from max(days_previous) (or 7 days if days_previous is not set), capped at 30 days.
  • For each forward 5‑minute slot, the historical samples at the same time‑of‑day are combined into a weighted average. Per‑sample weight = weekday × holiday × age:
    • Weekday: 1.0 same weekday as the slot; 0.7 if different but both weekday or both weekend; 0.5 cross (weekday vs weekend).
    • Holiday: ×0.5 when the holiday‑mode state at the moment the sample was recorded does not match today's. Historical holiday state is reconstructed from the recorded holiday_days_left history (via minute_data) and matched per 5‑minute bucket so a mid‑day change of holiday mode is handled correctly.
    • Age: 0.9 for yesterday, reducing by 0.03/day down to a floor of 0.1.
  • Zero (missing‑data) buckets are ignored entirely so gaps in the history do not drag the estimate down.
  • Produces a cumulative‑from‑midnight forecast that is consumed exactly like the ML load forecast (via load_forecast + load_forecast_only). load_ml takes precedence if both are enabled.

Fix: car‑charging hold applied per day before averaging

The legacy days_previous path 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_minute now applies the car/iBoost subtraction and the car‑charging‑hold threshold to each previous day individually and only then weighted‑averages them (new get_filtered_load_window helper). This matches the per‑sample behaviour of the new weighted‑bucket forecast.

Other changes

  • The weighted forecast is genuinely cumulative‑from‑midnight (so consumers such as load_today_comparison that read minutes before minutes_now get the right values) and correctly handles midnight crossings — each slot samples whole, distinct days at the slot's time‑of‑day.
  • Test harness: the interactive single debug run (--debug) and the debug_cases regression suite now exercise the same recompute path (new redo flag / --noredo), and the plan comparison is value‑based rather than a raw JSON string compare (robust to numpy‑vs‑python float repr).

Tests & docs

  • New test_load_forecast_history.py: weekday/age weighting, per‑bucket holiday weighting, zero‑bucket exclusion, short/gappy history, days_previous_auto activation, per‑day car‑charging hold, and cumulative‑from‑midnight / midnight crossing.
  • New 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: documents days_previous_auto.

Copilot AI review requested due to automatic review settings June 21, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_auto config 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.

Comment thread apps/predbat/fetch.py Outdated
Comment thread apps/predbat/fetch.py
Comment thread apps/predbat/predbat.py Outdated
@springfall2008 springfall2008 requested a review from Copilot June 21, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Comment thread apps/predbat/fetch.py Outdated
Comment thread apps/predbat/fetch.py Outdated
Comment thread apps/predbat/tests/test_single_debug.py Outdated
@springfall2008 springfall2008 merged commit 9f4be99 into main Jun 21, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/load_forecast_new branch June 21, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants