Skip to content

Commit 07a1416

Browse files
test(replay): read a logged load divergence of None, as the plan now logs it when divergence is off
The logging now writes the divergence exactly as the plan uses it, which is None when metric_load_divergence_enable is off. The replay applied the rounded percentage line instead, giving the plan a divergence live never used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 98254ca commit 07a1416

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎apps/predbat/tests/replay_forward.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
INDAY_RE = re.compile(r"in-day adjustment ([\d.]+)%")
4747
DIVERGENCE_RE = re.compile(r"Load divergence over .* divergence ([\d.]+)%")
4848
# The divergence fraction exactly as get_load_divergence() returns it, which the rounded percentage above can miss
49-
DIVERGENCE_EXACT_RE = re.compile(r"Replay input: load divergence ([\d.e+-]+)$")
49+
DIVERGENCE_EXACT_RE = re.compile(r"Replay input: load divergence ([\d.e+-]+|None)$")
5050
FILTERED_RE = re.compile(r"Export windows filtered (\[.*\])")
5151
NEXT_LIMIT_RE = re.compile(r"Next export window will be: .* at reserve \((\d+), (\w+), ([\d.]+)\)")
5252
VERSION_RE = re.compile(r"version (\S+) currently running")
@@ -480,7 +480,8 @@ def apply_run(my_predbat, prev, run):
480480
# at the log's 5-minute resolution - smoother than the live 1-minute history, so it comes out different.
481481
# Use the logged value instead; it is rounded to 2 dp of the fraction exactly as get_load_divergence returns it.
482482
if run.get("divergence_exact"):
483-
my_predbat.replay_load_divergence = float(run["divergence_exact"])
483+
# None when the live plan had divergence off, which the rounded percentage line does not show
484+
my_predbat.replay_load_divergence = None if run["divergence_exact"] == "None" else float(run["divergence_exact"])
484485
elif run.get("divergence"):
485486
my_predbat.replay_load_divergence = round(float(run["divergence"]) / 100.0, 2)
486487
apply_logged_state(my_predbat, run.get("state"))

‎apps/predbat/tests/test_replay_forward.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ def test_inverter_input():
749749
if bat.replay_load_divergence != 0.31:
750750
print("ERROR: the exact divergence should win over the rounded percentage: {}".format(bat.replay_load_divergence))
751751
return 1
752+
# Divergence off live: the plan used None, whatever the rounded percentage line says
753+
off = dict(runs[0], divergence_exact="None")
754+
apply_run(bat, {"today": None, "force": None, "time": "2026-10-05 23:30:00+01:00"}, off)
755+
if bat.replay_load_divergence is not None:
756+
print("ERROR: a logged None divergence should be applied as None, got {}".format(bat.replay_load_divergence))
757+
return 1
752758
return 0
753759

754760

0 commit comments

Comments
 (0)