EV-18: no floor alarm at a quarter's start while the car explains the excess
EV-15 rig F-A: with both batteries at the peak reserve and the car charging, PEAK_GUARD_FLOOR_LIMITED and goodwe_peak_soc_floor fired at a quarter's start and stayed red for the quarter, the excess smaller than the car. Two causes, both held by the per-quarter latch `_car_need_excl`: - C2: "without the car" assumed the batteries give 0 W from now on, so what the loop still gives below the reserve counted as house (T2 red on base); - C1: one cycle with no trusted car figure latched it for the quarter (T1). Owner 2026-11-19 (Q1-Q3): without the car the batteries keep giving what they give now (lower of two readings, every cycle); a house need seen with a trusted car figure stays latched to the quarter's end (`_car_need_house`); an unknown car figure keeps the alarm only while it is unknown. A car known to draw nothing (fresh reading, not charging) still grades the house's own need. After a restart or a gap only the rest of the quarter is graded without the car. A 0 W figure explains nothing outside our own pause (EV-15). The guard's claim, floor, setpoints and charger writes are unchanged (N4: 41 runs, same command digests as base). test_ev18.py: the test plan's T1-T18, T2b, T2c, N2-N5 (tools/ev18_peak.py: the real Controller across one quarter edge, N=2 at the reserve). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,7 @@ class CarMixin:
|
||||
self._car_over_gone = None
|
||||
self._car_batt_prev = None
|
||||
self._car_need_real = self._car_need_excl = False # EV-10 latches
|
||||
self._car_need_house = self._car_over_now = False # EV-18 latches
|
||||
self._car_latch_block = None
|
||||
self._car_over_notified = None # the session a notice was raised for
|
||||
self._car_session = 0
|
||||
@@ -235,6 +236,16 @@ class CarMixin:
|
||||
<= OWN_PAUSE_MAX_S
|
||||
return 0.0 <= mono - wr.phase_done_at <= OWN_PAUSE_TAIL_S
|
||||
|
||||
def _car_idle(self, mono) -> bool:
|
||||
"""EV-18: is the car known to draw nothing? A fresh reading that says
|
||||
it is not charging (mode3 A or B) at under `CAR_PEAK_MIN_W`. Not an
|
||||
unknown figure: the house's own need is graded in such a cycle."""
|
||||
r = getattr(self.car, "reading", None)
|
||||
if r is None or not r.available or r.charging is not False:
|
||||
return False
|
||||
p = self.car.car_w(mono)
|
||||
return p is not None and p < CAR_PEAK_MIN_W
|
||||
|
||||
def _car_quarter(self, proj, w, mono, wg=None) -> None:
|
||||
"""The car's energy in the open quarter, for the average the guard's
|
||||
house leaves out and for the peak line. `wg` (EV-15) is the figure for
|
||||
@@ -244,8 +255,16 @@ class CarMixin:
|
||||
key = None if proj is None else proj.block_start
|
||||
last = q["mono"]
|
||||
if key != q["key"]:
|
||||
# EV-18: `whole` when the count covers the block: it follows on
|
||||
# from the block before, or starts in its first seconds (not
|
||||
# after a restart or a gap).
|
||||
whole = key is not None and (
|
||||
float(proj.elapsed_s) <= 5.0 or (
|
||||
last is not None and q["key"] is not None
|
||||
and (key - q["key"]).total_seconds() == QUARTER_S))
|
||||
self._car_bank(q)
|
||||
q["key"], q["ws"], q["ws_p"] = key, 0.0, 0.0
|
||||
q["whole"] = whole
|
||||
if key is not None and last is not None:
|
||||
dt = min(max(mono - last, 0.0), 5.0)
|
||||
if w is not None:
|
||||
@@ -322,7 +341,8 @@ class CarMixin:
|
||||
# car at 0 A and the energy meter cannot corroborate it then, so for
|
||||
# that bounded time its fresh, not stuck figure stands in.
|
||||
wg = w
|
||||
if w is None and self._car_own_pause(mono):
|
||||
own = (w is None or float(w) <= 0.0) and self._car_own_pause(mono)
|
||||
if w is None and own:
|
||||
wg = self.car.car_w_paused(mono)
|
||||
self._car_quarter(real_proj, w, mono, wg)
|
||||
self._car_session_tick(mono)
|
||||
@@ -330,7 +350,14 @@ class CarMixin:
|
||||
if real_proj is not None and target_w is not None \
|
||||
and real_proj.block_start is not None:
|
||||
# EV-10: every cycle, so the latches do not depend on the option.
|
||||
graded = self._car_explains_alarm(real_proj, guard, target_w, wg)
|
||||
# EV-18: a car known to draw nothing counts as 0 W for the latches
|
||||
# (the house's own need); it and a 0 W figure explain nothing,
|
||||
# but in our own pause (EV-15).
|
||||
idle = wg is None and self._car_idle(mono)
|
||||
graded = self._car_explains_alarm(real_proj, guard, target_w,
|
||||
0.0 if idle else wg)
|
||||
if idle or (w is not None and float(w) <= 0.0 and not own):
|
||||
graded = False
|
||||
if self.car_cover:
|
||||
explains = over = graded
|
||||
elif w is not None:
|
||||
@@ -360,35 +387,41 @@ class CarMixin:
|
||||
batteries left are graded by `load_too_high` on where the period lands
|
||||
(SAFETY-81 / 87); a floor that leaves nothing is graded by SAFETY-126's
|
||||
`misses_aim` (the batteries at 0 W from now on), latched for the
|
||||
quarter. That latch is kept here twice, on the period as it is
|
||||
(`_car_need_real`) and without the car (`_car_need_excl`), from the
|
||||
same `misses_aim` and the same batteries reading. Both reset at a new
|
||||
quarter and when the guard no longer wants power, whatever the cover
|
||||
option says (this runs every cycle). A car that is 0 W, or untrusted
|
||||
(`w` None sets the second latch), makes the two equal and explains
|
||||
nothing."""
|
||||
batt, prev = self.site_batt_w, self._car_batt_prev
|
||||
self._car_batt_prev = batt
|
||||
quarter (`_car_need_real`, and `_car_need_excl` without the car).
|
||||
EV-18 (owner 2026-11-19): without the car, the batteries keep giving
|
||||
what they give now (the lower of two readings), re-checked every cycle;
|
||||
a miss seen so (`_car_need_house`) never lets the car explain for the
|
||||
rest of the quarter. The car also explains where the period with it,
|
||||
on the same batteries, misses (`_car_over_now`). Only a trusted figure
|
||||
latches: an untrusted car (`w` None) or an unknown battery reading
|
||||
explains nothing in that cycle only. All reset at a new quarter and
|
||||
when the guard no longer wants power, whatever the cover option says
|
||||
(this runs every cycle). DECISIONS/EV-04-manual-mode.md (EV-18)."""
|
||||
now, prev = self.site_batt_w, self._car_batt_prev
|
||||
self._car_batt_prev = now
|
||||
wants = bool(guard is not None and guard.engaged
|
||||
and guard.blind is None
|
||||
and (guard.wanted_w or 0.0) > 0.0)
|
||||
if real_proj.block_start != self._car_latch_block:
|
||||
if real_proj.block_start != self._car_latch_block or not wants:
|
||||
self._car_latch_block = real_proj.block_start
|
||||
self._car_need_real = self._car_need_excl = False
|
||||
if not wants:
|
||||
self._car_need_real = self._car_need_excl = False
|
||||
self._car_need_house = self._car_over_now = False
|
||||
batt = now
|
||||
if batt is not None and prev is not None:
|
||||
batt = min(float(batt), float(prev))
|
||||
excl = self.car_exclude_alarm(real_proj, w)
|
||||
if wants:
|
||||
if batt is None:
|
||||
self._car_need_real = self._car_need_excl = True
|
||||
else:
|
||||
self._car_need_real = self._car_need_real or \
|
||||
peakguard.misses_aim(real_proj, batt_w=batt,
|
||||
target_w=target_w)
|
||||
self._car_need_excl = self._car_need_excl or w is None or \
|
||||
if wants and batt is not None:
|
||||
self._car_need_real = self._car_need_real or \
|
||||
peakguard.misses_aim(real_proj, batt_w=batt,
|
||||
target_w=target_w)
|
||||
self._car_over_now = self._car_over_now or \
|
||||
self._car_lands_over(real_proj, now, batt, target_w)
|
||||
if w is not None:
|
||||
whole = self._carq.get("whole", True)
|
||||
self._car_need_excl = self._car_need_excl or \
|
||||
peakguard.misses_aim(excl, batt_w=batt, target_w=target_w)
|
||||
self._car_need_house = self._car_need_house or \
|
||||
self._car_lands_over(excl, now, batt, target_w, whole)
|
||||
if w is None or batt is None or not wants \
|
||||
or not (guard.saturated or guard.floor_limited):
|
||||
return False
|
||||
@@ -398,7 +431,8 @@ class CarMixin:
|
||||
rating = guard.able_w
|
||||
else:
|
||||
return bool(not guard.within_aim and self._car_need_real
|
||||
and not self._car_need_excl)
|
||||
and not self._car_need_house
|
||||
and (self._car_over_now or not self._car_need_excl))
|
||||
|
||||
def high(p):
|
||||
return peakguard.load_too_high(
|
||||
@@ -406,6 +440,20 @@ class CarMixin:
|
||||
achievable_w=rating)
|
||||
return bool(high(real_proj) and not high(excl))
|
||||
|
||||
@staticmethod
|
||||
def _car_lands_over(p, now, gives, target_w, whole=True) -> bool:
|
||||
"""EV-18: does the period end more than `ALARM_MISS_W` over the aim
|
||||
with the batteries giving `gives` W from now on (`now`: what they gave
|
||||
in the meter's figure)? Not `whole`: the car's share of what is done
|
||||
is not known (a restart, a gap), so only the rest is graded."""
|
||||
if whole:
|
||||
return peakguard.load_too_high(p, batt_w=now, ceiling_w=target_w,
|
||||
achievable_w=gives)
|
||||
if QUARTER_S - float(p.elapsed_s) <= 0.0:
|
||||
return False
|
||||
rest = float(p.held_w) + float(now) - float(gives)
|
||||
return rest - float(target_w) > peakguard.ALARM_MISS_W
|
||||
|
||||
def _car_session_tick(self, mono) -> None:
|
||||
"""A charging session is a plug-in: the state goes from no car to a
|
||||
car. The notice is raised once per session."""
|
||||
|
||||
Reference in New Issue
Block a user