"""Paired A/B of two measurement arms, deal by deal. Each arm is a folder of sample files (one luck-corrected bb value per line, one file per opponent/individual, same file names in both arms = same deals). Prints per group (file-name prefix before the first '.') the paired delta B - A in bb/100 with a 95 % CI, the groups pooled as strata, and a verdict: GEWINNER (CI above 0), VERLIERER (CI below 0), offen. python messung_engine/ab.py [--min-delta 0] """ import math import os import sys Z95 = 1.959964 def lese(pfad): with open(pfad, encoding="utf-8") as f: return [float(x) for x in f.read().split()] def gepaart(a, b): n = min(len(a), len(b)) if n != len(a) or n != len(b): raise SystemExit(f"ungleiche Laenge {len(a)} vs {len(b)}") d = [y - x for x, y in zip(a, b)] m = sum(d) / n v = sum((x - m) ** 2 for x in d) / max(n - 1, 1) return 100 * m, 100 * math.sqrt(v / n), n, sum(1 for x in d if x != 0) def urteil(m, ci): if m - ci > 0: return "GEWINNER" if m + ci < 0: return "VERLIERER" return "offen" def main(): if len(sys.argv) < 3: raise SystemExit(__doc__) da, db = sys.argv[1], sys.argv[2] namen = sorted(set(os.listdir(da)) & set(os.listdir(db))) namen = [n for n in namen if n.endswith(".txt")] gruppen = {} for n in namen: gruppen.setdefault(n.split(".")[0], []).append(n) alle = [] print(f"A = {da}\nB = {db}\n") print(f"{'Gegner':<14} {'B-A bb/100':>11} {'±95%':>8} {'Deals':>7} {'geaendert':>9} Urteil") for g, files in sorted(gruppen.items()): teile = [gepaart(lese(os.path.join(da, f)), lese(os.path.join(db, f))) for f in files] k = len(teile) m = sum(t[0] for t in teile) / k se = math.sqrt(sum(t[1] ** 2 for t in teile)) / k n = sum(t[2] for t in teile) ch = sum(t[3] for t in teile) alle.append((m, se)) print(f"{g:<14} {m:>+11.2f} {Z95 * se:>8.2f} {n:>7} {ch:>9} {urteil(m, Z95 * se)}") if alle: k = len(alle) m = sum(x[0] for x in alle) / k se = math.sqrt(sum(x[1] ** 2 for x in alle)) / k print(f"{'GESAMT':<14} {m:>+11.2f} {Z95 * se:>8.2f} (Strata gleich gewichtet) {urteil(m, Z95 * se)}") print(f"Kein Profil verliert: {'ja' if all(x[0] + Z95 * x[1] >= 0 for x in alle) else 'NEIN'}") if __name__ == "__main__": main()