#!/usr/bin/env python3 """Turn chaos/round-NN.json into the findings doc's round table (the five things + the readback).""" import glob, json, re def short(x, n=160): x = re.sub(r"\s+", " ", str(x or "")).strip() return (x[:n] + "…") if len(x) > n else x rows = [] for p in sorted(glob.glob("chaos/round-[0-9][0-9].json")): r = json.load(open(p)) after = r.get("after") or {} st = after.get("state") or {} b = after.get("badges") or {} lines = after.get("lines") or {} saw = [] for lang in ("hu", "en"): bb = "; ".join(x.get("text", "") for x in (b.get(lang) or [])) ln = (lines.get(lang) or {}) extra = ln.get("undone_line") or ln.get("hold") or "" saw.append(f"{lang}: {bb or '—'}{(' / ' + short(extra, 110)) if extra else ''}") if not st and after.get("state") == "not deployed": saw = [f"not installed (leftovers: {after.get('leftovers') or 'none'})"] phases = " → ".join(f"{ph[1]}@{ph[0]}s" for ph in (r.get("phases") or [])) boxdid = phases or short(r.get("act"), 120) keylog = [l for l in (r.get("box_log") or []) if re.search(r"recovery|UNDO|UNDONE|HOLD|held|refus|interrupted|restore", l)] if keylog: boxdid += " | " + short(keylog[-1][21:], 140) rb = r.get("readback") if r.get("readback_B_reread") is not None: rb = dict(rb or {}); rb["B"] = f"{r['readback_B_reread']['value']} (re-read, paged)" rows.append(f"| {r['round']} | {r['action']} · {r['app']} | {short(r.get('accident'), 110)} (armed {r.get('armed_at','at start')}) | " f"{' ‖ '.join(saw)} | {boxdid} | {r.get('time_to_steady_s')} s | " f"{', '.join(e.split(' ', 1)[1] for e in (r.get('events') or [])) or 'none'} | {rb} |") print("| # | action · app | accident (when) | what the household saw | what the box did by itself | steady | events fired (R-620 witness) | data read back |") print("|---|---|---|---|---|---|---|---|") print("\n".join(rows))