EV-54 review r2: fails counts only refusals of the value now owed
Where a refused cut value stops being owed without a drop (the charger's return, another value written in its place), fails goes to 0; cut_fails is untouched. After a return under a capped quarter, Solar's own write gets its own 3 tries again instead of giving up after 1. New rows T40 (refused to 1430), T41 (to 1600, against the run without the away), T42 (replaced value). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -604,6 +604,95 @@ check(f"T39 (review r1): a new cut value above the refused one, under the "
|
||||
f"read-back, goes out as 'peak cut' ({t39})",
|
||||
t39[0] == [6.0, 7.0] and t39[1] == "peak cut")
|
||||
|
||||
# =========================================================================== #
|
||||
print("\n8. REVIEW ROUND 2: `fails` COUNTS ONLY THE OWED VALUE (T40-T42)")
|
||||
# =========================================================================== #
|
||||
|
||||
|
||||
def away_run(h, s, refuse_end, away=True):
|
||||
ev = {}
|
||||
if away:
|
||||
ev = {1100: lambda p, c: p.ch.go_unavailable(),
|
||||
1200: lambda p, c: p.ch.go_unavailable(False)}
|
||||
return run(house_c((1250, 900.0), h=h), sun_c((1250, 9000.0), s=s),
|
||||
dur=1800, events=window(ev, 959, refuse_end))
|
||||
|
||||
|
||||
def after_lift(r):
|
||||
tl = t_lift(r, 1200, 1800)
|
||||
w = [(t, a, ok) for t, a, ok, _w in writes(r, tl or 1e9, 1800)]
|
||||
hold = [t for t, _lv, _m in r["w"].lines(HOLD_TEXT)]
|
||||
gu = [x["t"] for x in rows(r, tl or 1e9, 1800) if x["gave_up"]]
|
||||
cf = sorted({x["cut_fails"] for x in rows(r, 1081, tl or 1e9)}, key=str)
|
||||
return tl, w, hold, gu, cf
|
||||
|
||||
|
||||
# T40 (PM row a): the charger refuses to 1430: after the return Solar's own
|
||||
# write gets its own tries; the 2nd, 60 s later, is taken.
|
||||
for tag, h, s in (("0 A", 3000.0, 0.0), ("6 A", 900.0, 1900.0)):
|
||||
r = away_run(h, s, 1430)
|
||||
tl, w, hold, gu, cf = after_lift(r)
|
||||
pre = [t for t, _a, _ok, _w in writes(r, 1081, tl or 1e9)]
|
||||
tk = [t for t, _a, ok in w if ok]
|
||||
check(f"T40 [{tag}] (review r2): away 1100-1200 while capped, refused to "
|
||||
f"1430: nothing until the lift at {tl} ({pre}); then Solar tries "
|
||||
f"{w[:3]}: the 1st refused, the 2nd 60 s later, a taken write by "
|
||||
f"1462 ({tk[:1]}); no gave_up ({gu[:2]}) or hold text ({hold}); "
|
||||
f"the quarter's cut count unchanged across the return ({cf})",
|
||||
present(tl) and tl is not None and not pre and len(w) >= 2
|
||||
and not w[0][2] and w[1][0] - w[0][0] >= 60 and bool(tk)
|
||||
and tk[0] <= 1462 and not gu and not hold and cf == [3])
|
||||
never54(f"T40 [{tag}]", r)
|
||||
|
||||
|
||||
def ok41(res):
|
||||
tl, w, hold, gu, cf = res
|
||||
if not (len(w) == 3 and len(hold) == 1 and present(tl) and tl is not None
|
||||
and bool(gu)):
|
||||
return False
|
||||
return (not any(ok for _t, _a, ok in w) and w[0][0] <= tl + 60
|
||||
and all(b[0] - a[0] >= 60 for a, b in zip(w, w[1:]))
|
||||
and abs(hold[0] - w[2][0]) <= 1 and gu[0] >= w[2][0] - 1
|
||||
and cf == [3])
|
||||
|
||||
|
||||
# T41 (PM row b): refused to 1600: Solar's own 3 tries 60 s apart, then
|
||||
# gave_up and the hold text, as in the same run without the away.
|
||||
for tag, h, s in (("0 A", 3000.0, 0.0), ("6 A", 900.0, 1900.0)):
|
||||
ra = after_lift(away_run(h, s, 1600, away=True))
|
||||
rn = after_lift(away_run(h, s, 1600, away=False))
|
||||
check(f"T41 [{tag}] (review r2): refused to 1600: with the away {ra[1]}, "
|
||||
f"gave_up from {ra[3][:1]}, hold text {ra[2]}; without it {rn[1]}, "
|
||||
f"gave_up from {rn[3][:1]}, hold text {rn[2]}: 3 tries 60 s apart, "
|
||||
f"then gave_up, in both", ok41(ra) and ok41(rn))
|
||||
|
||||
|
||||
async def replaced_value():
|
||||
"""T42 (PM row c): a refused 6 A cut, then the next quarter's 7 A (the
|
||||
reachable path of T39) replaces it and is refused too: `fails` counts
|
||||
only the owed 7 A."""
|
||||
w = carmode.SolarWriter()
|
||||
w.engaged, w.sent_a, w.taken, w.last_a = True, 10.0, True, 10.0
|
||||
drv, trk = Drv(), Trk()
|
||||
w.cut_quarter("q1")
|
||||
w.cut_a, w.cut_on = 6.0, True
|
||||
await w._put(drv, 6.0, 10.0, 1000.0, trk)
|
||||
w.cut_quarter("q2")
|
||||
w.cut_a = 7.0
|
||||
await w._put(drv, 7.0, 10.0, 1070.0, trk)
|
||||
return list(drv.calls), w.fails, w.cut_fails, w.refused_cut
|
||||
|
||||
|
||||
try:
|
||||
t42 = asyncio.run(replaced_value())
|
||||
except Exception as e: # noqa: BLE001
|
||||
t42 = (["raised " + repr(e)], None, None, None)
|
||||
check(f"T42 (review r2): 6 A refused, then 7 A written in its place and "
|
||||
f"refused (calls {t42[0]}): fails {t42[1]} counts only the owed 7 A "
|
||||
f"(1), the new quarter's cut count {t42[2]} (1), owed {t42[3]}",
|
||||
t42[0] == [6.0, 7.0] and t42[1] == 1 and t42[2] == 1
|
||||
and t42[3] == 7.0)
|
||||
|
||||
tb_all = LOG.tracebacks(n_log0)
|
||||
check(f"N13: no traceback in this file's runs ({tb_all[:1]})", not tb_all)
|
||||
if TAKE:
|
||||
|
||||
Reference in New Issue
Block a user