mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
fix(genetic): keep a deadline from capping the DAILY appliance estimate
The tail estimate queried its probe appliance with the configured deadline. A deadline inside the control horizon then left no start on the following days: with BEST_EFFORT the 48 h tail held one run and logged "deadline can not be met" twice per run, with STRICT it held no appliance load. The deadline only limits the run it was set for, so the probe leaves it out. Additional changes Test the tail load with a deadline inside the control horizon for both deadline policies Refs: #1495 Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
Claude Opus 5.5
parent
d9a5ac0b0b
commit
45a6377b60
@@ -1377,9 +1377,10 @@ class GeneticOptimization(OptimizationBase):
|
||||
# The configured appliance only spans the control horizon, so its
|
||||
# window logic cannot see the tail. Query a throwaway copy sized to
|
||||
# the estimated range instead; it shares the same parameters, so the
|
||||
# time windows, earliest start and deadline bounds all still apply.
|
||||
# time windows and the earliest start still apply. A deadline only
|
||||
# limits the run it was set for and must not cap the following days.
|
||||
probe = HomeAppliance(
|
||||
parameters=appliance.parameters,
|
||||
parameters=appliance.parameters.model_copy(update={"deadline_datetime": None}),
|
||||
optimization_hours=self._genetic_cfg.horizon_hours,
|
||||
prediction_hours=end_slot,
|
||||
slot_duration_h=self.slot_duration_h,
|
||||
|
||||
@@ -5,6 +5,7 @@ from unittest.mock import patch
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from loguru import logger
|
||||
|
||||
from akkudoktoreos.config.config import SettingsEOSDefaults
|
||||
from akkudoktoreos.core.coreabc import get_ems
|
||||
@@ -597,3 +598,60 @@ def test_daily_appliance_run_in_progress_counts_for_its_day_in_estimate(config_e
|
||||
expected_first_day = 0.0 if running else 3000.0
|
||||
assert float(np.sum(first_day)) == pytest.approx(expected_first_day)
|
||||
assert float(np.sum(two_days)) == pytest.approx(expected_first_day + 3000.0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("policy", ["BEST_EFFORT", "STRICT"])
|
||||
def test_daily_appliance_deadline_does_not_cap_tail(config_eos, policy):
|
||||
"""#1495: a deadline inside the control horizon does not limit the following days.
|
||||
|
||||
The run starts 22:00, so the control horizon holds one night run before the
|
||||
deadline and the 48 h tail two more nights. The tail must hold both, and
|
||||
estimating it must not log a missed deadline.
|
||||
"""
|
||||
opt, params = setup_run(config_eos, start_hour=22, hours=72 + 22)
|
||||
params.home_appliances = [
|
||||
HomeApplianceParameters.model_validate(
|
||||
dict(
|
||||
device_id="water_heater",
|
||||
consumption_wh=3000,
|
||||
duration_h=2,
|
||||
num_cycles=1,
|
||||
schedule_mode="DAILY",
|
||||
deadline_datetime="2026-09-06T08:00:00",
|
||||
deadline_policy=policy,
|
||||
time_windows={
|
||||
"windows": [{"start_time": "00:00", "duration": "5 hours", "value": 0}]
|
||||
},
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
def choose(*args, **kwargs):
|
||||
genome = opt.create_individual()
|
||||
genome[:] = [0] * len(genome)
|
||||
return genome, {}
|
||||
|
||||
messages: list[str] = []
|
||||
sink = logger.add(lambda message: messages.append(str(message)), level="WARNING")
|
||||
try:
|
||||
with (
|
||||
patch.object(opt, "optimize", side_effect=choose),
|
||||
patch(
|
||||
"akkudoktoreos.optimization.genetic.genetic.build_tail_value_curve",
|
||||
wraps=build_tail_value_curve,
|
||||
) as builder,
|
||||
):
|
||||
opt.optimize_ems(params)
|
||||
finally:
|
||||
logger.remove(sink)
|
||||
|
||||
tail_load = builder.call_args.kwargs["load_wh"]
|
||||
slot0 = opt._slot0_datetime
|
||||
tail_days = {
|
||||
str(slot0.add(hours=opt.control_end_slot + index).date())
|
||||
for index, energy in enumerate(tail_load)
|
||||
if energy > 0
|
||||
}
|
||||
assert tail_days == {"2026-09-07", "2026-09-08"}
|
||||
assert float(np.sum(tail_load)) == pytest.approx(6000)
|
||||
assert not [message for message in messages if "can not be met" in message]
|
||||
|
||||
Reference in New Issue
Block a user