EV-10 round 3: grade the floor case on the same landing with and without the car; per-quarter latches independent of the cover option; stricter write-mute test
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -86,18 +86,21 @@ up to 1.8 kW; the 40 Wh floor fixes that.)
|
|||||||
|
|
||||||
## EV-10, EV-11, EV-12: the rig's three findings (EV-04 test F-1 to F-3)
|
## EV-10, EV-11, EV-12: the rig's three findings (EV-04 test F-1 to F-3)
|
||||||
|
|
||||||
- **The car is the cause when the alarm's own test says so** (EV-10).
|
- **The car is the cause when the alarm's own test says so, on the same
|
||||||
`car_cycle` (`_car_explains_alarm`) grades the alarm's test on the period as it
|
landing** (EV-10). `car_cycle` (`_car_explains_alarm`) runs the alarm's test on
|
||||||
is and on the period without the car's fresh, corroborated average
|
the period as it is and on the period without the car's fresh, corroborated
|
||||||
(`car_exclude`): the car explains the alarm only if the test is true with it
|
average (`car_exclude`): the car explains the alarm only if it is true with the
|
||||||
and false without it. The test is the alarm's own landing (`_car_grade`: the
|
car and false without it. A saturated guard, and a floor with other batteries
|
||||||
batteries give only what they still can, `load_too_high` for a saturated guard
|
left, use `load_too_high` on the landing (the batteries give only what they
|
||||||
and for a floor with other batteries, `misses_aim` for a floor with none), not
|
still can). A floor that leaves nothing uses SAFETY-126's `misses_aim` (the
|
||||||
the plain projection, which still counts the batteries' help. So the car alone
|
batteries at 0 W from now on), which is latched for the quarter; the add-on keeps
|
||||||
taking the batteries to the reserve is silent (rig: 5888 W against 6000 W),
|
that latch twice, with and without the car, from the same readings. Both reset
|
||||||
while a house-caused drain with a small car still alarms. No minimum car power
|
at a new quarter and when the guard stops wanting power, and they run every
|
||||||
is needed: a car that changes nothing cannot flip the test. A stale, stuck or
|
cycle, so the cover option does not touch them. This holds with the projection
|
||||||
uncorroborated figure is `None` and the normal alarms stand.
|
still under the aim (rig: 5888 W against 6000 W). A car of 0 W makes the two the
|
||||||
|
same, so it explains nothing; a stale, stuck or uncorroborated figure is `None`,
|
||||||
|
sets the latch without the car, and the normal alarms stand. There is no minimum
|
||||||
|
car power: the comparison itself is what separates car from house.
|
||||||
- **Steady row, no hold on the alarm** (EV-11). Cause: after the car's own quarter
|
- **Steady row, no hold on the alarm** (EV-11). Cause: after the car's own quarter
|
||||||
became the month peak, the aim sat on the grid it made (14.04 kW +-40 W), so
|
became the month peak, the aim sat on the grid it made (14.04 kW +-40 W), so
|
||||||
the test crossed the aim every few seconds. `car_over` (row, card, notice) now
|
the test crossed the aim every few seconds. `car_over` (row, card, notice) now
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ class CarMixin:
|
|||||||
self._car_over_since = None
|
self._car_over_since = None
|
||||||
self._car_over_gone = None
|
self._car_over_gone = None
|
||||||
self._car_batt_prev = None
|
self._car_batt_prev = None
|
||||||
self._car_needed = False # EV-10: SAFETY-126's latch without the car
|
self._car_need_real = self._car_need_excl = False # EV-10 latches
|
||||||
|
self._car_latch_block = None
|
||||||
self._car_over_notified = None # the session a notice was raised for
|
self._car_over_notified = None # the session a notice was raised for
|
||||||
self._car_session = 0
|
self._car_session = 0
|
||||||
self._car_prev_state = None
|
self._car_prev_state = None
|
||||||
@@ -262,11 +263,10 @@ class CarMixin:
|
|||||||
explains = over = False
|
explains = over = False
|
||||||
if real_proj is not None and target_w is not None \
|
if real_proj is not None and target_w is not None \
|
||||||
and real_proj.block_start 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, w)
|
||||||
if self.car_cover:
|
if self.car_cover:
|
||||||
# EV-10: the car explains the ALARM (`_car_explains_alarm`).
|
explains = over = graded
|
||||||
explains = self._car_explains_alarm(real_proj, guard,
|
|
||||||
target_w, w)
|
|
||||||
over = explains
|
|
||||||
elif w is not None:
|
elif w is not None:
|
||||||
ex = float(real_proj.projected_w) - float(target_w)
|
ex = float(real_proj.projected_w) - float(target_w)
|
||||||
over = ex > 0.0 and self.car_avg_w(real_proj, w) >= ex
|
over = ex > 0.0 and self.car_avg_w(real_proj, w) >= ex
|
||||||
@@ -289,26 +289,40 @@ class CarMixin:
|
|||||||
|
|
||||||
def _car_explains_alarm(self, real_proj, guard, target_w, w) -> bool:
|
def _car_explains_alarm(self, real_proj, guard, target_w, w) -> bool:
|
||||||
"""EV-10: is the alarm's own test true with the car and false without
|
"""EV-10: is the alarm's own test true with the car and false without
|
||||||
its fresh, corroborated share (`car_exclude`)? The tests are the
|
its fresh, corroborated share (`car_exclude`), on the same landing? The
|
||||||
alarms': a saturated guard and a floor with other batteries left are
|
tests are the alarms': a saturated guard and a floor with other
|
||||||
graded by `load_too_high` on where the period lands (SAFETY-81 / 87); a
|
batteries left are graded by `load_too_high` on where the period lands
|
||||||
floor that leaves nothing is graded by `within_aim`, which SAFETY-126
|
(SAFETY-81 / 87); a floor that leaves nothing is graded by SAFETY-126's
|
||||||
latches for the quarter once the batteries at 0 W would miss the aim.
|
`misses_aim` (the batteries at 0 W from now on), latched for the
|
||||||
`_car_needed` is that latch on the period without the car; an
|
quarter. That latch is kept here twice, on the period as it is
|
||||||
untrusted car figure (`w` None) sets it, so nothing is explained."""
|
(`_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
|
batt, prev = self.site_batt_w, self._car_batt_prev
|
||||||
self._car_batt_prev = batt
|
self._car_batt_prev = batt
|
||||||
wants = bool(guard is not None and guard.engaged
|
wants = bool(guard is not None and guard.engaged
|
||||||
and guard.blind is None
|
and guard.blind is None
|
||||||
and (guard.wanted_w or 0.0) > 0.0)
|
and (guard.wanted_w or 0.0) > 0.0)
|
||||||
|
if real_proj.block_start != self._car_latch_block:
|
||||||
|
self._car_latch_block = real_proj.block_start
|
||||||
|
self._car_need_real = self._car_need_excl = False
|
||||||
if not wants:
|
if not wants:
|
||||||
self._car_needed = False
|
self._car_need_real = self._car_need_excl = False
|
||||||
if batt is not None and prev is not None:
|
if batt is not None and prev is not None:
|
||||||
batt = min(float(batt), float(prev))
|
batt = min(float(batt), float(prev))
|
||||||
excl = self.car_exclude(real_proj, w)
|
excl = self.car_exclude(real_proj, w)
|
||||||
if wants:
|
if wants:
|
||||||
self._car_needed = self._car_needed or w is None or batt is None \
|
if batt is None:
|
||||||
or peakguard.misses_aim(excl, batt_w=batt, target_w=target_w)
|
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 \
|
||||||
|
peakguard.misses_aim(excl, batt_w=batt, target_w=target_w)
|
||||||
if w is None or batt is None or not wants \
|
if w is None or batt is None or not wants \
|
||||||
or not (guard.saturated or guard.floor_limited):
|
or not (guard.saturated or guard.floor_limited):
|
||||||
return False
|
return False
|
||||||
@@ -317,7 +331,8 @@ class CarMixin:
|
|||||||
elif (guard.floor_w or 0.0) > 0.0 and guard.able_w is not None:
|
elif (guard.floor_w or 0.0) > 0.0 and guard.able_w is not None:
|
||||||
rating = guard.able_w
|
rating = guard.able_w
|
||||||
else:
|
else:
|
||||||
return bool(not guard.within_aim and not self._car_needed)
|
return bool(not guard.within_aim and self._car_need_real
|
||||||
|
and not self._car_need_excl)
|
||||||
|
|
||||||
def high(p):
|
def high(p):
|
||||||
return peakguard.load_too_high(
|
return peakguard.load_too_high(
|
||||||
|
|||||||
@@ -215,12 +215,18 @@ class _G:
|
|||||||
|
|
||||||
|
|
||||||
def explains(proj_w, car_w, *, floor=True, cover=True, car_so_far_w=None,
|
def explains(proj_w, car_w, *, floor=True, cover=True, car_so_far_w=None,
|
||||||
within_aim=False):
|
within_aim=False, earlier=(), block=0, c=None, at=0.0):
|
||||||
c = _Car(cover, car_w)
|
"""One cycle of `car_cycle` on a stub; `earlier` are projections of
|
||||||
p = _Proj(proj_w)
|
cycles before it in the same quarter (they latch SAFETY-126's test)."""
|
||||||
|
c = c or _Car(cover, car_w)
|
||||||
|
c.w = car_w
|
||||||
|
for k, e in enumerate(tuple(earlier) + (proj_w,)):
|
||||||
|
p = _Proj(e)
|
||||||
|
p.block_start = p.block_start + timedelta(minutes=15 * block)
|
||||||
|
c._now = at - len(earlier) + k
|
||||||
c._carq = {"key": p.block_start,
|
c._carq = {"key": p.block_start,
|
||||||
"ws": (car_w if car_so_far_w is None else car_so_far_w)
|
"ws": ((car_w or 0.0) if car_so_far_w is None else car_so_far_w)
|
||||||
* p.elapsed_s, "mono": 0.0}
|
* p.elapsed_s, "mono": c._now}
|
||||||
c.car_cycle(p, _G(floor, within_aim=within_aim), 4450.0, None)
|
c.car_cycle(p, _G(floor, within_aim=within_aim), 4450.0, None)
|
||||||
return c.car_explains
|
return c.car_explains
|
||||||
|
|
||||||
@@ -228,11 +234,41 @@ def explains(proj_w, car_w, *, floor=True, cover=True, car_so_far_w=None,
|
|||||||
check("rule: the alarm's test is true with the car (4468 W, the batteries "
|
check("rule: the alarm's test is true with the car (4468 W, the batteries "
|
||||||
"at 0 W land 4485 W) and false without it (768 W): the car explains it, "
|
"at 0 W land 4485 W) and false without it (768 W): the car explains it, "
|
||||||
"with the projection under the aim", explains(4468.0, 3700.0))
|
"with the projection under the aim", explains(4468.0, 3700.0))
|
||||||
|
check("rule: under the aim, the quarter's test latched by the car's share "
|
||||||
|
"(4600 W earlier), the car explains the alarm (the positive under-aim "
|
||||||
|
"case; a single 4300 W cycle has no landing miss to explain, so it "
|
||||||
|
"needs the earlier cycle)", explains(4300.0, 3700.0, earlier=(4600.0,)))
|
||||||
check("rule: where the alarm would not fire anyway nothing is explained",
|
check("rule: where the alarm would not fire anyway nothing is explained",
|
||||||
not explains(4300.0, 3700.0, within_aim=True))
|
not explains(4300.0, 3700.0, within_aim=True))
|
||||||
check("rule: without the car it is still over the aim: the car does not "
|
check("rule: without the car it is still over the aim: the car does not "
|
||||||
"explain it", not explains(9000.0, 3700.0))
|
"explain it", not explains(9000.0, 3700.0))
|
||||||
check("rule: no car power, no explanation", not explains(9000.0, 0.0))
|
check("rule: no car power, no explanation", not explains(4300.0, 0.0))
|
||||||
|
check("rule: ...also when the test was latched earlier in the quarter",
|
||||||
|
not explains(4300.0, 0.0, earlier=(4600.0,))
|
||||||
|
and not explains(9000.0, 0.0))
|
||||||
|
check("rule: an untrusted car figure (None) explains nothing",
|
||||||
|
not explains(4300.0, None, earlier=(4600.0,)))
|
||||||
|
# the latches: per quarter, and independent of the cover option
|
||||||
|
c4 = _Car(True, 3700.0)
|
||||||
|
explains(9000.0, 3700.0, c=c4, block=0) # the house needs it: latched
|
||||||
|
check("latch: in the same quarter the house need stays latched, so the car "
|
||||||
|
"does not explain", not explains(4300.0, 3700.0, c=c4, block=0, at=10.0))
|
||||||
|
check("latch: a new quarter starts clean: the car alone explains it again",
|
||||||
|
explains(4300.0, 3700.0, c=c4, block=1, at=1000.0,
|
||||||
|
earlier=(4600.0,)))
|
||||||
|
c5 = _Car(False, 3700.0) # cover OFF
|
||||||
|
explains(9000.0, 3700.0, c=c5, block=0) # the house needs it
|
||||||
|
c5.o["ev_batt_cover"] = True # ... and the option flips
|
||||||
|
check("latch: the option flipping to ON does not lose a house need seen "
|
||||||
|
"while it was off", not explains(4300.0, 3700.0, c=c5, block=0, at=10.0))
|
||||||
|
c6 = _Car(True, 3700.0)
|
||||||
|
explains(9000.0, 3700.0, c=c6, block=0)
|
||||||
|
c6.o["ev_batt_cover"] = False
|
||||||
|
explains(4300.0, 3700.0, c=c6, block=0, at=10.0)
|
||||||
|
c6.o["ev_batt_cover"] = True
|
||||||
|
check("latch: ... nor does flipping it off and on again",
|
||||||
|
not explains(4300.0, 3700.0, c=c6, block=0, at=20.0))
|
||||||
|
|
||||||
check("rule: the guard is not floor-limited or saturated: nothing to explain",
|
check("rule: the guard is not floor-limited or saturated: nothing to explain",
|
||||||
not explains(4300.0, 3700.0, floor=False))
|
not explains(4300.0, 3700.0, floor=False))
|
||||||
|
|
||||||
@@ -490,32 +526,36 @@ check("Manual: two writes of ours, never 'another writer' in the tracker",
|
|||||||
|
|
||||||
async def failed_write_then_outside(how):
|
async def failed_write_then_outside(how):
|
||||||
"""A write that RAISES or returns FAILURE must still close the self-mute:
|
"""A write that RAISES or returns FAILURE must still close the self-mute:
|
||||||
a later outside change shows the row."""
|
it ends 15 s after the write returned, and a later outside change shows
|
||||||
|
the row."""
|
||||||
w = World()
|
w = World()
|
||||||
await w.step(3)
|
await w.step(3)
|
||||||
await w.c.handle_action("car_mode", value="manual")
|
await w.c.handle_action("car_mode", value="manual")
|
||||||
|
ret = []
|
||||||
|
|
||||||
async def bad(a):
|
async def bad(a):
|
||||||
await w.sleep(1.0)
|
await w.sleep(1.0)
|
||||||
|
ret.append(w.t) # when the write came back
|
||||||
if how == "raise":
|
if how == "raise":
|
||||||
raise RuntimeError("the charger link broke")
|
raise RuntimeError("the charger link broke")
|
||||||
return False
|
return False
|
||||||
w.drv.write_current = bad
|
w.drv.write_current = bad
|
||||||
await w.c.handle_action("car_current", value=12)
|
await w.c.handle_action("car_current", value=12)
|
||||||
await w.step(3) # the write is tried
|
await w.step(3) # the write is tried
|
||||||
|
closed = (bool(ret) and w.c.car.mute_until <= ret[-1] + 15.0 + 1e-6)
|
||||||
await w.c.handle_action("car_mode", value="off")
|
await w.c.handle_action("car_mode", value="off")
|
||||||
await w.step(20) # past the 15 s mute
|
await w.step(20) # past the 15 s mute
|
||||||
w.sim.set_current(7) # somebody else
|
w.sim.set_current(7) # somebody else
|
||||||
await w.step(3)
|
await w.step(3)
|
||||||
return w
|
return w, closed
|
||||||
|
|
||||||
|
|
||||||
for how in ("raise", "fail"):
|
for how in ("raise", "fail"):
|
||||||
wf = asyncio.run(failed_write_then_outside(how))
|
wf, closed = asyncio.run(failed_write_then_outside(how))
|
||||||
check(f"a write that {'raises' if how == 'raise' else 'returns failure'}"
|
check(f"a write that {'raises' if how == 'raise' else 'returns failure'}"
|
||||||
": the mute closes within 15 s, and a later outside change shows "
|
": the mute ends within 15 s of the write's return, and a later "
|
||||||
"the row", wf.c.car.mute_until < wf.t
|
"outside change shows the row",
|
||||||
and "charger_writer" in wf.rows())
|
closed and "charger_writer" in wf.rows())
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print("FAIL: " + ", ".join(fails) if fails else "PASS: every check passed")
|
print("FAIL: " + ", ".join(fails) if fails else "PASS: every check passed")
|
||||||
|
|||||||
Reference in New Issue
Block a user