From 35d51370672264bf3558ba85cbb06cc7e783b2c2 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sat, 28 Nov 2026 13:50:54 +0100 Subject: [PATCH] exakt6: EXAKT_TEIL=i/n teilt die gekippten Haende auf mehrere Prozesse (eigene Teildateien, der Lauf ohne Teil zaehlt sie als fertig und schreibt das Ergebnis) Co-Authored-By: Claude Opus 5.5 --- messung/motor/pruef6/sharingan/exakt6.py | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/messung/motor/pruef6/sharingan/exakt6.py b/messung/motor/pruef6/sharingan/exakt6.py index e20abcce..befe9ef3 100644 --- a/messung/motor/pruef6/sharingan/exakt6.py +++ b/messung/motor/pruef6/sharingan/exakt6.py @@ -76,6 +76,10 @@ def frage(p, a): T.frage = frage +def glob_escape(p): + return __import__("glob").escape(p) + + def lade(p): return {(x["blatt"], x["dreh"]): x for x in map(json.loads, open(p, encoding="utf-8"))} @@ -160,25 +164,41 @@ def main(): name = os.path.basename(fv).split("--")[-1].replace(".jsonl", "") os.makedirs(os.path.join(HIER, "daten", "exakt"), exist_ok=True) roh = os.path.join(HIER, "daten", "exakt", "%s--%s--%s.jsonl" % (zelle, os.path.basename(fv).split("--")[1], name)) + # Teile (28.11.): EXAKT_TEIL="i/n" rechnet nur jede n-te gekippte Hand ab i, in eine eigene Datei .teil.jsonl + # (mehrere Prozesse ohne gemeinsames Schreiben). Ohne EXAKT_TEIL zaehlen alle Teildateien als fertig; der Lauf ohne Teil + # rechnet den Rest und schreibt das Ergebnis. + teil = os.environ.get("EXAKT_TEIL") + if teil: + ti, tn = map(int, teil.split("/")) + behalten = set(sorted(fv_k)[ti::tn]) + fv_k = {h: w for h, w in fv_k.items() if h in behalten} + fb_k = {h: w for h, w in fb_k.items() if h in behalten} + ziel = roh[:-6] + ".teil%d.jsonl" % ti if teil else roh fertig = {} - if os.path.exists(roh): - for zl in open(roh, encoding="utf-8"): + for q in [roh] + sorted(__import__("glob").glob(glob_escape(roh[:-6]) + ".teil*.jsonl")): + if not os.path.exists(q): + continue + for zl in open(q, encoding="utf-8"): try: z = json.loads(zl) fertig[(z["seite"], z["blatt"], z["dreh"])] = z except ValueError: pass - with open(roh, "rb") as f: + if os.path.exists(ziel): + with open(ziel, "rb") as f: ende = f.read()[-1:] if ende and ende != b"\n": # halbe letzte Zeile (Platte voll / abgebrochen): abschliessen, nichts kuerzen - with open(roh, "ab") as f: + with open(ziel, "ab") as f: f.write(b"\n") - datei = open(roh, "a", encoding="utf-8") + datei = open(ziel, "a", encoding="utf-8") aus = {"datei": datei, "fertig": fertig} print("Blaetter %d, Haende %d, gekippt %d" % (len(blaetter), len(blaetter) * n, len(fv_k)), flush=True) seite(ev_, envv, fv_k, zelle, K, aus, "var") seite(eb, envb, fb_k, zelle, K, aus, "basis") - je = {b: 0.0 for b in blaetter} + if teil: + print("TEIL fertig", teil, flush=True) + return + je ={b: 0.0 for b in blaetter} ok = gesamt = vor_ok = 0 se2 = 0.0 for (b, dreh) in fv_k: