EV-18 review round 1: restart keeps the house's done part; contradicted figure untrusted to the quarter's end
- [Critical] After a restart or a gap only the rest of the quarter was graded without the car (`_carq["whole"]`), which dropped the house's own energy from before it and hid an honest alarm (review repro: house 18 kW then 12 kW, restart at E+310). The rest-only grading is gone: the car is credited only with energy counted since the start, the rest of what is done counts as house (base's side). T17b covers it; T17 T2 at E+300 now alarms from the restart (the conservative side). - [Major] Owner 2026-11-19: a figure the energy meter contradicted (fresh, charging, not corroborated) stays untrusted to the quarter's end, also as the EV-15 stand-in. T9(c): one alarm edge, red to the end; T9(c) is back in the N5 check. - [Major] T2c lagging-meter variant (readings 389 W then 800 W, the meter at 800 W): the house latch grades on the lower reading. - Unit stub: a run that starts mid-quarter has the car counted since the quarter's start (no restart). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -146,9 +146,11 @@ up to 1.8 kW; the 40 Wh floor fixes that.)
|
||||
(`_car_need_house`) seen with a trusted car figure stays latched to the
|
||||
quarter's end. The car explains where the period with it misses on the same
|
||||
batteries (`_car_over_now`), or by the EV-10 test above. A `None` car figure
|
||||
or battery reading explains nothing in that cycle and latches nothing. After
|
||||
a restart or a gap the car's share of what is done is unknown (`_carq`
|
||||
`whole`), so only the rest of the period is graded without the car.
|
||||
or battery reading explains nothing in that cycle and latches nothing; a car
|
||||
known to draw nothing (fresh, not charging) still grades the house's need.
|
||||
Owner 2026-11-19: a figure the energy meter contradicted (fresh, charging,
|
||||
not corroborated) stays untrusted to the quarter's end. After a restart or a
|
||||
gap the car's earlier energy is not known, so it counts as house.
|
||||
- **Our own write is ours until its mute ends** (EV-12). The mute of the tracker's
|
||||
own detector opens before the write and runs 15 s from when it returns, because
|
||||
the read-back reaches the cycle while the write still waits for it.
|
||||
|
||||
@@ -62,6 +62,7 @@ class CarMixin:
|
||||
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_contra_block = None # EV-18: the quarter it was contradicted
|
||||
self._car_over_notified = None # the session a notice was raised for
|
||||
self._car_session = 0
|
||||
self._car_prev_state = None
|
||||
@@ -236,6 +237,17 @@ class CarMixin:
|
||||
<= OWN_PAUSE_MAX_S
|
||||
return 0.0 <= mono - wr.phase_done_at <= OWN_PAUSE_TAIL_S
|
||||
|
||||
def _car_contradicted(self, mono) -> bool:
|
||||
"""EV-18 (owner 2026-11-19): does the charger's energy meter
|
||||
contradict a fresh, not stuck figure of a charging car? Then that
|
||||
figure stays untrusted to the quarter's end (`car_cycle`)."""
|
||||
r = getattr(self.car, "reading", None)
|
||||
if r is None or not r.available or r.charging is not True \
|
||||
or not self.car_manual():
|
||||
return False
|
||||
return (self.car.car_w(mono) is not None and not self.car.stuck(mono)
|
||||
and not self.car.corroborated(mono))
|
||||
|
||||
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
|
||||
@@ -255,16 +267,8 @@ 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:
|
||||
@@ -340,8 +344,15 @@ class CarMixin:
|
||||
# EV-15: the figure for grading only. Our own phase change holds the
|
||||
# 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
|
||||
own = (w is None or float(w) <= 0.0) and self._car_own_pause(mono)
|
||||
# EV-18: a figure the meter contradicted is not trusted again in
|
||||
# that quarter, not even as the stand-in for our own pause.
|
||||
key = None if real_proj is None else real_proj.block_start
|
||||
if key is not None and not own and self._car_contradicted(mono):
|
||||
self._car_contra_block = key
|
||||
if key is not None and key == self._car_contra_block:
|
||||
w, own = None, False
|
||||
wg = w
|
||||
if w is None and own:
|
||||
wg = self.car.car_w_paused(mono)
|
||||
self._car_quarter(real_proj, w, mono, wg)
|
||||
@@ -417,11 +428,10 @@ class CarMixin:
|
||||
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)
|
||||
self._car_lands_over(excl, now, batt, target_w)
|
||||
if w is None or batt is None or not wants \
|
||||
or not (guard.saturated or guard.floor_limited):
|
||||
return False
|
||||
@@ -441,18 +451,14 @@ class CarMixin:
|
||||
return bool(high(real_proj) and not high(excl))
|
||||
|
||||
@staticmethod
|
||||
def _car_lands_over(p, now, gives, target_w, whole=True) -> bool:
|
||||
def _car_lands_over(p, now, gives, target_w) -> 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
|
||||
in the meter's figure)? Of what is done, only the car's energy counted
|
||||
since the add-on started is the car's (a restart or a gap leaves the
|
||||
rest with the house)."""
|
||||
return peakguard.load_too_high(p, batt_w=now, ceiling_w=target_w,
|
||||
achievable_w=gives)
|
||||
|
||||
def _car_session_tick(self, mono) -> None:
|
||||
"""A charging session is a plug-in: the state goes from no car to a
|
||||
|
||||
@@ -99,6 +99,11 @@ def urun(secs, grid, batt, w, *, x=1, mono_x=None, c=None, guard=None):
|
||||
c = c or _Car()
|
||||
mono_x = x if mono_x is None else mono_x
|
||||
done, out = {}, {}
|
||||
t0 = nth(list(secs), 0)
|
||||
if c._carq["key"] is None and present(t0) and t0 % 900:
|
||||
# started mid-quarter: the car was counted since its start (no restart)
|
||||
c._carq.update(key=BS + timedelta(seconds=900 * (t0 // 900)),
|
||||
ws=float(w(t0) or 0.0) * (t0 % 900), ws_p=0.0)
|
||||
for t in secs:
|
||||
q = t // 900
|
||||
bs, el = BS + timedelta(seconds=900 * q), t - 900 * q
|
||||
@@ -167,6 +172,18 @@ check("T2c: b at 389 W (13 611 W, aim + 11 W): it does not, from E+0",
|
||||
not any(e389) and len(e389) == 6)
|
||||
check("T2c: readings 395 then 385 W: graded on 385 W, no explanation from "
|
||||
"the second cycle on", not any(e395[1:]) and len(e395) == 6)
|
||||
# review round 1 (MD): the meter shows the higher output while the readings
|
||||
# are 389 W then 800 W. b gives 800 W; one reading of 389 W at E+3, the meter
|
||||
# still at 800 W. House 14 005 W: at E+4 the house latch grades on the lower
|
||||
# reading (389 W), rest 13 616 W, landing 13 614 W > aim + 10 W; on the
|
||||
# current one (800 W) it would be 13 205 W.
|
||||
_cl, elag = urun(range(0, 12), const(14005.0 + CAR - 800.0),
|
||||
lambda t: 389.0 if t == 3 else 800.0, const(CAR))
|
||||
print(f" T2c lagging meter E+0..E+11: {run_of(elag, 0, 11)}")
|
||||
check("T2c (meter lags, readings 389 then 800 W): explained before, the "
|
||||
"house latch sets on the lower reading at E+4 and holds to E+11",
|
||||
all(run_of(elag, 0, 3)) and not any(run_of(elag, 4, 11))
|
||||
and len(run_of(elag, 4, 11)) == 8)
|
||||
|
||||
# --- T4: ALARM_MISS_W, batteries at 0 W -------------------------------------- #
|
||||
e09 = run_of(urun(range(0, 6), const(13609.0 + CAR), const(0.0),
|
||||
@@ -503,9 +520,12 @@ a9c = nth(H.alarms(r9c), 0)
|
||||
check("T9(c): reports 1 380 W, draws 100 W: the first alarm once the figure "
|
||||
"is uncorroborated, at most 104 s + 10 s after the edge, no later than "
|
||||
"base", present(a9c) and a9c <= E + 114 and a9c <= T9C_BASE)
|
||||
print(f" T9(c) alarm edges {[t - E for t in H.edges(tr9c)]} (base: one; "
|
||||
f"the meter's 10 Wh step re-corroborates the figure every 360 s and "
|
||||
f"Expected 3/5 release the alarm then: see the dev report)")
|
||||
check("T9(c) (owner 2026-11-19): the meter contradicted the figure, so it "
|
||||
"stays untrusted to the quarter's end: one alarm edge, red and never "
|
||||
"explained to E+899 (the meter's 10 Wh step re-corroborates it every "
|
||||
"360 s)", H.edges(tr9c) == [a9c] and all(
|
||||
x["alarm"] and x["red"] and not x["explains"]
|
||||
for x in H.window(tr9c, a9c, E + 899)))
|
||||
|
||||
# --- T10: a lost battery reading, an unavailable charger ---------------------- #
|
||||
for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
|
||||
@@ -606,6 +626,16 @@ for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
|
||||
f"as base; red throughout",
|
||||
H.alarms(rr) == T5_BASE + [at] and len(H.red_secs(trr))
|
||||
== len(H.red_secs(tr0)))
|
||||
elif nm == "T2" and at == E + 300:
|
||||
# review round 1: the car's energy before a restart is not known,
|
||||
# so it counts as house (never credited to the car). Here that
|
||||
# tips the house alone over the aim: the alarm stands from the
|
||||
# restart, the conservative side (base: red from E+0).
|
||||
check("T17 T2, restart at E+300: quiet before the restart; after "
|
||||
"it the car's unknown earlier share counts as house, so at "
|
||||
"most one alarm edge, at the restart",
|
||||
quiet(rr0, tr0) and H.red_secs(trr, t1=at - 1) == []
|
||||
and H.edges(trr) in ([], [at]))
|
||||
else:
|
||||
check(f"T17 {nm}, restart at E+{at - E}: the same as without "
|
||||
f"(no floor notice, no ERROR, no red row)",
|
||||
@@ -616,6 +646,25 @@ for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
|
||||
f"once-per-session state does not survive a restart, as on "
|
||||
f"base)")
|
||||
|
||||
# --- T17b (review round 1): a house need only the done part shows ----------- #
|
||||
def heavy_then_light(t):
|
||||
"""House 18 000 W for E..E+300, then 12 000 W: alone it lands 14 000 W."""
|
||||
if t < E:
|
||||
return H.PRE_W if t < E - 120 else 12000.0
|
||||
return 18000.0 if t < E + 300 else 12000.0
|
||||
|
||||
|
||||
r17b0, tr17b0 = H.run(heavy_then_light, a=ZERO, b=ZERO)
|
||||
r17b, tr17b = H.run(heavy_then_light, a=ZERO, b=ZERO,
|
||||
extra=restart_at(E + 310))
|
||||
summary("T17b no restart", r17b0, tr17b0)
|
||||
summary("T17b restart at E+310", r17b, tr17b)
|
||||
check("T17b: the house heavy before a restart at E+310 (alone it lands "
|
||||
"14 000 W, excess 1 780 W > car): red to the quarter's end and never "
|
||||
"explained, as without the restart (and as base and Off)",
|
||||
len(H.red_secs(tr17b, E, E + 899)) == len(H.red_secs(tr17b0, E, E + 899))
|
||||
== 899 and not any(x["explains"] for x in H.window(tr17b, E, E + 899)))
|
||||
|
||||
# --- T15 controller: x10 ------------------------------------------------------ #
|
||||
# F2 (out of scope, filed apart): `_car_quarter` caps a cycle's dt at 5 s, so at
|
||||
# 10 s a cycle half the car's energy is counted, and late in the quarter the
|
||||
@@ -669,12 +718,11 @@ def per_quarter(ts):
|
||||
|
||||
|
||||
many = [(nm, ts) for nm, ts in RUNS
|
||||
if not nm.startswith("T9(c)")
|
||||
and any(v > 1 for v in per_quarter(
|
||||
if any(v > 1 for v in per_quarter(
|
||||
[t for t in ts if not nm.startswith("T15 x10") or t < F2_FROM])
|
||||
.values())]
|
||||
check(f"N5: at most one floor-alarm edge per quarter in every run "
|
||||
f"({len(RUNS)} runs; T9(c) apart, x10 to E+500): {many}", many == [])
|
||||
f"({len(RUNS)} runs; x10 to E+500): {many}", many == [])
|
||||
|
||||
print()
|
||||
print("FAIL: " + ", ".join(fails) if fails else "PASS: every check passed")
|
||||
|
||||
Reference in New Issue
Block a user