SAFETY-135 round 2: the first guard stop in a period may restart once; tests and docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bdqr7PiaHcBnzPituu2yTC
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
66d8777b39
commit
4066624cce
@@ -472,15 +472,36 @@ _sw = [(UTC0.timestamp() + 60 * k, 2000.0 if k % 2 else 3900.0)
|
||||
ROWS_W, _, _ = run_day("p3_ch_sell", hours=1.5, house=_sw,
|
||||
soc0={"a": 60.0, "b": 30.0})
|
||||
_per_q = {}
|
||||
_ev_q = {} # SAFETY-135: per period, the charge's starts and stops
|
||||
for a_, b_ in zip(ROWS_W, ROWS_W[1:]):
|
||||
if a_["action"] != arbitrage.CHARGE and b_["action"] == arbitrage.CHARGE:
|
||||
on_a, on_b = (a_["action"] == arbitrage.CHARGE,
|
||||
b_["action"] == arbitrage.CHARGE)
|
||||
if on_a != on_b:
|
||||
q = int(b_["now"].timestamp() // 900)
|
||||
_ev_q.setdefault(q, []).append((on_b, b_["now"].timestamp()))
|
||||
if not on_a and on_b:
|
||||
q = int(b_["now"].timestamp() // 900)
|
||||
_per_q[q] = _per_q.get(q, 0) + 1
|
||||
|
||||
|
||||
def _one_restart(ev):
|
||||
"""At most one start after a stop in the period, RESTART_S or more after
|
||||
it; a second stop is the last change of the period."""
|
||||
re = [(t0, t1) for (s0, t0), (s1, t1) in zip(ev, ev[1:])
|
||||
if not s0 and s1]
|
||||
stops, late = 0, False
|
||||
for on, _t in ev:
|
||||
stops += 0 if on else 1
|
||||
late = late or (on and stops >= 2)
|
||||
return (len(re) <= 1 and not late
|
||||
and all(t1 - t0 >= modetrade.RESTART_S - 1 for t0, t1 in re))
|
||||
print(f" house swinging 2.0/3.9 kW each minute: charge starts per period "
|
||||
f"{sorted(_per_q.values())}")
|
||||
check("a charge the peak guard or the headroom stopped stays off for the "
|
||||
"rest of that 15-minute period (at most one start per period)",
|
||||
_per_q and max(_per_q.values()) == 1)
|
||||
"rest of that 15-minute period, after at most one restart RESTART_S or "
|
||||
"more after the first stop; a second stop latches (SAFETY-135)",
|
||||
_per_q and max(_per_q.values()) <= 2
|
||||
and all(_one_restart(ev) for ev in _ev_q.values()))
|
||||
|
||||
# At the floor: B starts the sale just above it.
|
||||
ROWS_F, _, _ = run_day("p3_ch_sell", start_h=18.75, hours=1.5,
|
||||
|
||||
Reference in New Issue
Block a user