EV-05 round 5: headroom counts only the batteries that can give
checks / unit (pull_request) Successful in 24m24s
infra-pin / fresh (pull_request) Successful in 2s

Review of 8818768: the headroom test compared the output with the site
rating, which still counted a battery refusing to give (SAFETY-73) or under
a safety stop, so the 15 s wait ran at the real maximum (N4). Now only the
units that can give (above their cut-out, not refusing, not stopped,
switched on) count, in what they give and in their ratings.

Tests: R5a (A refuses, B at full rating, against a car-Off twin: the cut at
910, period 3361 W), R5b (headroom and a slow battery: the cut at exactly
15 s), R5c (floor-limited alone decides: cut at once). DOCS wrapped to 79.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-18 17:27:17 +01:00
co-authored by Claude
parent 8818768dab
commit 69f58181bc
5 changed files with 164 additions and 46 deletions
+94
View File
@@ -1714,6 +1714,100 @@ for H in (25900.0, 25950.0):
cut4 is not None and since4 is not None
and cut4["t"] - since4 <= 1 and 900 in q4 and 900 in q4o
and q4[900] <= 3400.0 and q4o[900] <= 3400.0)
# =========================================================================== #
print("\nROUND 5. HEADROOM COUNTS ONLY BATTERIES THAT CAN GIVE; EACH CLAUSE DECIDES")
# =========================================================================== #
def headroom_at(store):
def f(p, c, t):
g = c.peak_guard
store[t] = (c._car_batt_headroom(g), c.site_batt_w,
None if g is None else (g.saturated, g.floor_limited))
return f
def since_cut(r, t0):
since = next((x["since"] for x in r["trace"] if x["since"] is not None
and x["t"] >= t0), None)
cut = first_cut(r, t0)
return since, (None if cut is None else cut["t"])
# R5a (review round 4 repro): A refuses to give from 850 (SAFETY-73), B gives
# its full 4600 W; the house steps to 8000 W at 905 and 20 950 W at 908. Only
# the full-rating clause, counted over the units that can give, decides: the
# guard is neither saturated (its rating still counts A) nor at the reserve.
def _refuse_a(p, c):
if not getattr(p, "_a_held", False):
p._a_held = True
orig = p.batt_of
p.batt_of = lambda u, at, _o=orig: (min(_o(u, at), 0.0) if u == "a"
else _o(u, at))
[i for i in c.inverters if i.name.endswith("a")][0].refused = 1
hh5 = steps((0, 500.0), (905, 8000.0), (908, 20950.0))
EV5 = {t: _refuse_a for t in range(850, 1810)}
hr5 = {}
r5a = S.drive(house=hh5, sun=const(13000.0), first="car", socs=ABLE,
dur=1810, opts={"slew_w": 0}, events=dict(EV5),
on_cycle=headroom_at(hr5))
r5ao = S.drive(house=hh5, sun=const(13000.0), first="car", socs=ABLE,
dur=1810, opts={"slew_w": 0}, events=dict(EV5), mode="off")
q5 = {q: g for q, g, _c in quarters(r5a, 3400.0)}
q5o = {q: g for q, g, _c in quarters(r5ao, 3400.0)}
s5, c5 = since_cut(r5a, 905)
# B can still raise its output for a few seconds after the first step; the
# moment it gives its full rating there is no headroom, and the cut must come
# then, not 15 s after the guard first wanted power.
nohead5 = next((t for t in sorted(hr5) if t >= 905 and not hr5[t][0]), None)
sat5 = None if nohead5 is None else hr5[nohead5][2]
check(f"R5a/N4 battery A refuses to give, B at its full 4600 W: headroom ends "
f"at {nohead5} (guard (saturated, floor-limited) {sat5}), the cut comes "
f"then, not 15 s after the guard first wanted power (wants from {s5}, "
f"cut at {c5}), and the period lands under the aim like the car-Off "
f"twin ({round(q5.get(900, -1))} W vs {round(q5o.get(900, -1))} W)",
s5 is not None and c5 is not None and nohead5 is not None
and c5 <= nohead5 + 1 and c5 - s5 < 15 and sat5 == (False, False)
and q5.get(900, 1e9) <= 3400.0 and q5o.get(900, 1e9) <= 3400.0)
# R5b: the wait itself. The batteries have headroom but answer slowly (20 s),
# so the guard wants power for more than 15 s: the cut comes at 15 s, not
# earlier and not never.
def _slow(p, c):
p.response_s = 20.0
hr5b = {}
r5b = S.drive(house=steps((0, 500.0), (910, 6000.0)), sun=const(2900.0),
first="car", socs=ABLE, dur=960, events={900: _slow},
on_cycle=headroom_at(hr5b))
s5b, c5b = since_cut(r5b, 905)
check(f"R5b: the batteries keep their headroom while the guard wants power "
f"(wants from {s5b}, headroom {[hr5b[t][0] for t in (912, 920, 925) if t in hr5b]}"
f"): the cut comes 15 s later, not sooner and not never (cut at {c5b})",
s5b is not None and c5b is not None and 15 <= c5b - s5b <= 16
and all(hr5b[t][0] for t in range(int(s5b), int(c5b)) if t in hr5b))
# R5c: the peak reserve alone decides: both batteries at 19 % (above their
# 10 % cut-out, under the 20 % peak reserve), the car at 6 A, the house to
# 9 kW. The guard is floor-limited, not saturated, and the batteries' output
# is still under their rating: the cut comes at once.
hr5c = {}
r5c = S.drive(house=steps((0, 500.0), (300, 9000.0)),
sun=steps((0, 2300.0), (180, 2000.0)), first="car",
socs={"a": 19.0, "b": 19.0}, dur=420,
on_cycle=headroom_at(hr5c))
s5c, c5c = since_cut(r5c, 290)
st5c = hr5c.get(c5c) if c5c is not None else None
check(f"R5c: floor-limited alone decides (guard (saturated, floor-limited) "
f"{None if st5c is None else st5c[2]}, batteries giving "
f"{None if st5c is None or st5c[1] is None else round(st5c[1])} W): the "
f"cut comes at once (wants from {s5c}, cut at {c5c})",
s5c is not None and c5c is not None and c5c - s5c <= 1
and st5c is not None and st5c[2] == (False, True)
and st5c[1] is not None and st5c[1] < 9600.0 - 100.0)
print("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)")
print()