Files
BT411/scratchpad/night17/seek21_check.py
T

69 lines
2.9 KiB
Python

# #21 correction bench checker -- see seek21_bench.sh for the PASS contract.
import io, re, sys
path = sys.argv[1] if len(sys.argv) > 1 else "/c/git/bt411/content/sk21.log"
L = io.open(path, encoding="latin-1", errors="replace").read().splitlines()
# Emitter gear-switch lines (Myomers [seek] lines lack "seekV["):
# [seek] NAME -> gear N seekV[N]=X table={...} max=M level=L genV=...
gear_re = re.compile(
r"\[seek\] (\S+) -> gear (\d+) seekV\[\d+\]=([-\d.eE+]+) .*level=([-\d.eE+]+)")
gears = [] # (line_idx, name, gear, seekV, level)
for i, l in enumerate(L):
m = gear_re.search(l)
if m:
gears.append((i, m.group(1), int(m.group(2)),
float(m.group(3)), float(m.group(4))))
names = sorted(set(g[1] for g in gears))
print("=== #21 CORRECTION BENCH (faithful overcharge clamp) ===")
print("weapon(s) under seek cycling:", names or "NONE")
ok = True
if not gears:
print("FAIL: no emitter [seek] gear lines -- rig broken (expert gate? seektest?)")
ok = False
for name in names:
G = [g for g in gears if g[1] == name]
wraps = sum(1 for a, b in zip(G, G[1:]) if b[2] < a[2])
over = [g for g in G if g[3] > 0.0 and g[4] > 1.01 * g[3]]
fired_all = [i for i, l in enumerate(L) if ("FIRED '%s'" % name) in l]
last_over = over[-1][0] if over else None
fired_after = ([i for i in fired_all if i > last_over]
if last_over is not None else [])
# gauge source: [fire-probe] NAME ... pct=1 after the last overcharge
pct1_after = 0
if last_over is not None:
pr = re.compile(r"\[fire-probe\] %s .*pct=([-\d.eE+]+)" % re.escape(name))
for l in L[last_over:]:
m = pr.search(l)
if m and float(m.group(1)) >= 0.999:
pct1_after += 1
# tail liveness: still firing in the last 25% of the run
tail = int(len(L) * 0.75)
fired_tail = sum(1 for i in fired_all if i >= tail)
print("-- %s: gearSwitches=%d wraps=%d overchargeEvents=%d "
"FIRED total=%d afterLastOver=%d pct=1 probes after=%d tailFIRED=%d"
% (name, len(G), wraps, len(over), len(fired_all),
len(fired_after), pct1_after, fired_tail))
if wraps < 1:
ok = False; print("FAIL(%s): no wrap past top gear" % name)
if not over:
ok = False; print("FAIL(%s): no overcharge composition ever formed" % name)
if last_over is not None and not fired_after:
ok = False; print("FAIL(%s): NEVER FIRED after the last overcharge -- dark state" % name)
if last_over is not None and pct1_after < 1:
ok = False; print("FAIL(%s): recharge gauge (pct) never read full after overcharge" % name)
if fired_tail < 1:
ok = False; print("FAIL(%s): not firing in the run tail -- possible late brick" % name)
rescues = sum(1 for l in L if "rescue" in l)
print("rescue prints in log:", rescues)
if rescues != 0:
ok = False; print("FAIL: rescue print still present")
print("RESULT:", "PASS" if ok else "FAIL")