EV-22 review round 1: press covers one reading, unknown read keeps the count, window ends on the close's clock
Major 1: the `pressed` mark of a sequence is consumed by the first `_advance`
(the first reading judged after the press); a later raise in the same zero
stage gets the raise-check hold again (Solar and Manual).
Major 2: with `cur` None `_watch` does not judge the current: the count
neither starts nor clears (phases are still judged).
Finding 4 (PM): the DA3 window uses the close's own clock and comparison
(`now - t1 < SETTLE_S`) and the one step that closes at its end is still
inside it, so a `last_done` a fraction of a second after the step's now no
longer pushes the close step outside the window.
Tests: rows A-D, R1 (Manual red under the mutant), the two fraction rows,
all red on b7c91ff. test_ev60: comment exactly as ruled, unused imports gone.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1047,4 +1047,164 @@ try:
|
||||
finally:
|
||||
CM.PHASE_GAP_S = keep_gap
|
||||
|
||||
# =========================================================================== #
|
||||
print("\nREVIEW ROUND 1 (rows A-D, R1, the window's closing step)")
|
||||
# =========================================================================== #
|
||||
|
||||
|
||||
class NoneSim(SimCharger):
|
||||
"""The read-back and the setpoint answer with a non-number while
|
||||
`badcur` (the charger is available, `cur` is None)."""
|
||||
badcur = False
|
||||
|
||||
def _build(self):
|
||||
out = super()._build()
|
||||
if self.badcur:
|
||||
for k in list(out):
|
||||
if k.endswith("max_current_socket_1") and \
|
||||
("number." in k or "main_active" in k):
|
||||
out[k] = dict(out[k], state="n/a")
|
||||
return out
|
||||
|
||||
|
||||
def badcur(on):
|
||||
def f(p, c):
|
||||
p.ch.badcur = on
|
||||
return f
|
||||
|
||||
|
||||
class LateSim(SimCharger):
|
||||
"""Ignores current writes while t0 <= sim t < t1 and remembers the last;
|
||||
`late` (an event) shows it: a write the charger took late."""
|
||||
owed = None
|
||||
t0, t1 = 0.0, 0.0
|
||||
|
||||
def request_current(self, a):
|
||||
if self.t0 <= self.t < self.t1:
|
||||
self.owed = a
|
||||
keep, self.refuse = self.refuse, "ignore"
|
||||
try:
|
||||
return super().request_current(a)
|
||||
finally:
|
||||
self.refuse = keep
|
||||
return super().request_current(a)
|
||||
|
||||
|
||||
def late(p, c):
|
||||
if p.ch.owed is not None:
|
||||
p.ch.set_current(p.ch.owed)
|
||||
|
||||
|
||||
T0Z = int(([x[2] for x in r13["c"].car_solar.log
|
||||
if x[0] == "current" and x[1] == 0.0 and x[2] > 400]
|
||||
or [580.0])[0])
|
||||
# A (Major 1, Solar): the press covers the first reading only; a later raise
|
||||
# in the same zero stage is held at once.
|
||||
n, rec = LOG.mark(), Rec()
|
||||
r = solar(800, sun=R39, sim=slow_sim(), rec=rec,
|
||||
events={T0Z + 2: act("car_mode", "solar"), T0Z + 8: setc(16)})
|
||||
check(f"T44 (A): Solar, a press at {T0Z + 2} in the zero stage, another "
|
||||
f"writer's 16 A at {T0Z + 8}: the raise check holds at once "
|
||||
f"({rec.first('hold', lambda v: v, T0Z + 8)}), nothing written over it "
|
||||
f"({after(r, T0Z + 8)})",
|
||||
(rec.first("hold", lambda v: v, T0Z + 8) or 99999) <= T0Z + 9
|
||||
and after(r, T0Z + 8) == [])
|
||||
# B (Major 1, Manual)
|
||||
rec = Rec()
|
||||
r = man(300, {102: act("car_current", 14), 106: setc(9)}, rec=rec,
|
||||
sim=slow_sim())
|
||||
check(f"T43 (B): Manual, the user sets 14 A at 102 in the zero stage, another "
|
||||
f"writer's 9 A at 106: held at once "
|
||||
f"({rec.first('mhold', lambda v: v, 106)}), nothing written over it "
|
||||
f"({after(r, 107)})",
|
||||
(rec.first("mhold", lambda v: v, 106) or 99999) <= 107
|
||||
and after(r, 107) == [] and r["sim"].setpoint_a == 9.0)
|
||||
# C (Major 2, Solar): an unknown read-back leaves the count alone.
|
||||
n, rec = LOG.mark(), Rec()
|
||||
r = solar(700, sun=R39, sim=NoneSim(setpoint_a=0), rec=rec,
|
||||
events={TS + 3: setc(16), TS + 9: badcur(True),
|
||||
TS + 12: badcur(False)})
|
||||
check(f"T9 (C): another writer's 16 A at {TS + 3}, an unknown read-back "
|
||||
f"{TS + 9}-{TS + 11}: the count stands "
|
||||
f"({[rec.d[t]['ms'] for t in (TS + 8, TS + 10, TS + 12)]}), nothing "
|
||||
f"is written over the 16 A ({after(r, TS + 3)}), the hold comes",
|
||||
rec.every("ms", lambda v: v is not None, TS + 5, TS + 14)
|
||||
and after(r, TS + 3) == []
|
||||
and rec.first("hold", lambda v: v) is not None)
|
||||
# D (Major 2, Manual)
|
||||
rec = Rec()
|
||||
r = man(300, {104: setc(9), 109: badcur(True), 113: badcur(False)}, rec=rec,
|
||||
sim=NoneSim(setpoint_a=0))
|
||||
check(f"T1 (D): Manual, 9 A at 104, an unknown read-back 109-112 over the "
|
||||
f"close at 111: no write over the 9 A ({after(r, 104)}), the count "
|
||||
f"stands ({[rec.d[t]['mm'] for t in (108, 110, 112)]})",
|
||||
after(r, 104) == [] and rec.every("mm", lambda v: v is not None, 106, 112))
|
||||
# R1: the sequence's own values count as own after a press (formal note).
|
||||
lm = LateSim(setpoint_a=0)
|
||||
lm.t0, lm.t1 = 110.0, 120.0
|
||||
rec = Rec()
|
||||
r = man(260, {113: act("car_current", 12), 120: late}, rec=rec, sim=lm)
|
||||
check(f"T43 (R1, Manual): the close refused until 120, a press at 113 clears "
|
||||
f"`attempted_a`, the charger then shows the late close: own value, "
|
||||
f"never a mismatch or a hold "
|
||||
f"({rec.first('mm', lo=100)}, {rec.first('mhold', lambda v: v)})",
|
||||
rec.first("mm", lo=100) is None
|
||||
and rec.first("mhold", lambda v: v) is None)
|
||||
ls = LateSim(setpoint_a=0)
|
||||
ls.t0, ls.t1 = TS + 10.5, TS + 14.0 # the close at 592 (sim 593) ignored
|
||||
rec = Rec()
|
||||
r = solar(700, sun=R39, sim=ls, rec=rec,
|
||||
events={TS + 12: act("car_mode", "solar"), TS + 14: late})
|
||||
check(f"T44 (R1, Solar): the close refused from 592, a press at {TS + 12}, "
|
||||
f"the charger then shows the late close: own value, never a mismatch "
|
||||
f"or a hold ({rec.first('ms', lo=TS)}, "
|
||||
f"{rec.first('hold', lambda v: v)})",
|
||||
rec.first("ms", lo=TS) is None
|
||||
and rec.first("hold", lambda v: v) is None)
|
||||
|
||||
|
||||
# Finding 4: `last_done` a fraction of a second after the step's `now`: the
|
||||
# step that closes is still inside the window.
|
||||
def frac_run(taken_late):
|
||||
w = swriter(0.0, ph=3)
|
||||
w.plan.a, w.plan.n = 12.0, 1
|
||||
drv = Drv(0.0, ph=3)
|
||||
w.seq = {"stage": "settle", "t0": 119.0, "t1": 121.4, "n": 1, "tries": 0,
|
||||
"prev": None, "from": 3, "own": [0.0], "sel": True}
|
||||
w.last_done = 121.4
|
||||
w._own_n = 3
|
||||
w._select_try(1, not taken_late)
|
||||
ms = {}
|
||||
|
||||
def pre(w_, d, t):
|
||||
if taken_late:
|
||||
d.ph = 1 if t >= 132 else 3 # the take is first seen at 132
|
||||
else:
|
||||
d.ph = 3 if t >= 124 else 1 # another writer's 3 phases
|
||||
ms[t] = w_.mismatch_since
|
||||
trk = Trk()
|
||||
for t in range(122, 138):
|
||||
drv.now = float(t)
|
||||
pre(w, drv, t)
|
||||
rd = Rd(drv.cur, drv.ph, power=0.0 if drv.cur == 0 else 1840.0)
|
||||
LOOP.run_until_complete(w.step(
|
||||
drv, rd, mode=CM.SOLAR, sun=CM.SunInputs(target_w=2000.0),
|
||||
clamp=16.0, now=float(t), tracker=trk, writing=True,
|
||||
status="charging"))
|
||||
ms[t] = w.mismatch_since
|
||||
return w, drv, ms
|
||||
|
||||
|
||||
w, drv, ms = frac_run(False)
|
||||
cl = [(int(t), a) for t, a in drv.calls if a > 0]
|
||||
check(f"T29 (fraction): last_done 121.4, the close step at 132 (10.6 s later) "
|
||||
f"is inside the window: the close is written at 132 ({cl}), no "
|
||||
f"mismatch at 132 ({ms[132]}), the mismatch from 133 ({ms[133]})",
|
||||
cl and cl[0][0] == 132 and ms[132] is None and ms[133] == 133.0)
|
||||
w, drv, ms = frac_run(True)
|
||||
check(f"T48 (fraction): a take first seen on the closing step (132, last_done "
|
||||
f"121.4) is Solar's own: own phases {w._own_n}, no mismatch "
|
||||
f"({ms[132]}, {ms[134]})",
|
||||
w._own_n == 1 and ms[132] is None and ms[134] is None)
|
||||
|
||||
report()
|
||||
|
||||
Reference in New Issue
Block a user