Farm: Bitgleich-Vergleich zaehlt zusaetzlich Abweichungen ohne Rundungsrauschen (12 Stellen)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Marc Mintel
2026-12-05 21:36:41 +01:00
co-authored by Claude Opus 5.5
parent 73a42a410e
commit c83a496047
+10 -3
View File
@@ -4,6 +4,12 @@
import json, os, re, sys, collections
O, N, EIN, ARME = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4:]
MS = re.compile(r"\d+(\.\d+)?\s?ms")
def rund(o):
"""Gleitkomma auf 12 gueltige Stellen (Rundungsrauschen aus der Summierreihenfolge, z. B. linie[].d in der 15. Stelle)."""
if isinstance(o, float): return float("%.12g" % o)
if isinstance(o, dict): return {k: rund(v) for k, v in o.items()}
if isinstance(o, list): return [rund(v) for v in o]
return o
def ohne(o):
if isinstance(o, dict): return {k: ohne(v) for k, v in o.items() if not (k == "ms" or k.endswith("_ms") or k == "timing" or k.startswith("zeit"))}
if isinstance(o, list): return [ohne(v) for v in o]
@@ -11,7 +17,7 @@ def ohne(o):
return o
st = [json.loads(z)["street"] for z in open(EIN, encoding="utf-8")]
def vergleiche(A, B, ERG):
n, anders, zug, bsp = collections.Counter(), collections.Counter(), collections.Counter(), []
n, anders, zug, bsp, anders12 = collections.Counter(), collections.Counter(), collections.Counter(), [], collections.Counter()
for t in range(N):
ka = json.load(open(os.path.join(A, f"teil{t}.jsonl.kopf.json")))
a = [json.loads(z) for z in open(os.path.join(A, f"teil{t}.jsonl"), encoding="utf-8") if z.strip()]
@@ -21,11 +27,12 @@ def vergleiche(A, B, ERG):
i = ka["idx"][j]; s = st[i]; n[s] += 1
if ohne(x) != ohne(y):
anders[s] += 1
if rund(ohne(x)) != rund(ohne(y)): anders12[s] += 1
if (x.get("action"), x.get("size")) != (y.get("action"), y.get("size")): zug[s] += 1
if len(bsp) < 20: bsp.append({"zeile": i, "strasse": s, "A": str(x.get("reason"))[:200], "B": str(y.get("reason"))[:200], "A_zug": [x.get("action"), x.get("size")], "B_zug": [y.get("action"), y.get("size")]})
erg = {"anfragen": dict(n), "anders": dict(anders), "anders_zug_oder_groesse": dict(zug), "bitgleich": sum(anders.values()) == 0, "beispiele": bsp}
erg = {"anfragen": dict(n), "anders": dict(anders), "anders_ohne_rundungsrauschen_12stellen": dict(anders12), "anders_zug_oder_groesse": dict(zug), "bitgleich": sum(anders.values()) == 0, "beispiele": bsp}
json.dump(erg, open(ERG + ".tmp", "w"), ensure_ascii=False, indent=1); os.replace(ERG + ".tmp", ERG)
print(json.dumps({k: erg[k] for k in ("anfragen", "anders", "anders_zug_oder_groesse", "bitgleich")}, ensure_ascii=False))
print(json.dumps({k: erg[k] for k in ("anfragen", "anders", "anders_ohne_rundungsrauschen_12stellen", "anders_zug_oder_groesse", "bitgleich")}, ensure_ascii=False))
return erg
for arm in ARME[1:]:
print(arm, end=": ")