mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
fix(genetic): date a run in progress in the time zone of the horizon
The start day of a run in progress decides which DAILY cycle it counts for. Take it in the time zone of slot 0, which also dates the cycles. The cycle counting test gave its times with a +01:00 offset, so on a runner in UTC the run started on the previous day and was rightly not counted for today. It now uses local times without offset and passes in local time zones from UTC-12 to UTC+14. Refs: #1548 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
4693e1fa97
commit
e40ff7f6e3
@@ -483,7 +483,11 @@ class HomeAppliance:
|
|||||||
)
|
)
|
||||||
self.pinned_start_datetime = started
|
self.pinned_start_datetime = started
|
||||||
self.pinned_end_datetime = max(started.add(seconds=self.run_duration_seconds), now)
|
self.pinned_end_datetime = max(started.add(seconds=self.run_duration_seconds), now)
|
||||||
self.pinned_run_date = started.date()
|
# The start day in the time zone of the horizon, which also dates the cycles.
|
||||||
|
horizon_timezone = slot0_datetime.timezone
|
||||||
|
self.pinned_run_date = (
|
||||||
|
started.in_timezone(horizon_timezone) if horizon_timezone is not None else started
|
||||||
|
).date()
|
||||||
if elapsed >= self.run_duration_seconds:
|
if elapsed >= self.run_duration_seconds:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Home appliance '{}': run started {} is past its duration of {} s "
|
"Home appliance '{}': run started {} is past its duration of {} s "
|
||||||
|
|||||||
@@ -459,13 +459,13 @@ class TestRunInProgress:
|
|||||||
|
|
||||||
SLOT0 = "2026-11-14T01:00:00+01:00"
|
SLOT0 = "2026-11-14T01:00:00+01:00"
|
||||||
|
|
||||||
def pinned(self, started: str, now: str, **overrides) -> HomeAppliance:
|
def pinned(self, started: str, now: str, slot0: str = SLOT0, **overrides) -> HomeAppliance:
|
||||||
appliance = make_appliance(
|
appliance = make_appliance(
|
||||||
prediction_hours=overrides.pop("prediction_hours", 6),
|
prediction_hours=overrides.pop("prediction_hours", 6),
|
||||||
run_started_datetime=started,
|
run_started_datetime=started,
|
||||||
**overrides,
|
**overrides,
|
||||||
)
|
)
|
||||||
appliance.pin_run_in_progress(to_datetime(self.SLOT0), to_datetime(now))
|
appliance.pin_run_in_progress(to_datetime(slot0), to_datetime(now))
|
||||||
return appliance
|
return appliance
|
||||||
|
|
||||||
def test_remaining_flat_run_is_placed_from_now(self):
|
def test_remaining_flat_run_is_placed_from_now(self):
|
||||||
@@ -542,17 +542,21 @@ class TestRunInProgress:
|
|||||||
assert appliance.get_load_curve()[0] == pytest.approx(1000 * 55 / 60)
|
assert appliance.get_load_curve()[0] == pytest.approx(1000 * 55 / 60)
|
||||||
|
|
||||||
def test_counts_as_a_cycle_of_its_start_day_and_delays_the_next(self):
|
def test_counts_as_a_cycle_of_its_start_day_and_delays_the_next(self):
|
||||||
|
# Local times without offset, so the start day is the same in every local timezone of the test run.
|
||||||
|
slot0 = "2026-11-14T01:00:00"
|
||||||
appliance = self.pinned(
|
appliance = self.pinned(
|
||||||
"2026-11-14T00:47:00+01:00",
|
"2026-11-14T00:47:00",
|
||||||
"2026-11-14T01:05:00+01:00",
|
"2026-11-14T01:05:00",
|
||||||
|
slot0=slot0,
|
||||||
num_cycles=2,
|
num_cycles=2,
|
||||||
min_cycle_gap_h=1,
|
min_cycle_gap_h=1,
|
||||||
schedule_mode="DAILY",
|
schedule_mode="DAILY",
|
||||||
)
|
)
|
||||||
today = to_datetime(self.SLOT0).date()
|
today = to_datetime(slot0).date()
|
||||||
|
|
||||||
assert appliance.completed_cycles_on(today) == 1
|
assert appliance.completed_cycles_on(today) == 1
|
||||||
assert appliance.completed_cycles_on(today.add(days=1)) == 0
|
assert appliance.completed_cycles_on(today.add(days=1)) == 0
|
||||||
|
assert appliance.completed_cycles_on(today.subtract(days=1)) == 0
|
||||||
# Ends 02:47 (slot 2 is the first free slot) plus 1 h gap.
|
# Ends 02:47 (slot 2 is the first free slot) plus 1 h gap.
|
||||||
assert appliance.next_cycle_earliest_slot() == 3
|
assert appliance.next_cycle_earliest_slot() == 3
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user