diff --git a/messung/farm/bitgleich/bg_basis.py b/messung/farm/bitgleich/bg_basis.py index d58ef199..b83398ea 100644 --- a/messung/farm/bitgleich/bg_basis.py +++ b/messung/farm/bitgleich/bg_basis.py @@ -81,7 +81,21 @@ def masse(z, k): return z.get("masse") if v is None else v # mehrweg 06.12. (ab Merge 10): basis.action/size ist der Zug NACH der Basis-Regel, der Zug davor steht in basis.vor_regel; # die endpruefung traegt kein "A Basis" mehr. Hat ein Stand irgendwo vor_regel, gilt die neue Lesart fuer alle Zeilen. -NEUE_LESART = any(isinstance(c[i].get("basis"), dict) and "vor_regel" in c[i]["basis"] for i in c) +# Lesart am Commit festmachen (mehrweg 06.12.): VOR_REGEL_AB = Merge 10; Arm C aus auftrag.json ist Nachfahre -> neu. BG_LESART=neu|alt erzwingt. +# Ohne Commit-Angabe: neu, sobald eine Zeile basis.vor_regel hat (ein neuer Stand ohne jeden Regelwechsel faellt dann in die alte Lesart). +VOR_REGEL_AB = "" # Hash folgt von mehrweg +def lesart_aus_commit(): + if os.environ.get("BG_LESART") in ("neu", "alt"): return os.environ["BG_LESART"] == "neu", "BG_LESART" + try: arme = {a[0]: a[2] for a in json.load(open(os.path.join(O, "auftrag.json")))["arme"]} + except (OSError, ValueError, KeyError): return None, "kein auftrag.json" + if not VOR_REGEL_AB or C not in arme: return None, "kein VOR_REGEL_AB" + import subprocess + r = subprocess.run(["git", "-C", "/Users/marcmintel/Projects/pokerfreak", "merge-base", "--is-ancestor", VOR_REGEL_AB, arme[C]], capture_output=True) + if r.returncode not in (0, 1): sys.exit(f"Lesart: git merge-base scheitert ({r.stderr.decode()[:200]}) - Abbruch") + return r.returncode == 0, f"Commit {arme[C][:9]} {'enthaelt' if r.returncode == 0 else 'ohne'} {VOR_REGEL_AB[:9]}" +NEUE_LESART, LESART_GRUND = lesart_aus_commit() +if NEUE_LESART is None: + NEUE_LESART = any(isinstance(c[i].get("basis"), dict) and "vor_regel" in c[i]["basis"] for i in c); LESART_GRUND += ", vor_regel " + ("gefunden" if NEUE_LESART else "nirgends") def regel1_befunde(bas, q): """Neue Lesart, Regel 1: hat die Basis-Regel den Zug geaendert (vor_regel vorhanden), muss vor_regel != basis sein und der Zug basis Masse gewonnen haben.""" vr = bas.get("vor_regel") if isinstance(bas, dict) else None @@ -159,7 +173,7 @@ if any(isinstance(c[i].get("basis"), dict) for i in c): if NEUE_LESART: W = sum(1 for i in c if isinstance(c[i].get("basis"), dict) and isinstance(c[i]["basis"].get("vor_regel"), dict) and zug(c[i]["basis"]["vor_regel"]) != zug(c[i]["basis"])) else: W = sum(1 for x in streicht if tv(c[x["zeile"]].get("basis")) is not None and basis_regel(x["zeile"])) # nur Wechsel der Basis-Regel (Art "A Basis") regel1 = [{"zeile": i, "strasse": st[i], "basis": zug(c[i]["basis"]), "vor_regel": zug(c[i]["basis"]["vor_regel"]), "befunde": r} for i in sorted(c) - if isinstance(c[i].get("basis"), dict) and isinstance(c[i]["basis"].get("vor_regel"), dict) for r in [regel1_befunde(c[i]["basis"], ANF[i])] if r] + if isinstance(c[i].get("basis"), dict) and isinstance(c[i]["basis"].get("vor_regel"), dict) for r in [regel1_befunde(c[i]["basis"], ANF[i])] if r] if NEUE_LESART else [] grenze = E + 3 * math.sqrt(E) + 1 summe = {"zeilen_mit_sicherheit": sum(1 for t in tvs if t is not None), "erwartet_E": round(E, 6), "beobachtet_W": W, "grenze": round(grenze, 6), "befund": W > grenze} # weder Endpruefungs- noch Probe-Strich: echter Befund # aus-Lauf: ausser der endpruefung kein Protokolleintrag (Tor 10 e) @@ -175,7 +189,7 @@ if any(isinstance(c[i].get("basis"), dict) for i in c): "ohne_basis_feld": dict(ohne), "bestanden_uebrige": not abw and not ohne, "summenpruefung_basis_regel": summe, - "lesart": "neu (basis nach der Regel, vor_regel)" if NEUE_LESART else "alt (Art A Basis in der endpruefung)", + "lesart": ("neu (basis nach der Regel, vor_regel; jeder Strich Veto)" if NEUE_LESART else "alt (Art A Basis in der endpruefung)") + " | " + LESART_GRUND, "basis_regel_wechsel": W if NEUE_LESART else None, "regel1_befunde": len(regel1), "liste_regel1_befunde": regel1[:50], "strich_befunde": len(strich_falsch), "liste_strich_befunde": [{"zeile": x["zeile"], "strasse": x["strasse"], "basis": x["basis"], "endzug": x["endzug"], "befunde": x["strich_befunde"]} for x in strich_falsch], "bestanden": not abw and not ohne and not offen and not fremd and not strich_falsch and not regel1 and not summe["befund"],