vorflop_selbst: real VSELBS02 sidecar reader, archive list from the motor rows (TSV on the SSD, sums only in the repo), direction per decision, spec
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
"""Archive list of the self-consistency sidecar: rows per changed decision, TSV, summary numbers (pure, no I/O).
|
||||
|
||||
Input: rows of `vorflop-selbst-archiv` (changed decisions: key, class, action names, roles, pi_alt, pi_neu, values V with covariance, R, R_se, w, reach, played move,
|
||||
line index `i`) and the archive description per line index (`entscheidungen.jsonl`: pos, linie, spieler, sonder). Output carries no player or hand IDs, no line indices.
|
||||
"""
|
||||
import collections
|
||||
|
||||
import wert as W
|
||||
|
||||
SPALTEN = ["linie", "position", "spieler", "sonder", "knoten", "klasse", "gespielt", "alt", "neu", "richtung", "R", "R_se", "R_untere95", "w", "erreichbarkeit", "erreich_x_R"]
|
||||
RICHTUNGEN = ("MehrJam", "MehrFold", "Sonstige", "Unveraendert")
|
||||
|
||||
|
||||
def mischung_text(mischung):
|
||||
return ", ".join("%s %.0f%%" % (a, 100 * p) for a, p in mischung.items() if p > 0.0005)
|
||||
|
||||
|
||||
def entscheidungszeilen(roh, beschreibung):
|
||||
"""Per changed decision one dict; `beschreibung`: {line index: {pos, linie, spieler, sonder}}."""
|
||||
out = []
|
||||
for r in roh:
|
||||
b = beschreibung[r["i"]]
|
||||
namen = r["namen"]
|
||||
pi_alt, pi_neu = dict(zip(namen, r["pi_alt"])), dict(zip(namen, r["pi_neu"]))
|
||||
rollen = dict(zip(namen, r["rollen"]))
|
||||
richt, sh = W.richtung_zeile(rollen, pi_alt, pi_neu)
|
||||
cov = {a: {c: r["cov"][i][j] for j, c in enumerate(namen)} for i, a in enumerate(namen)}
|
||||
out.append({"linie": b["linie"], "pos": b["pos"], "spieler": b["spieler"], "sonder": b["sonder"], "key": r["key"], "klasse": r["klasse"],
|
||||
"klasse_name": r["klasse_name"], "erreich": r["erreich"], "pi_alt": pi_alt, "pi_neu": pi_neu, "V": dict(zip(namen, r["V"])), "cov": cov,
|
||||
"R": r["R"], "R_se": r["R_se"], "R_lo": W.untere_grenze(r["R"], r["R_se"]), "w": r["w"], "gespielt": r["gespielt"],
|
||||
"richtung": richt, "shifts": sh, "erreich_x_R": r["erreich"] * r["R"]})
|
||||
return out
|
||||
|
||||
|
||||
def wertzeilen(zeilen):
|
||||
"""Unique cells (node, class, line, position) with frequency n and value without dice; the same cell shares one estimate."""
|
||||
zellen = collections.OrderedDict()
|
||||
for z in zeilen:
|
||||
k = (z["key"], z["klasse"], z["linie"], z["pos"])
|
||||
zellen.setdefault(k, dict(z, n=0))["n"] += 1
|
||||
out = []
|
||||
for z in zellen.values():
|
||||
r = W.zeile(dict(z, se_V=None))
|
||||
if r:
|
||||
r["lp"] = "%s|%s" % (z["linie"], z["pos"])
|
||||
out.append(r)
|
||||
return W.sortiert(out)
|
||||
|
||||
|
||||
def tsv(zeilen):
|
||||
"""TSV text, sorted by reach x R (descending), one line per changed decision."""
|
||||
kopf = "\t".join(SPALTEN)
|
||||
zs = sorted(zeilen, key=lambda z: (-z["erreich_x_R"], z["key"], z["klasse"]))
|
||||
t = [kopf]
|
||||
for z in zs:
|
||||
t.append("\t".join([z["linie"], z["pos"], str(z["spieler"]), ",".join(z["sonder"]) or "-", z["key"], z["klasse_name"], z["gespielt"] or "-",
|
||||
mischung_text(z["pi_alt"]), mischung_text(z["pi_neu"]), z["richtung"], "%.3f" % z["R"], "%.3f" % z["R_se"], "%.3f" % z["R_lo"],
|
||||
"%.2f" % z["w"], "%.5f" % z["erreich"], "%.5f" % z["erreich_x_R"]]))
|
||||
return "\n".join(t) + "\n"
|
||||
|
||||
|
||||
def zaehlen_je(zeilen, schluessel):
|
||||
c = collections.Counter(schluessel(z) for z in zeilen)
|
||||
return c
|
||||
|
||||
|
||||
def markdown(zeilen, zaehlung, kopf, top=20, gezaehlt=None):
|
||||
"""AENDERUNGEN.md: counts per direction, line and position with value and interval; the `top` largest single changes (reach x R)."""
|
||||
haende, entsch = zaehlung["haende"], zaehlung["entscheidungen"]
|
||||
cells = wertzeilen(zeilen)
|
||||
s = W.summen(cells, entsch, haende)
|
||||
t = ["# Vorflop-selbst: Aenderungen an den Preflop-Entscheidungen des Archivs", "", kopf, ""]
|
||||
if gezaehlt:
|
||||
t += ["Archiv-Durchlauf des Dienstes: " + ", ".join("%s: %d" % (k, v) for k, v in gezaehlt.items()), ""]
|
||||
t += ["Entscheidungen im Archiv: %d, davon geaendert: %d (%.1f %%), verschiedene (Knoten, Klasse, Lage): %d. Wert ohne Wuerfel (Summe (pi' - pi) V mit V der Suchfortsetzung): "
|
||||
"%+.2f bb/100 Haende [%+.2f; %+.2f] (95 %%)." % (entsch, len(zeilen), 100.0 * len(zeilen) / max(entsch, 1), len(cells), s["wert_bb_pro_100"], s["lo_bb_pro_100"], s["hi_bb_pro_100"]), ""]
|
||||
# direction
|
||||
t += ["## Richtung", "", "| Richtung | Entscheidungen | verschiedene | Wert bb/100 [95 %] |", "|---|---|---|---|"]
|
||||
for r in RICHTUNGEN:
|
||||
zz = [z for z in zeilen if z["richtung"] == r]
|
||||
cc = [c for c in cells if c["richtung"] == r]
|
||||
v = W.summen(cc, len(zz), haende) if cc else None
|
||||
t.append("| %s | %d | %d | %s |" % (r, len(zz), len(cc), "%+.2f [%+.2f; %+.2f]" % (v["wert_bb_pro_100"], v["lo_bb_pro_100"], v["hi_bb_pro_100"]) if v else "-"))
|
||||
t += ["", "Richtung = die Rolle (Fold, Jam, Call/Raise) mit der groessten positiven Netto-Verschiebung der Entscheidung.", ""]
|
||||
for titel, schl, denom in (("Je Linie", "linie", zaehlung["je_linie"]), ("Je Linie und Position", "lp", zaehlung["je_linie_position"])):
|
||||
je = W.summen_je(cells, schl, denom, haende)
|
||||
t += ["## " + titel, "", "| %s | Entscheidungen | geaendert | Jam mehr | Fold mehr | sonstige | Wert bb/100 [95 %%] |" % ("Linie" if schl == "linie" else "Linie, Position"), "|---|---|---|---|---|---|---|"]
|
||||
for g, v in je.items():
|
||||
zz = [z for z in zeilen if (z["linie"] if schl == "linie" else "%s|%s" % (z["linie"], z["pos"])) == g]
|
||||
c = collections.Counter(z["richtung"] for z in zz)
|
||||
t.append("| %s | %d | %d | %d | %d | %d | %+.2f [%+.2f; %+.2f] |" % (g, v["entscheidungen"], len(zz), c["MehrJam"], c["MehrFold"], c["Sonstige"] + c["Unveraendert"], v["wert_bb_pro_100"], v["lo_bb_pro_100"], v["hi_bb_pro_100"]))
|
||||
t.append("")
|
||||
t += ["## Die %d groessten Einzelaenderungen (Erreichbarkeit x R)" % top, ""]
|
||||
for i, z in enumerate(sorted(zeilen, key=lambda z: (-z["erreich_x_R"], z["key"], z["klasse"]))[:top]):
|
||||
t.append("%d. %s, %s, %d Spieler%s, Klasse %s, Knoten %s: Tafel %s -> neu %s; gespielt %s; R %.2f +- %.2f bb (untere 95-%%-Grenze %.2f), w %.2f, Erreichbarkeit %.4f; Richtung %s." % (
|
||||
i + 1, z["linie"], z["pos"], z["spieler"], (", " + "/".join(z["sonder"])) if z["sonder"] else "", z["klasse_name"], z["key"][:8], mischung_text(z["pi_alt"]), mischung_text(z["pi_neu"]),
|
||||
z["gespielt"] or "-", z["R"], z["R_se"], z["R_lo"], z["w"], z["erreich"], z["richtung"]))
|
||||
return "\n".join(t) + "\n"
|
||||
@@ -1,43 +1,65 @@
|
||||
"""Reader for the MOTOR_VORFLOP_SELBST sidecar and for the reason mark - ISOLATED because the real format is still unknown.
|
||||
"""Reader for the MOTOR_VORFLOP_SELBST sidecar (format VSELBS02, written by `vorflop-selbst-bauen`; description: docs/vorflop_selbst.md in claude/vorflop-selbst-2).
|
||||
|
||||
STUB FORMAT (replace `lade`/`parse_marke` once the other branch (claude/vorflop-selbst) documents the real one):
|
||||
sidecar JSON: {"format": "stub-1", "eintraege": [{"key": str, "klasse": int, "pi": {a: p}, "pi_neu": {a: p},
|
||||
"R": float, "R_se": float, "w": float, "V": {a: bb}, "se_V": {a: bb}, "cov": {a: {b: c}} | null}]}
|
||||
reason mark : "[Vorflop-selbst <alt>-><neu> R <R> w <w>]" inside the answer's `reason`.
|
||||
Header: "VSELBS02" | tau_ref2 f32 | alpha f32 | draws u32 | delta f32 x4 | (u8 length + text) x3: mode, stand, spiel_id.
|
||||
Node record: key u64 | k u16 | a u8 | flags u8 (bit 0: classes present), then k classes of a + 11 bytes each:
|
||||
pi' u8 x a (sum 255; the table bytes when unchanged) | w u8 (w * 255) | R f32 | R_se f32 | n u16 (hands; 0 = class not evaluated).
|
||||
Little-endian. The sidecar holds mixtures and diagnostics only, no action values V; V comes from the rollouts of `vorflop-selbst-archiv` (rows read by `archiv_zeilen`).
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
import struct
|
||||
|
||||
MARKE = re.compile(r"\[Vorflop-selbst\s+(?P<alt>[^\]]*?)->(?P<neu>[^\]]*?)\s+R\s+(?P<R>\S+)\s+w\s+(?P<w>\S+?)\]")
|
||||
KLASSE = re.compile(r"Klasse (\d+)")
|
||||
ANTEIL = re.compile(r"([\w.\-]+)\s+(\d+(?:\.\d+)?)%")
|
||||
MAGIE = b"VSELBS02"
|
||||
|
||||
|
||||
def parse_marke(reason):
|
||||
"""Reason mark -> {alt, neu, R, w} (strings as logged) or None."""
|
||||
m = MARKE.search(reason or "")
|
||||
return m.groupdict() if m else None
|
||||
def lies_kopf(b):
|
||||
"""Header -> (dict, length). ValueError for files that are not VSELBS02."""
|
||||
if b[:8] != MAGIE:
|
||||
raise ValueError("not a VSELBS02 sidecar (magic %r)" % (b[:8],))
|
||||
tau, alpha, zieh = struct.unpack_from("<ffI", b, 8)
|
||||
delta = struct.unpack_from("<4f", b, 20)
|
||||
p, text = 36, []
|
||||
for _ in range(3):
|
||||
n = b[p]
|
||||
text.append(b[p + 1:p + 1 + n].decode("utf-8", "replace"))
|
||||
p += 1 + n
|
||||
return {"tau_ref2": tau, "alpha": alpha, "ziehungen": zieh, "delta": delta, "modus": text[0], "stand": text[1], "spiel_id": text[2]}, p
|
||||
|
||||
|
||||
def parse_klasse(reason):
|
||||
m = KLASSE.search(reason or "")
|
||||
return int(m.group(1)) if m else None
|
||||
class Sidecar:
|
||||
def __init__(self, daten):
|
||||
self.kopf, p = lies_kopf(daten)
|
||||
self.daten, self.lage = daten, {}
|
||||
while p < len(daten):
|
||||
key, k, a, flags = struct.unpack_from("<QHBB", daten, p)
|
||||
n = 12 + (k * (a + 11) if flags & 1 else 0)
|
||||
if p + n > len(daten):
|
||||
raise ValueError("truncated record")
|
||||
if flags & 1:
|
||||
self.lage[key] = (p + 12, k, a)
|
||||
p += n
|
||||
|
||||
def knoten(self):
|
||||
return len(self.lage)
|
||||
|
||||
def parse_mischung(text):
|
||||
"""'fold 0%, call 5%, 0.75x 95%' -> {'fold': 0.0, 'call': 0.05, '0.75x': 0.95} (whole percent, only a fallback)."""
|
||||
return {a: float(p) / 100.0 for a, p in ANTEIL.findall(text or "")}
|
||||
|
||||
|
||||
def knoten_schluessel(q_beschreibung, antwort):
|
||||
"""Node key of a request. STUB: line type + position + players + class; the real key comes from the motor CLI."""
|
||||
k = parse_klasse(antwort.get("reason"))
|
||||
return "%s|%s|%d|%s" % (q_beschreibung["linie"], q_beschreibung["pos"], q_beschreibung["spieler"], k), k
|
||||
def klasse(self, key, kl):
|
||||
"""-> dict(bytes=[pi' bytes], w=float, R=float, R_se=float, n=int) or None (node/class not in the sidecar)."""
|
||||
e = self.lage.get(key)
|
||||
if e is None or kl >= e[1]:
|
||||
return None
|
||||
o, _, a = e
|
||||
o += kl * (a + 11)
|
||||
b = list(self.daten[o:o + a])
|
||||
w = self.daten[o + a] / 255.0
|
||||
r, se, n = struct.unpack_from("<ffH", self.daten, o + a + 1)
|
||||
return {"bytes": b, "w": w, "R": r, "R_se": se, "n": n}
|
||||
|
||||
|
||||
def lade(pfad):
|
||||
with open(pfad, "rb") as f:
|
||||
return Sidecar(f.read())
|
||||
|
||||
|
||||
def archiv_zeilen(pfad):
|
||||
"""Rows of `vorflop-selbst-archiv` (JSON lines): changed decisions with mixtures, R, w, reach, played move and values V (covariance matrix)."""
|
||||
with open(pfad) as f:
|
||||
d = json.load(f)
|
||||
if d.get("format") != "stub-1":
|
||||
raise ValueError("unknown sidecar format %r - update sidecar.py" % d.get("format"))
|
||||
return {(e["key"], e["klasse"]): e for e in d["eintraege"]}
|
||||
return [json.loads(z) for z in f if z.strip()]
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
"""Measurement over ALL preflop decisions of the archive (basis-rein): which would MOTOR_VORFLOP_SELBST change, worth what?
|
||||
|
||||
python3 messung/innovation/vorflop_selbst/vorflop_selbst.py zaehlen
|
||||
python3 .../vorflop_selbst.py lauf <exe> sidecar=<json> [env=K=V ...] (switch ON and OFF through the service, parses the mark)
|
||||
python3 .../vorflop_selbst.py aus <exe_basis> <exe_neu> [n=500] [saat=1] (switch OFF: bit-identical on real requests)
|
||||
python3 .../vorflop_selbst.py bericht (AENDERUNGEN.md + aenderungen.jsonl from lauf.jsonl)
|
||||
python3 .../vorflop_selbst.py auswerten [roh=<archiv-roh.jsonl>] (aenderungen-archiv.tsv on the SSD + AENDERUNGEN.md from the rows of `vorflop-selbst-archiv`)
|
||||
python3 .../vorflop_selbst.py sidecar <datei> [key=<hex> klasse=<n>] (read VSELBS02: header, node count, one class)
|
||||
|
||||
The computation (rollouts for V, the changed decisions, the "sonstige" analysis) runs in the motor tool `vorflop-selbst-archiv` on the farm, see docs/vorflop_selbst.md
|
||||
in claude/vorflop-selbst-2; this script only reads its output.
|
||||
|
||||
Source (read only): <ARCHIV>/ein.jsonl (one request per line), ref.jsonl (logged live answers, same line order).
|
||||
Every exe run goes through werkzeuge/motorplatz.py --plaetze 2, nice 10. Outputs carry no player or hand IDs.
|
||||
@@ -21,6 +24,7 @@ sys.path.insert(0, HIER)
|
||||
import linien as L # noqa: E402
|
||||
import sidecar as S # noqa: E402
|
||||
import wert as W # noqa: E402
|
||||
import auswertung as A # noqa: E402
|
||||
|
||||
WURZEL = "/Users/marcmintel/Projects/pokerfreak"
|
||||
ARCHIV = "/Volumes/Alpha SSD/pokerfreak-daten/pruefstand/basis-rein"
|
||||
@@ -88,38 +92,6 @@ def dienst(exe, qs, env_zusatz):
|
||||
return out
|
||||
|
||||
|
||||
def lauf(exe, opt):
|
||||
"""Runs the preflop requests with the switch ON; keeps the lines whose answer carries the mark."""
|
||||
sc = S.lade(opt["sidecar"])
|
||||
extra = dict(x.split("=", 1) for x in opt.get("env", "").split(",") if x)
|
||||
es = list(preflop_entscheidungen())
|
||||
qs = [q for _, q, _, _, _ in es]
|
||||
an = dienst(exe, qs, dict(extra, **{SCHALTER: "1"}))
|
||||
ohne = dienst(exe, qs, {SCHALTER: "0"})
|
||||
zeilen = {}
|
||||
for (i, q, b, k, _), a, o in zip(es, an, ohne):
|
||||
marke = S.parse_marke(a.get("reason"))
|
||||
key, klasse = S.knoten_schluessel(b, a)
|
||||
e = sc.get((key, klasse))
|
||||
z = zeilen.setdefault((key, klasse), dict(b, key=key, klasse=klasse, n=0, markiert=marke is not None, e=e))
|
||||
z["n"] += 1
|
||||
rows = []
|
||||
for z in zeilen.values():
|
||||
e = z.pop("e")
|
||||
if e is None or not z["markiert"]:
|
||||
continue
|
||||
r = W.zeile({"pi_alt": e["pi"], "pi_neu": e["pi_neu"], "V": e["V"], "cov": e.get("cov"), "se_V": e.get("se_V"),
|
||||
"n": z["n"], "key": z["key"], "klasse": z["klasse"], "linie": z["linie"], "pos": z["pos"],
|
||||
"spieler": z["spieler"], "sonder": z["sonder"], "R": e["R"], "R_se": e["R_se"], "w": e["w"]})
|
||||
if r:
|
||||
rows.append(r)
|
||||
with open(GROSS + "/lauf.jsonl.tmp", "w") as f:
|
||||
for r in W.sortiert(rows):
|
||||
f.write(json.dumps(r) + "\n")
|
||||
os.replace(GROSS + "/lauf.jsonl.tmp", GROSS + "/lauf.jsonl")
|
||||
print("rows changed:", len(rows), "of", len(zeilen), "unique decisions")
|
||||
|
||||
|
||||
def aus(exe_a, exe_b, opt):
|
||||
"""Switch OFF: both exes answer identically on preflop + other streets (turn/river included) of the archive."""
|
||||
n, saat = int(opt.get("n", 500)), int(opt.get("saat", 1))
|
||||
@@ -144,33 +116,28 @@ def aus(exe_a, exe_b, opt):
|
||||
print(json.dumps({k: erg[k] for k in ("n", "je_strasse_gleich_anders", "anders")}))
|
||||
|
||||
|
||||
def erklaerung(z):
|
||||
d = W.differenz(z["pi_alt"], z["pi_neu"])
|
||||
ab = max(d, key=lambda a: -d[a])
|
||||
auf = max(d, key=lambda a: d[a])
|
||||
return ("%s, %s, %d Spieler, Klasse %s: %.0f %% weniger %s, %.0f %% mehr %s (Tafel behaelt Gewicht w=%.2f, der Rest geht auf die selbstkonsistente Antwort); Wert %+.3f bb je Vorkommen "
|
||||
"[%+.3f; %+.3f], kommt %dx im Archiv vor." % (z["linie"], z["pos"], z["spieler"], z["klasse"], -100 * d[ab], ab, 100 * d[auf], auf,
|
||||
z["w"], z["wert"], z["wert_lo"], z["wert_hi"], z["n"]))
|
||||
|
||||
|
||||
def bericht():
|
||||
z = json.load(open(HIER + "/zaehlung.json"))
|
||||
rows = list(lies(GROSS + "/lauf.jsonl"))
|
||||
s = W.summen(rows, z["entscheidungen"], z["haende"])
|
||||
je = W.summen_je(rows, "linie", z["je_linie"], z["haende"])
|
||||
with open(HIER + "/aenderungen.jsonl", "w") as f:
|
||||
for r in rows:
|
||||
f.write(json.dumps({k: r[k] for k in ("key", "linie", "pos", "spieler", "klasse", "n", "pi_alt", "pi_neu", "R", "R_se", "w", "wert", "wert_se", "wert_lo", "wert_hi")}) + "\n")
|
||||
t = ["# Vorflop-selbst: Aenderungen an allen Preflop-Entscheidungen des Archivs", "",
|
||||
"Entscheidungen: %d, davon geaendert (eindeutig): %d (%d Vorkommen). Wert ohne Wuerfel: %+.2f bb/100 [%+.2f; %+.2f]." % (
|
||||
s["entscheidungen"], s["geaendert_eindeutig"], s["geaendert_vorkommen"], s["wert_bb_pro_100"], s["lo_bb_pro_100"], s["hi_bb_pro_100"]),
|
||||
"", "| Linie | Entscheidungen | geaendert | bb/100 [95 %] |", "|---|---|---|---|"]
|
||||
for l, v in je.items():
|
||||
t.append("| %s | %d | %d | %+.2f [%+.2f; %+.2f] |" % (l, v["entscheidungen"], v["geaendert_eindeutig"], v["wert_bb_pro_100"], v["lo_bb_pro_100"], v["hi_bb_pro_100"]))
|
||||
t += ["", "## Top %d nach |Wert|" % TOP, ""] + ["%d. %s" % (i + 1, erklaerung(r)) for i, r in enumerate(rows[:TOP])]
|
||||
def auswerten(opt):
|
||||
"""Rows of `vorflop-selbst-archiv` + archive description -> TSV (SSD) and AENDERUNGEN.md (repo; sums only)."""
|
||||
roh = S.archiv_zeilen(opt.get("roh", GROSS + "/archiv-roh.jsonl"))
|
||||
zaehlung = json.load(open(HIER + "/zaehlung.json"))
|
||||
beschreibung = {z["i"]: z for z in lies(GROSS + "/entscheidungen.jsonl")}
|
||||
zeilen = A.entscheidungszeilen(roh, beschreibung)
|
||||
tmp = GROSS + "/aenderungen-archiv.tsv.tmp"
|
||||
with open(tmp, "w") as f:
|
||||
f.write(A.tsv(zeilen))
|
||||
os.replace(tmp, GROSS + "/aenderungen-archiv.tsv")
|
||||
kopf = "Sidecar: %s" % opt.get("kopf", "sechs100-v2-suche-jam.vselbst (VSELBS02, Modus suche+jam, Delta-Prior aus vergleich2)")
|
||||
text = A.markdown(zeilen, zaehlung, kopf)
|
||||
with open(HIER + "/AENDERUNGEN.md", "w") as f:
|
||||
f.write("\n".join(t) + "\n")
|
||||
print("\n".join(t[:12]))
|
||||
f.write(text)
|
||||
print(text[:1500])
|
||||
|
||||
|
||||
def sidecar_zeigen(pfad, opt):
|
||||
sc = S.lade(pfad)
|
||||
print(json.dumps(sc.kopf), "nodes:", sc.knoten())
|
||||
if "key" in opt:
|
||||
print(sc.klasse(int(opt["key"], 16), int(opt.get("klasse", 0))))
|
||||
|
||||
|
||||
def main(argv):
|
||||
@@ -179,12 +146,12 @@ def main(argv):
|
||||
opt = dict(x.split("=", 1) for x in rest if "=" in x)
|
||||
if cmd == "zaehlen":
|
||||
zaehlen()
|
||||
elif cmd == "lauf":
|
||||
lauf(pos[0], opt)
|
||||
elif cmd == "aus":
|
||||
aus(pos[0], pos[1], opt)
|
||||
elif cmd == "bericht":
|
||||
bericht()
|
||||
elif cmd == "auswerten":
|
||||
auswerten(opt)
|
||||
elif cmd == "sidecar":
|
||||
sidecar_zeigen(pos[0], opt)
|
||||
else:
|
||||
raise SystemExit(__doc__)
|
||||
|
||||
|
||||
@@ -84,3 +84,31 @@ def summen_je(zeilen, schluessel, entscheidungen_je, haende):
|
||||
for z in zeilen:
|
||||
gruppen.setdefault(z[schluessel], []).append(z)
|
||||
return {g: summen(gruppen.get(g, []), entscheidungen_je[g], haende) for g in sorted(entscheidungen_je)}
|
||||
|
||||
|
||||
ROLLEN_RICHTUNG = {"Fold": "MehrFold", "Jam": "MehrJam", "Sonst": "Sonstige"}
|
||||
Z_EINSEITIG95 = 1.645
|
||||
|
||||
|
||||
def richtung_zeile(rollen, pi_alt, pi_neu):
|
||||
"""(direction, net shift per role) of one decision: the role with the largest positive net shift gets the mass (as the motor's `richtung`).
|
||||
Mass moving only between call and raises changes no role total and counts as 'Unveraendert' here too (the motor's convention)."""
|
||||
sh = {"Fold": 0.0, "Jam": 0.0, "Sonst": 0.0}
|
||||
for a, d in differenz(pi_alt, pi_neu).items():
|
||||
sh[rollen[a]] += d
|
||||
if all(abs(x) < VERAENDERT_AB for x in sh.values()):
|
||||
return "Unveraendert", sh
|
||||
return ROLLEN_RICHTUNG[max(sh, key=lambda k: sh[k])], sh
|
||||
|
||||
|
||||
def untere_grenze(r, se):
|
||||
"""Lower one-sided 95 % bound of a normally estimated quantity."""
|
||||
return r - Z_EINSEITIG95 * se
|
||||
|
||||
|
||||
def klassenname(k):
|
||||
"""Preflop class 0..169 as in karten.rs: pairs on the diagonal, suited = high * 13 + low, offsuit = low * 13 + high."""
|
||||
r = "23456789TJQKA"
|
||||
x, y = divmod(k, 13)
|
||||
h, l = max(x, y), min(x, y)
|
||||
return "%s%s%s" % (r[h], r[l], "" if x == y else ("s" if x > y else "o"))
|
||||
|
||||
@@ -12,6 +12,9 @@ while _w != "/" and not os.path.isdir(os.path.join(_w, "messung")):
|
||||
sys.path.insert(0, os.path.join(_w, "messung", "innovation", "vorflop_selbst"))
|
||||
import linien as L # noqa: E402
|
||||
import wert as W # noqa: E402
|
||||
import sidecar as S # noqa: E402
|
||||
import auswertung as A # noqa: E402
|
||||
import struct # noqa: E402
|
||||
|
||||
|
||||
def h(seat, a, amt=None):
|
||||
@@ -138,5 +141,110 @@ class Wert(unittest.TestCase):
|
||||
W.summen([], 0, 0)
|
||||
|
||||
|
||||
def _sidecar_bytes():
|
||||
kopf = b"VSELBS02" + struct.pack("<ffI4f", 0.0, 0.05, 1000, 0.1, 1.0, 0.2, 2.0)
|
||||
for t in (b"suche+jam", b"abc123", b"Sechs100"):
|
||||
kopf += bytes([len(t)]) + t
|
||||
# node 0xABCD: 2 classes, 3 actions; class 1 changed
|
||||
satz = struct.pack("<QHBB", 0xABCD, 2, 3, 1)
|
||||
satz += bytes([85, 85, 85, 255]) + struct.pack("<ffH", 0.0, 0.01, 0)
|
||||
satz += bytes([0, 255, 0, 12]) + struct.pack("<ffH", 1.5, 0.2, 300)
|
||||
leer = struct.pack("<QHBB", 7, 169, 2, 0)
|
||||
return kopf + satz + leer
|
||||
|
||||
|
||||
class SidecarFormat(unittest.TestCase):
|
||||
def test_kopf_und_klassen(self):
|
||||
sc = S.Sidecar(_sidecar_bytes())
|
||||
self.assertEqual((sc.kopf["modus"], sc.kopf["stand"], sc.kopf["spiel_id"]), ("suche+jam", "abc123", "Sechs100"))
|
||||
self.assertAlmostEqual(sc.kopf["delta"][3], 2.0)
|
||||
self.assertEqual(sc.knoten(), 1) # the node without classes is not listed
|
||||
k = sc.klasse(0xABCD, 1)
|
||||
self.assertEqual((k["bytes"], k["n"]), ([0, 255, 0], 300))
|
||||
self.assertAlmostEqual(k["w"], 12 / 255.0)
|
||||
self.assertAlmostEqual(k["R"], 1.5, places=5)
|
||||
self.assertIsNone(sc.klasse(0xABCD, 2))
|
||||
self.assertIsNone(sc.klasse(7, 0))
|
||||
|
||||
def test_falsches_format_und_abgeschnitten(self):
|
||||
with self.assertRaises(ValueError):
|
||||
S.Sidecar(b"VSELBS01" + b"x" * 40)
|
||||
with self.assertRaises(ValueError):
|
||||
S.Sidecar(_sidecar_bytes()[:-5 - 12 - 2])
|
||||
|
||||
|
||||
class Richtung(unittest.TestCase):
|
||||
ROLLEN = {"fold": "Fold", "call": "Sonst", "r": "Sonst", "ai": "Jam"}
|
||||
|
||||
def test_groesste_positive_nettoverschiebung(self):
|
||||
self.assertEqual(W.richtung_zeile(self.ROLLEN, {"fold": 0.5, "call": 0.5}, {"fold": 0.2, "call": 0.5, "ai": 0.3})[0], "MehrJam")
|
||||
self.assertEqual(W.richtung_zeile(self.ROLLEN, {"fold": 0.2, "ai": 0.8}, {"fold": 0.9, "ai": 0.1})[0], "MehrFold")
|
||||
self.assertEqual(W.richtung_zeile(self.ROLLEN, {"fold": 0.6, "ai": 0.4}, {"fold": 0.1, "call": 0.5, "ai": 0.4})[0], "Sonstige")
|
||||
self.assertEqual(W.richtung_zeile(self.ROLLEN, ALT, dict(ALT))[0], "Unveraendert")
|
||||
|
||||
def test_wechsel_nur_zwischen_call_und_raise_gilt_als_unveraendert(self):
|
||||
# Konvention des Motors (`richtung`): die Rolle Call/Raise behaelt ihre Summe; dieselbe Lage zaehlt `sonstige` im Motor-Befund getrennt als Umschichtung
|
||||
self.assertEqual(W.richtung_zeile(self.ROLLEN, {"call": 0.8, "r": 0.2}, {"call": 0.5, "r": 0.5})[0], "Unveraendert")
|
||||
|
||||
def test_klassennamen(self):
|
||||
self.assertEqual((W.klassenname(108), W.klassenname(0), W.klassenname(168), W.klassenname(12), W.klassenname(13 * 12 + 11), W.klassenname(11 * 13 + 12)), ("T6s", "22", "AA", "A2o", "AKs", "AKo"))
|
||||
self.assertAlmostEqual(W.untere_grenze(10.0, 2.0), 10.0 - 1.645 * 2.0)
|
||||
|
||||
|
||||
def _roh(i, key, klasse, erreich, r, se, alt, neu, v, gespielt="CALL"):
|
||||
n = ["fold", "call", "all-in"]
|
||||
cov = [[0.0] * 3, [0.0, 0.04, 0.0], [0.0, 0.0, 0.09]]
|
||||
return {"i": i, "key": key, "klasse": klasse, "klasse_name": W.klassenname(klasse), "erreich": erreich, "namen": n, "rollen": ["Fold", "Sonst", "Jam"],
|
||||
"pi_alt": alt, "pi_neu": neu, "V": v, "cov": cov, "R": r, "R_se": se, "w": 0.0, "n": 1024, "gespielt": gespielt}
|
||||
|
||||
|
||||
BESCHR = {1: {"pos": "BTN", "linie": "open", "spieler": 6, "sonder": []}, 2: {"pos": "BB", "linie": "vs_open", "spieler": 5, "sonder": ["straddle"]}, 3: {"pos": "BTN", "linie": "open", "spieler": 6, "sonder": []}}
|
||||
|
||||
|
||||
class Archivliste(unittest.TestCase):
|
||||
ROH = [_roh(1, "00000000000000aa", 108, 0.1, 10.0, 1.0, [0.3, 0.2, 0.5], [1.0, 0.0, 0.0], [-0.5, -3.0, -9.0], "RAISE 2.0"),
|
||||
_roh(3, "00000000000000aa", 108, 0.1, 10.0, 1.0, [0.3, 0.2, 0.5], [1.0, 0.0, 0.0], [-0.5, -3.0, -9.0], "FOLD"),
|
||||
_roh(2, "00000000000000bb", 168, 0.5, 1.0, 0.5, [0.0, 0.9, 0.1], [0.0, 0.4, 0.6], [-0.5, 5.0, 6.0])]
|
||||
|
||||
def zeilen(self):
|
||||
return A.entscheidungszeilen(self.ROH, BESCHR)
|
||||
|
||||
def test_richtung_und_sortierung_nach_erreichbarkeit_mal_R(self):
|
||||
z = self.zeilen()
|
||||
self.assertEqual([x["richtung"] for x in z], ["MehrFold", "MehrFold", "MehrJam"])
|
||||
t = A.tsv(z).splitlines()
|
||||
self.assertEqual(t[0].split("\t"), A.SPALTEN)
|
||||
# 0,1 x 10 = 1,0 (zweimal) vor 0,5 x 1 = 0,5
|
||||
self.assertEqual([r.split("\t")[5] for r in t[1:]], ["T6s", "T6s", "AA"])
|
||||
self.assertEqual(len(t), 4)
|
||||
|
||||
def test_tsv_traegt_keine_zeilenindizes_oder_kennungen(self):
|
||||
t = A.tsv(self.zeilen())
|
||||
for r in t.splitlines()[1:]:
|
||||
f = r.split("\t")
|
||||
self.assertEqual(len(f), len(A.SPALTEN))
|
||||
self.assertNotIn("kennung", r.lower())
|
||||
self.assertEqual(A.tsv(self.zeilen()).splitlines()[1].split("\t")[:6], ["open", "BTN", "6", "-", "00000000000000aa", "T6s"])
|
||||
|
||||
def test_wert_je_zelle_einmal_mit_haeufigkeit(self):
|
||||
c = A.wertzeilen(self.zeilen())
|
||||
self.assertEqual(len(c), 2) # the two T6s decisions share one cell, n = 2
|
||||
t6 = [x for x in c if x["klasse"] == 108][0]
|
||||
self.assertEqual(t6["n"], 2)
|
||||
# (pi' - pi) V = 0,7 * -0,5 - 0,2 * -3 - 0,5 * -9 = -0,35 + 0,6 + 4,5
|
||||
self.assertAlmostEqual(t6["wert"], 0.7 * -0.5 + 0.2 * 3.0 + 0.5 * 9.0)
|
||||
|
||||
def test_markdown_zahlen_je_richtung_linie_und_position(self):
|
||||
zaehlung = {"entscheidungen": 100, "haende": 50, "je_linie": {"open": 60, "vs_open": 40}, "je_linie_position": {"open|BTN": 60, "vs_open|BB": 40}}
|
||||
m = A.markdown(self.zeilen(), zaehlung, "Sidecar: test", top=2)
|
||||
self.assertIn("geaendert: 3 (3.0 %)", m)
|
||||
self.assertIn("| MehrFold | 2 | 1 |", m)
|
||||
self.assertIn("| MehrJam | 1 | 1 |", m)
|
||||
self.assertIn("| open | 60 | 2 | 0 | 2 | 0 |", m)
|
||||
self.assertIn("| vs_open|BB | 40 | 1 | 1 | 0 | 0 |", m)
|
||||
self.assertEqual(m.count("Knoten 00000000"), 2) # only the top 2 single changes
|
||||
self.assertNotIn("kennung", m.lower())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user