From 9e74041b576b2b09679c4f81e23e44a192ce0f29 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Fri, 4 Dec 2026 13:24:53 +0100 Subject: [PATCH] Tor-1-Belege fuer basis-rein je Spieltag (summe, abweichungen-B, urteile) nach werkzeuge/fassung_tor.py Co-Authored-By: Claude Opus 5.5 --- messung/motor/paket/tor1_belege.py | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 messung/motor/paket/tor1_belege.py diff --git a/messung/motor/paket/tor1_belege.py b/messung/motor/paket/tor1_belege.py new file mode 100644 index 00000000..4faac1c9 --- /dev/null +++ b/messung/motor/paket/tor1_belege.py @@ -0,0 +1,88 @@ +"""Tor-1-Belege (werkzeuge/fassung_tor.py) fuer basis-rein je Spieltag: summe.json, abweichungen-B.json, urteile.json. + +Arm A = Wiedergabe der Live-Basis 331206FA (Quelle claude/basis-2511 7e0a2221, dieselbe Linie ohne jeden Schalter, Gegnerzaehler eingefroren) +gegen das Live-Log; Arm B = basis-rein (R0, volle Zeile) aus dem Nachweislauf. Abweichung = B-Antwort (Aktion, Groesse) anders als die +geloggte Live-Basis; Id = Index der Anfrage in pruefstand/basis-rein/ein.jsonl. Urteile nach den Regeln der Hauptsession (gelesen 04.12.): + Regel weg -> gut "Loeser-Zug statt NL2-Regel (reine Basis, Owner 04.12.)" + Rechnung (Turn/River exakt, Vorflop-Tafel, Preis-Weg, Flop exakt, Tafel) -> gut "Rechnung: Rake/Uebersetzung/Ziehung bzw. exakt geloest" + Einzelfall Hand 190375000008 River (KdQc All-in aus 28 %) -> vertretbar "Loeser-Mischung, beobachten" +ungueltig = Antwort fehlt oder Aktion nicht in legalActions; abstuerze_fehler = Antworten mit Fehlerfeld bzw. fehlende Zeilen am Ende. +Aufruf: python3 tor1_belege.py ... +""" +import sys + +sys.dont_write_bytecode = True + +import json # noqa: E402 +import os # noqa: E402 +import re # noqa: E402 + +REGEL = re.compile(r"(NL2-[A-Za-z-]+|\[Vorflop-All-in|river-wert|Jam-Probe|Schwachjam-Sperre)") +GUT_REGEL = "Löser-Zug statt NL2-Regel (reine Basis, Owner 04.12.)" +GUT_RECHNUNG = "Rechnung: Rake/Übersetzung/Ziehung bzw. exakt gelöst" +EINZEL = {("190375000008", "RIVER"): ("vertretbar", "Löser-Mischung, beobachten")} + + +def k(a): + return (a.get("action"), a.get("size")) + + +def zaehle_lauf(qs, aus): + ungueltig = sum(1 for q, o in zip(qs, aus) if o.get("action") not in (q.get("legalActions") or [])) + fehler = sum(1 for o in aus if "error" in o or "fehler" in o) + max(0, len(qs) - len(aus)) + return {"ungueltig": ungueltig, "abstuerze_fehler": fehler} + + +def schreibe(pfad, inhalt): + if os.path.exists(pfad): + raise SystemExit(f"{pfad} existiert schon") + with open(pfad + ".tmp", "x") as f: + json.dump(inhalt, f, ensure_ascii=False, indent=1) + os.rename(pfad + ".tmp", pfad) + + +def main(): + d, tage = sys.argv[1], sys.argv[2:] + E = open(os.path.join(d, "ein.jsonl")).read().splitlines() + R = [json.loads(z) for z in open(os.path.join(d, "ref.jsonl"))] + B = [] + for t in range(5): + B += [json.loads(z) for z in open(os.path.join(d, f"aus{t}.jsonl"))] + for tag in tage: + idx = [int(x) for x in open(os.path.join(d, "tor1", f"idx-{tag}.txt")).read().split()] + A = [] + t = 0 + while os.path.exists(os.path.join(d, "tor1", f"aus-A-{tag}-{t}.jsonl")): + A += [json.loads(z) for z in open(os.path.join(d, "tor1", f"aus-A-{tag}-{t}.jsonl"))] + t += 1 + qs = [json.loads(E[i]) for i in idx] + summe = {"anfragen": len(idx), "lauf": {"A": zaehle_lauf(qs, A), "B": zaehle_lauf(qs, [B[i] for i in idx])}, + "A_wiedergabe": {"n": len(A), "aktion_gleich": sum(1 for i, a in zip(idx, A) if a.get("action") == R[i]["motor"].get("action")), + "aktion_und_groesse_gleich": sum(1 for i, a in zip(idx, A) if k(a) == k(R[i]["motor"]))}, + "quelle": {"A": "claude/basis-2511-Linie ohne Schalter (= Quelle der Live-Basis 331206FA), Gegnerzaehler eingefroren", + "B": "basis-rein 807e7a4e, R0=1 mit voller Teil-3-Zeile"}} + liste, urteile = [], {} + for i in idx: + b, alt = B[i], R[i]["motor"] + if k(b) == k(alt): + continue + q = json.loads(E[i]) + weg = REGEL.search(str(alt.get("reason") or "")) + art = f"Regel weg: {weg.group(1).strip('[')}" if weg else "Rechnung" + h = str(R[i]["hand"]) + liste.append({"id": i, "hand": h, "strasse": q["street"], "alt": f"{alt.get('action')} {alt.get('size')}", + "neu": f"{b.get('action')} {b.get('size')}", "art": art}) + u, g = EINZEL.get((h, q["street"]), ("gut", GUT_REGEL if weg else GUT_RECHNUNG)) + urteile[str(i)] = {"urteil": u, "grund": g, "gelesen_von": "Hauptsession"} + ziel = os.path.join(d, "tor1", tag) + os.makedirs(ziel, exist_ok=True) + schreibe(os.path.join(ziel, "summe.json"), summe) + schreibe(os.path.join(ziel, "abweichungen-B.json"), liste) + schreibe(os.path.join(ziel, "urteile.json"), urteile) + w = summe["A_wiedergabe"] + print(tag, json.dumps(summe["lauf"]), f"A-Wiedergabe {w['aktion_und_groesse_gleich']}/{w['n']} = {100 * w['aktion_und_groesse_gleich'] / max(w['n'], 1):.2f} %", + f"Abweichungen B {len(liste)}", "vertretbar:", [x for x, e in urteile.items() if e['urteil'] != 'gut']) + + +if __name__ == "__main__": + main()