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 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 13:50:54 +01:00
co-authored by Claude Opus 5.5
parent eec4956f8c
commit 35d5137067
+26 -6
View File
@@ -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 <roh>.teil<i>.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: