EV-21: Solar cuts the car first for the quarter peak
In Solar, when the 15-minute period heads over the aim and the batteries would have to give more, the car is lowered first: floor((car - excess) / (230 x phases)) A, 0 under 6 A. At once without real headroom (saturated, floor-limited, excess beyond what the batteries can add, no battery figure, cover off, last 120 s), else after at most 15 s. One cut per episode from its start, deeper only on a growing excess; restart with the start power under the aim for the start time; none after a 2nd cut in the period. Grading (formal C2): a Solar car Solar cannot cut is graded, banked and left in the guard as in Off. A Solar car is never banked. Grey note and Why "Solar lowered the car for the peak." Manual and Off unchanged. Tests: test_ev21.py, test_ev21_paths.py, test_ev21_same.py; T49 in tools/ev20_day.py; T50 in test_ev20_fuzz.py; test_ev20_guard section 8 moved from "as Manual" to "as Off" where Solar cannot cut (T51). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""EV-20: the peak guard treats a Solar car as a Manual car; Solar kWh; what
|
||||
"""EV-20: the peak guard and a Solar car (EV-21: as Off where Solar cannot cut
|
||||
it, as Manual's grading otherwise); Solar kWh; what
|
||||
stays unchanged; the strings, docs and settings; the write seam (T21, T22,
|
||||
T47-T52, T55, T57-T60).
|
||||
`python3 -B test_ev20_guard.py`
|
||||
@@ -38,7 +39,8 @@ from ev20_kit import (_dies, _err, _freeze_after_write, _shutdown, # noqa: E40
|
||||
|
||||
|
||||
# =========================================================================== #
|
||||
print("\n8. THE PEAK GUARD: A SOLAR CAR IS A MANUAL CAR (T21, T22, T47, T48)")
|
||||
print("\n8. THE PEAK GUARD: A SOLAR CAR SOLAR CANNOT CUT IS OFF'S (T21, T22, "
|
||||
"T47, T48; EV-21)")
|
||||
# =========================================================================== #
|
||||
ALARMS = S.ALARMS
|
||||
|
||||
@@ -48,17 +50,12 @@ def twin(mode, **kw):
|
||||
**kw)
|
||||
|
||||
|
||||
def manual_twin(rs, **kw):
|
||||
"""The Manual twin of a Solar run: the same plant and events, Manual with
|
||||
its writer held still, and Solar's own writes put on the charger at the
|
||||
same seconds, so both runs have the same charger trace and only the mode
|
||||
differs for the peak guard."""
|
||||
def off_twin(rs, **kw):
|
||||
"""EV-21: the Off twin of a Solar run: the same plant and events, and
|
||||
Solar's own writes put on the charger at the same seconds. Where Solar
|
||||
cannot cut the car (another writer, Stop, shadow, a safety stop), the
|
||||
alarm path, the banking and the guard are this twin's (Q5, OQ8, C2)."""
|
||||
ev = dict(kw.pop("events", None) or {})
|
||||
|
||||
def inert(p, c):
|
||||
async def nop(*a, **k):
|
||||
return None
|
||||
c.car_writer.step = nop
|
||||
rep_ = {}
|
||||
for t_sim, what, v, _pw, _sp in rs["sim"].log:
|
||||
rep_.setdefault(int(round(t_sim)), []).append((what, v))
|
||||
@@ -67,13 +64,23 @@ def manual_twin(rs, **kw):
|
||||
for what, v in acts:
|
||||
(p.ch.set_current if what == "current" else p.ch.set_phases)(v)
|
||||
ev[t] = both(ev[t], put) if t in ev else put
|
||||
ev[0] = both(ev[0], inert) if 0 in ev else inert
|
||||
return twin("manual", events=ev, **kw)
|
||||
return twin("off", events=ev, **kw)
|
||||
|
||||
|
||||
def guard_view(r, t0=0):
|
||||
return [(x["t"], x["explains"], x["over"], tuple(x["red"]),
|
||||
x["alarm_w"] is None) for x in r["trace"] if x["t"] >= t0]
|
||||
def alarm_view(r, t0=0):
|
||||
"""EV-21: the alarm path only (car_explains, red rows, the car figure);
|
||||
the car-over row is display and shows when Solar cannot cut (OQ5)."""
|
||||
return [(x["t"], x["explains"], tuple(x["red"]), x["alarm_w"] is None)
|
||||
for x in r["trace"] if x["t"] >= t0]
|
||||
|
||||
|
||||
def alarms_of(r):
|
||||
return [(t, n) for t, n in r["raised"] if n in ALARMS]
|
||||
|
||||
|
||||
def same_alarms(a, b):
|
||||
return len(a) == len(b) and all(abs(x[0] - y[0]) <= 2 and x[1] == y[1]
|
||||
for x, y in zip(a, b))
|
||||
|
||||
|
||||
def notes(r):
|
||||
@@ -88,44 +95,45 @@ for cover in (True, False):
|
||||
opts={"ev_phases": "3", "ev_batt_cover": cover},
|
||||
events={600: lambda p, c: p.ch.set_current(16)})
|
||||
rs = twin("solar", **dict(kw))
|
||||
rm = manual_twin(rs, **dict(kw))
|
||||
gs, gm = guard_view(rs, 640), guard_view(rm, 640)
|
||||
rm = off_twin(rs, **dict(kw))
|
||||
gs, gm = alarm_view(rs, 640), alarm_view(rm, 640)
|
||||
diff = [(a, b) for a, b in zip(gs, gm) if a[1:] != b[1:]]
|
||||
check(f"T21 (b{'' if cover else ', c'}) cover {'on' if cover else 'off'}:"
|
||||
f" another writer's 16 A in Solar is graded, shown and notified as "
|
||||
f"the Manual car at 16 A, every cycle from 640 s ({len(diff)} "
|
||||
f" another writer's 16 A in Solar (Solar cannot cut it) is graded "
|
||||
f"as the Off twin, every cycle from 640 s (EV-21; {len(diff)} "
|
||||
f"differ: {diff[:2]})", not diff)
|
||||
ns, nm = notes(rs), notes(rm)
|
||||
check(f"T21 (b) cover {'on' if cover else 'off'}: the same notices at the "
|
||||
f"same seconds +2 s, never silent ({ns} vs {nm})",
|
||||
len(ns) == len(nm) and all(abs(a[0] - b[0]) <= 2 and a[1] == b[1]
|
||||
for a, b in zip(ns, nm))
|
||||
and (ns or any(x[2] for x in gs)))
|
||||
check(f"T21: the car's banked quarters are the Manual twin's "
|
||||
ns, nm = alarms_of(rs), alarms_of(rm)
|
||||
over_s = [t for t, n in rs["raised"] if n == messages.ID_CAR_OVER]
|
||||
check(f"T21 (b) cover {'on' if cover else 'off'}: the Off twin's alarms "
|
||||
f"at the same seconds +2 s, never silent ({ns} vs {nm}); the "
|
||||
f"car-over note shows, as Solar cannot cut ({over_s[:1]})",
|
||||
same_alarms(ns, nm) and bool(ns) and bool(over_s))
|
||||
check(f"T21: the car's banked quarters are the Off twin's "
|
||||
f"({rs['c'].car_peak_q} vs {rm['c'].car_peak_q})",
|
||||
rs["c"].car_peak_q == rm["c"].car_peak_q)
|
||||
if not cover:
|
||||
pj = [(round(a["proj"] or 0), round(b["proj"] or 0))
|
||||
for a, b in zip(rs["trace"], rm["trace"]) if a["t"] >= 640
|
||||
and round(a["proj"] or 0) != round(b["proj"] or 0)]
|
||||
check(f"T21 (c): with the cover off, the guard's own projection "
|
||||
f"(the car left out) is the Manual twin's ({pj[:2]})", not pj)
|
||||
check(f"T21 (c): with the cover off and Solar unable to cut, the "
|
||||
f"guard keeps the car in, as the Off twin (Q-A; {pj[:2]})",
|
||||
not pj)
|
||||
# T21 (a): car_cycle itself, fed the same projection, guard and reading on
|
||||
# two Controllers that differ only in the mode (the twins of (c), now).
|
||||
cs, cm = rs["c"], rm["c"]
|
||||
proj_s, guard_s = cs._peak_proj_real, cs.peak_guard
|
||||
same_in = (proj_s == cm._peak_proj_real
|
||||
and repr(guard_s) == repr(cm.peak_guard)
|
||||
and cs.car.reading == cm.car.reading)
|
||||
cs.car_cycle(proj_s, guard_s, 3400.0, None)
|
||||
cm.car_cycle(proj_s, guard_s, 3400.0, None)
|
||||
check(f"T21 (a): car_cycle on the same projection, guard and reading gives "
|
||||
f"the same car_alarm_w, car_explains and car_over in Solar and Manual "
|
||||
f"(inputs equal {same_in}; {cs.car_alarm_w()} {cs.car_explains} "
|
||||
f"{cs.car_over} vs {cm.car_alarm_w()} {cm.car_explains} {cm.car_over})",
|
||||
same_in and (cs.car_alarm_w(), cs.car_explains, cs.car_over)
|
||||
== (cm.car_alarm_w(), cm.car_explains, cm.car_over)
|
||||
and cs.car_alarm_w() is not None)
|
||||
check(f"T21 (a): car_cycle on the same projection and reading gives the "
|
||||
f"same car_alarm_w (None) and car_explains in Solar, under another "
|
||||
f"writer, as in Off (EV-21, C2; inputs equal {same_in}; "
|
||||
f"{cs.car_alarm_w()} {cs.car_explains} vs {cm.car_alarm_w()} "
|
||||
f"{cm.car_explains})",
|
||||
same_in and (cs.car_alarm_w(), cs.car_explains)
|
||||
== (cm.car_alarm_w(), cm.car_explains)
|
||||
and cs.car_alarm_w() is None)
|
||||
over_note = [x for x in rs["plant"].notes if x[1] == messages.ID_CAR_OVER]
|
||||
check("T21 D1: Solar's car-over notice reads 'Solar charges the car at 16 A' "
|
||||
"(the charger's current), never Manual's stored value",
|
||||
@@ -145,13 +153,14 @@ for name, fn, opts in (("Stop (auto)", lambda p, c: setattr(c, "auto", False),
|
||||
opts=dict({"ev_phases": "3"}, **opts),
|
||||
events={500: fn, 600: lambda p, c: p.ch.set_current(16)})
|
||||
rs = twin("solar", **dict(kw))
|
||||
rm = manual_twin(rs, **dict(kw))
|
||||
gs, gm = guard_view(rs, 640), guard_view(rm, 640)
|
||||
rm = off_twin(rs, **dict(kw))
|
||||
gs, gm = alarm_view(rs, 640), alarm_view(rm, 640)
|
||||
diff = [(a, b) for a, b in zip(gs, gm) if a[1:] != b[1:]]
|
||||
check(f"T21 (d) [{name}]: graded and shown as the Manual twin each cycle "
|
||||
f"({len(diff)} differ: {diff[:1]}); notices "
|
||||
f"{notes(rs)} vs {notes(rm)}",
|
||||
not diff and [n for _, n in notes(rs)] == [n for _, n in notes(rm)])
|
||||
check(f"T21 (d) [{name}]: graded as the Off twin each cycle (EV-21; "
|
||||
f"{len(diff)} differ: {diff[:1]}); alarms "
|
||||
f"{alarms_of(rs)} vs {alarms_of(rm)}; banked as Off",
|
||||
not diff and same_alarms(alarms_of(rs), alarms_of(rm))
|
||||
and rs["c"].car_peak_q == rm["c"].car_peak_q)
|
||||
|
||||
# T22: EV-15 shapes in Solar: Solar's own 3 -> 1 sequence and own 0 A pause
|
||||
# with both batteries at the reserve.
|
||||
@@ -202,15 +211,15 @@ for T in (615, 640, 680):
|
||||
opts={"ev_phases": "3"},
|
||||
events={T: lambda p, c: p.ch.set_current(16)})
|
||||
rs = twin("solar", **dict(kw))
|
||||
rm = manual_twin(rs, **dict(kw))
|
||||
gs, gm = guard_view(rs, T), guard_view(rm, T)
|
||||
rm = off_twin(rs, **dict(kw))
|
||||
gs, gm = alarm_view(rs, T), alarm_view(rm, T)
|
||||
diff = [(a, b) for a, b in zip(gs, gm) if a[1:] != b[1:]]
|
||||
own = [x["t"] for x in rs["trace"] if x["t"] >= T and x["own"]]
|
||||
z = [t for t, a, _ in cur_writes(rs) if a == 0.0]
|
||||
check(f"T47 [T={T}]: Solar's own 0 A at {z[:1]}; the other writer's car "
|
||||
f"never counts as Solar's own pause (own-pause seconds from T: "
|
||||
f"{own[:3]}), rows and car_explains as the Manual twin "
|
||||
f"({len(diff)} differ: {diff[:1]})",
|
||||
f"{own[:3]}), rows and car_explains as the Off twin (EV-21; "
|
||||
f"{len(diff)} differ: {diff[:1]})",
|
||||
bool(z) and not own and not diff)
|
||||
# Solar's own pause is graded as its own for at most OWN_PAUSE_MAX_S.
|
||||
kw = dict(house=const(500.0), sun=step_fn((300, 0.0), base=7000.0), dur=1200,
|
||||
|
||||
Reference in New Issue
Block a user