Merge pull request 'EV-60: Solar never passes the cut cap per quarter; press during close retries gets 3 tries' (#283) from EV-60 into release/1.0
infra-pin / fresh (push) Successful in 2s
infra-pin / fresh (push) Successful in 2s
This commit was merged in pull request #283.
This commit is contained in:
@@ -840,6 +840,11 @@ class SolarPlan:
|
||||
self.a, self.set_at, self.last_dir = CH.MIN_A, now, -1
|
||||
|
||||
|
||||
class _CloseHeld(Exception):
|
||||
"""EV-60: Solar's cut gate holds the close (raised inside `_advance`'s
|
||||
want-a call, caught in `SolarWriter._advance`; never leaves it)."""
|
||||
|
||||
|
||||
class SolarWriter(ManualWriter):
|
||||
"""What Solar does to the charger, one `step()` per cycle. It shares
|
||||
ManualWriter's write, phase sequence and other-writer watch.
|
||||
@@ -901,6 +906,7 @@ class SolarWriter(ManualWriter):
|
||||
self.cut_warned = False # ... and its one CHARGER_REFUSED was given
|
||||
self.sent_cut = False # `sent_a` went out as a cut try
|
||||
self.refused_cut = None # a cut value the charger did not take
|
||||
self._cap_end = False # EV-60: a capped close ended the change
|
||||
|
||||
def owe_start(self) -> None:
|
||||
"""C1: the add-on starts in Off while an exit 0 A of its own was still
|
||||
@@ -1084,7 +1090,50 @@ class SolarWriter(ManualWriter):
|
||||
return "peak cut" if q.get("cut") else "Solar"
|
||||
|
||||
def _close_end(self, now) -> None:
|
||||
self._failed(now) # EV-59: Solar stays as it was (EV-60)
|
||||
"""EV-60: no extra `_failed`. Each refused close was counted when it
|
||||
went (`_write`), a cut try in `cut_fails` too, so the sequence's end
|
||||
adds nothing (Manual's `_close_end` is EV-59's, unchanged)."""
|
||||
|
||||
def _cut_gate(self, now) -> bool:
|
||||
"""EV-60 (Q1): the quarter key's cut tries are used up, or the last
|
||||
refused one is less than RETRY_S old (`_put`'s two gates)."""
|
||||
return self.cut_fails >= MAX_TRIES or (
|
||||
self.cut_fail_at is not None and now - self.cut_fail_at < RETRY_S)
|
||||
|
||||
async def _advance(self, drv, r, cur, now, tracker, want_a, clamp, rev):
|
||||
"""EV-60: Solar's capped close is a cut try, so it passes the cut's
|
||||
gates. Tries used up: the change ends at its 0 A, nothing written
|
||||
(`_cap_end`: `step` then leaves the plan as `end_switch(False)` put
|
||||
it). The sequence's first cut close waits at 0 A until RETRY_S after
|
||||
the last refused cut try (counts nothing, ends nothing); after a cut
|
||||
close of the sequence went, the 5 s spacing of `_advance` rules."""
|
||||
self._cap_end = False # set again below, read by `step` only
|
||||
if callable(want_a):
|
||||
# The gate runs where `_advance` asks for the close value, just
|
||||
# before it writes: also on the "car kept drawing" path, which
|
||||
# turns zero into settle and closes in the same call.
|
||||
inner, hi = want_a, (CH.ENTITY_MAX_A if clamp is None
|
||||
else float(clamp))
|
||||
|
||||
def want_a(q):
|
||||
v = inner(q)
|
||||
if self._cut_try(min(max(float(v), CH.MIN_A), hi)):
|
||||
if self.cut_fails >= MAX_TRIES:
|
||||
self.seq, self.last_a, self.reapply = None, None, True
|
||||
self.rev_applied = None
|
||||
self.plan.end_switch(False)
|
||||
self._cap_end = True
|
||||
raise _CloseHeld
|
||||
if not q.get("cut_went") and self.cut_fail_at is not None \
|
||||
and now - self.cut_fail_at < RETRY_S:
|
||||
raise _CloseHeld
|
||||
q["cut_went"] = True
|
||||
return v
|
||||
try:
|
||||
await super()._advance(drv, r, cur, now, tracker, want_a, clamp,
|
||||
rev)
|
||||
except _CloseHeld:
|
||||
pass
|
||||
|
||||
def _failed(self, now) -> None:
|
||||
if self.sent_cut:
|
||||
@@ -1321,10 +1370,15 @@ class SolarWriter(ManualWriter):
|
||||
async def _begin_solar(self, drv, r, cur, n, now, tracker) -> None:
|
||||
"""Step 1 of the safe sequence: 0 A (kept when it already stands).
|
||||
A 0 A the charger does not take ends the change; tried again later
|
||||
by the plan's own dwell."""
|
||||
by the plan's own dwell. EV-60: under a cap that 0 A is a cut try and
|
||||
passes the cut's gates; stopped by them the change waits (nothing
|
||||
written or counted, never a give-up) for the next quarter key."""
|
||||
owed = not (cur is not None and cur <= TOL_A and self.sent_a == 0.0
|
||||
and self.taken)
|
||||
if owed and self._cut_try(0.0) and self._cut_gate(now):
|
||||
return
|
||||
self.phase_done_at = None
|
||||
if not (cur is not None and cur <= TOL_A and self.sent_a == 0.0
|
||||
and self.taken):
|
||||
if owed:
|
||||
if not await self._write(drv, 0.0, cur, now, tracker):
|
||||
self.plan.end_switch(False)
|
||||
return
|
||||
@@ -1569,6 +1623,9 @@ class SolarWriter(ManualWriter):
|
||||
clamp, None)
|
||||
if any(x[0] == "phases" for x in self.log[n_log:]):
|
||||
q["sel"] = True # a select went out, taken or not
|
||||
if self.seq is None and self._cap_end:
|
||||
self._cap_end = False # EV-60: ended at 0 A, plan as it was
|
||||
return
|
||||
if self.seq is None:
|
||||
# Back on the old phases only when no select went out; after
|
||||
# one the plan keeps the current it wrote (the lower one) and
|
||||
|
||||
@@ -58,7 +58,10 @@ GOLDEN = {
|
||||
"T20 T5 [A]": "369069be9187ab3c", "T20 T5 [R]": "78ffe9cf72c5e214", # EV-59
|
||||
"T20 T8 [A]": "2cd78dee7ee93aaa", "T20 T8 [R]": "f0adb058a5bbefba",
|
||||
"T20 T11 [A]": "6d7bcb747d1dc5a3", "T20 T11 [R]": "2be1a760b699b28c",
|
||||
"T20 T12 [A]": "a5888e4557b4ee8f", "T20 T12 [R]": "2fd24ddbb18f14cc",
|
||||
"T20 T12 [A]": "a5888e4557b4ee8f",
|
||||
# EV-60 (Q4): re-taken; the only change from 2fd24ddbb18f14cc is Solar's
|
||||
# `fails` 4 -> 3 in cycles 323-372 (after the 3rd close: no extra _failed).
|
||||
"T20 T12 [R]": "25a205989dc44204",
|
||||
"T20 T13 [A]": "1ad97e089468d71b", "T20 T13 [R]": "7baf8981ab382e05",
|
||||
"T20 T15 [A]": "54701b140ec6f30b", "T20 T15 [R]": "0cfd3ccd334f378d",
|
||||
"T20 T15d [A]": "1d85595302dc032a", "T20 T15d [R]": "5fc65dbdc730e539",
|
||||
@@ -889,12 +892,13 @@ e12 = row_at(x12, t12)
|
||||
check(f"T12: the change's close raises: writer equal to R ({eq12[:1]})",
|
||||
not eq12)
|
||||
check(f"T12: 3 close tries 5 s apart ({ts(c12)[:3]}); then seq None, the "
|
||||
f"change ended ({e12 and e12[2]['plan']}), fails 4 as with R "
|
||||
f"change ended ({e12 and e12[2]['plan']}), fails MAX_TRIES as with R "
|
||||
f"(EV-60: no extra _failed at Solar's close end) "
|
||||
f"({e12 and e12[2]['fails']}); the car at 0 A; one select only "
|
||||
f"({sel12})",
|
||||
len(c12) >= 3 and gaps(ts(c12)[:3]) == [5.0, 5.0]
|
||||
and e12 is not None and e12[2]["seq"] is None
|
||||
and e12[2]["fails"] == 4 and e12[2]["plan"][2] is False
|
||||
and e12[2]["fails"] == CM.MAX_TRIES and e12[2]["plan"][2] is False
|
||||
and x12["sim"].setpoint_a == 0.0 and len(sel12) == 1)
|
||||
never("T12", x12, close_ok=True)
|
||||
|
||||
@@ -1036,6 +1040,12 @@ def c4b(kind):
|
||||
return r
|
||||
drv = Drv(8.0, answer)
|
||||
w, trk, run = solar_writer(8.0), Trk(), Runner()
|
||||
# EV-60: the capped change ends and the plan is back at 8 A; the real
|
||||
# plan lowers it to the cap again at its next step (SolarPlan.step), so
|
||||
# nothing above the cap is written.
|
||||
w._plan_step = lambda *a, **k: (
|
||||
w.plan._cut(w.cut_a) if w.cut_a is not None and w.cut_a >= CH.MIN_A
|
||||
and w.plan.a > w.cut_a else None)
|
||||
w.cut_a, w.cut_on = 0.0, True
|
||||
w.plan.a = 0.0
|
||||
t = 0
|
||||
@@ -1055,12 +1065,13 @@ def c4b(kind):
|
||||
return tries, w.cut_fails, run
|
||||
|
||||
|
||||
for route, fn, want, cf in (("a", c4c, [0, 60, 120, 180], 4),
|
||||
("b", c4b, [0, 60, 120, 192, 197, 202], 7)):
|
||||
for route, fn, want, cf in (("a", c4c, [0, 60, 120], 3),
|
||||
("b", c4b, [0, 60, 120], 3)):
|
||||
res = {k: fn(k) for k in "RX"}
|
||||
check(f"T19b [{route}] (H4, not worse than base): refused cut tries per "
|
||||
f"key R {res['R'][0]} cut_fails {res['R'][1]}, X {res['X'][0]} "
|
||||
f"cut_fails {res['X'][1]} = base {want} / {cf}; no record",
|
||||
check(f"T19b [{route}] (H4, EV-60: never past the cap of MAX_TRIES): "
|
||||
f"refused cut tries per key R {res['R'][0]} cut_fails "
|
||||
f"{res['R'][1]}, X {res['X'][0]} cut_fails {res['X'][1]} = "
|
||||
f"{want} / {cf} (base had 4 / 7 tries); no record",
|
||||
res["R"][0] == res["X"][0] == want
|
||||
and res["R"][1] == res["X"][1] == cf
|
||||
and not res["X"][2].recs() and not res["R"][2].recs())
|
||||
|
||||
@@ -617,12 +617,15 @@ def sp3(press, cls=solar_writer):
|
||||
|
||||
S_NONE = sp3(False)
|
||||
S_PRESS = sp3(True)
|
||||
check(f"T25/T14 (N14): Solar equals base. No press: 8 A at 12, 17, 22, fails "
|
||||
f"4, gave_up, REF at 22 ({S_NONE})",
|
||||
S_NONE == ([12, 17, 22], 4, True, [22], None))
|
||||
check(f"T25 (resetSuper trap): a Solar press at 13 does not reset Solar's "
|
||||
f"tries: 8 A at 12, 17, 22, fails 3, gave_up, REF at 22 ({S_PRESS})",
|
||||
S_PRESS == ([12, 17, 22], 3, True, [22], 13))
|
||||
check(f"T25/T14 (N14, EV-60): Solar has no extra _failed at its close end. "
|
||||
f"No press: 8 A at 12, 17, 22, fails 3, gave_up, REF at 22 "
|
||||
f"({S_NONE})",
|
||||
S_NONE == ([12, 17, 22], 3, True, [22], None))
|
||||
check(f"T25 (resetSuper trap, EV-60): a Solar press at 13 does not reset "
|
||||
f"Solar's close tries, and the value gets MAX_TRIES tries since the "
|
||||
f"press: 8 A at 12, 17, 22, 82, fails 3, gave_up, REF at 82 "
|
||||
f"({S_PRESS})",
|
||||
S_PRESS == ([12, 17, 22, 82], 3, True, [82], 13))
|
||||
|
||||
def t14c():
|
||||
"""T14c: Solar's close value changes between the tries (the spare falls
|
||||
@@ -650,10 +653,10 @@ def t14c():
|
||||
|
||||
|
||||
S14C = t14c()
|
||||
check(f"T14c (N14): Solar's close value moves between tries: 8, 7, 6 A at "
|
||||
f"10, 15, 20, then `fails` 4, gave_up, REF at 20, seq None, as base "
|
||||
f"({S14C})",
|
||||
S14C == ([(10, 8.0), (15, 7.0), (20, 6.0)], 4, True, [20], None))
|
||||
check(f"T14c (N14, EV-60): Solar's close value moves between tries: 8, 7, 6 A "
|
||||
f"at 10, 15, 20, then `fails` 3 (no extra _failed), gave_up, REF at "
|
||||
f"20, seq None ({S14C})",
|
||||
S14C == ([(10, 8.0), (15, 7.0), (20, 6.0)], 3, True, [20], None))
|
||||
|
||||
print("\n6. THE CAP, RESTART, UNKNOWN, NO CHARGER (T15-T22)")
|
||||
UCS.clear()
|
||||
@@ -737,7 +740,8 @@ s56, s13, s28 = tsrc("test_ev56.py"), tsrc("test_ev13.py"), tsrc("test_ev28.py")
|
||||
BASE_DIGESTS = ("905c0b8ba89bb307", "343ea01aacfa1019", "ff6306ce56b35c64",
|
||||
"f1fb141275839562", "369069be9187ab3c", "2cd78dee7ee93aaa",
|
||||
"f0adb058a5bbefba", "6d7bcb747d1dc5a3", "2be1a760b699b28c",
|
||||
"a5888e4557b4ee8f", "2fd24ddbb18f14cc", "1ad97e089468d71b",
|
||||
# EV-60 (Q4): "T20 T12 [R]" re-taken, was 2fd24ddbb18f14cc
|
||||
"a5888e4557b4ee8f", "25a205989dc44204", "1ad97e089468d71b",
|
||||
"7baf8981ab382e05", "54701b140ec6f30b", "0cfd3ccd334f378d",
|
||||
"1d85595302dc032a", "5fc65dbdc730e539")
|
||||
check("T17 (Q1, Q2): test_ev56 has the re-taken golden 'T20 T5 [R]' "
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user