EV-10, EV-11, EV-12: car-alone peak alarm, steady car-over row, own write not another writer
checks / unit (pull_request) Failing after 2m13s
infra-pin / fresh (pull_request) Successful in 2s

EV-10: the car is the cause when the period without it (projected minus the car's
fresh, corroborated average) is at or under the aim, also with the projection
still under it. EV-11: car_over stays on until the test has been false for 180 s.
EV-12: the tracker's own-write mute opens before the write and runs 15 s from its
return.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-16 15:27:46 +01:00
parent 75ebe22a4d
commit 8efc385956
6 changed files with 509 additions and 11 deletions
+7 -2
View File
@@ -248,9 +248,14 @@ class ManualWriter:
"to it until you change it.", cur, known[0])
async def _write(self, drv, a, was, now, tracker) -> bool:
ok = await drv.write_current(a)
self._stamp(now)
tracker.begin_write() # EV-12: the read-back is ours
try:
ok = await drv.write_current(a)
finally:
self._stamp(now)
tracker.end_write(self.last_done)
tracker.note_write(now, was, a)
tracker.end_write(self.last_done)
self.log.append(("current", a, now, ok))
if ok:
self.last_a = a
+11
View File
@@ -716,6 +716,17 @@ class CarTracker:
return None
# -- EV-04: the stuck-reading rule -------------------------------------------
def begin_write(self) -> None:
"""EV-12: a write of ours is in flight. Its read-back can reach the
tracker before `note_write` runs (the write waits for it), so the mute
is open until `end_write`."""
self.mute_until = float("inf")
def end_write(self, now: float) -> None:
"""EV-12: the write returned (or failed). The mute runs
`OWN_WRITE_MUTE_S` from now, not from before the write."""
self.mute_until = now + OWN_WRITE_MUTE_S
def note_write(self, now: float, was_a, to_a) -> None:
"""The add-on wrote the current. Its own change is not "another
writer" for `OWN_WRITE_MUTE_S`, and a write that moved the setpoint by
+25 -9
View File
@@ -20,6 +20,9 @@ CAR_PEAK_KEY = "car_peak_q" # {quarter start iso: the car's average W}
CAR_PEAK_MIN_W = 50.0 # a quarter the car hardly touched is not kept
CAR_PEAK_KEEP = 3200 # about a month of quarters
OVER_HOLD_S = peakguard.ALARM_HOLD_S
# EV-11: the card, the row and Why stay on this long after the car stops being
# the cause (the rig's off gaps were 20 s to 3 min), or until it really ends.
OVER_OFF_HOLD_S = 180.0
class CarMixin:
@@ -46,6 +49,7 @@ class CarMixin:
self.car_explains = False # the car alone explains the excess
self.car_over = False # ... held: the card and row say so
self._car_over_since = None
self._car_over_gone = None
self._car_over_notified = None # the session a notice was raised for
self._car_session = 0
self._car_prev_state = None
@@ -255,26 +259,38 @@ class CarMixin:
explains = over = False
if w is not None and real_proj is not None and target_w is not None \
and real_proj.block_start is not None:
# The car explains the excess when the house alone would land the
# period under the aim: what the car takes over the whole period
# (`car_avg_w`) is at least how far the projection is over it.
# The car explains the excess when the period WITHOUT the car
# (`projected - car_avg_w`, over the same window) would be at or
# under the aim: the car, not the house, needs the batteries. EV-10:
# this holds with the projection still under the aim, when the
# car alone took the batteries to the reserve.
car_avg = self.car_avg_w(real_proj, w)
without = float(real_proj.projected_w) - car_avg
ex = float(real_proj.projected_w) - float(target_w)
beyond = ex > 0.0 and self.car_avg_w(real_proj, w) >= ex
if self.car_cover:
explains = bool(
beyond and guard is not None
car_avg >= CAR_PEAK_MIN_W and without <= float(target_w)
and guard is not None
and (guard.saturated or guard.floor_limited))
over = explains
else:
over = beyond
over = ex > 0.0 and car_avg >= ex
self.car_explains = explains
# EV-11: on once the condition has stood for OVER_HOLD_S, a short gap
# in it not starting that count again; off only after it has been gone
# for OVER_OFF_HOLD_S. `car_explains` (the alarm decision) has no hold.
if over:
self._car_over_gone = None
if self._car_over_since is None:
self._car_over_since = mono
held = mono - self._car_over_since >= OVER_HOLD_S
if mono - self._car_over_since >= OVER_HOLD_S:
self.car_over = True
else:
self._car_over_since, held = None, False
self.car_over = held
if self._car_over_gone is None:
self._car_over_gone = mono
if mono - self._car_over_gone >= OVER_OFF_HOLD_S:
self.car_over, self._car_over_since = False, None
self._car_over_gone = None
def _car_session_tick(self, mono) -> None:
"""A charging session is a plug-in: the state goes from no car to a