Files
pokerfreak/messung/fremd/4_regeln/rake_deckel.py
T

63 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Rake-Deckel nach Spielerzahl im Topf: aus den hhDealer-Novemberhaenden (plain-Kopf, ab 2026-11-01).
Rake je Hand = Summe aller Einsaetze - Summe collected (Text), Topf ab 1,00."""
import io, re, sys, zipfile, collections, csv, os, warnings
warnings.filterwarnings("ignore")
HIER = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HIER)
import hh
z = zipfile.ZipFile(sys.argv[1]); namen = [n for n in z.namelist() if n[:7] == "2026-11" or n[:7] == "2026-10" and n[8:10] >= "20"]
aus = collections.defaultdict(list)
RE = re.compile(r"Total pot ₮(\d+)\.(\d\d)")
n_h = 0
for tz in namen:
inner = zipfile.ZipFile(io.BytesIO(z.read(tz)))
for d in inner.namelist():
t = inner.read(d).decode("utf8", "replace")
for b in t.split("CoinPoker Hand #")[1:]:
m = RE.search(b)
if not m or int(m.group(1)) < 1:
continue
txt = "CoinPoker Hand #" + b
z1 = txt.split("\n", 1)[0]
if "Ante" in z1 or "FIRST" in txt or "Cashout" in txt or "posts big blind" in txt.split("*** HOLE")[0].replace("posts big blind", "X", 1):
continue
try:
h = hh.parse(txt)
ein = hh.text_einsatz(h)
except Exception:
continue
topf = sum(ein.values())
koll = sum(h["koll"].values())
lebend = {a[1] for a in h["akt"] if a[0] == "folds"}
n = len([x for x in h["sitze"] if x not in lebend])
if len(h["koll"]) > 1:
continue # Split/Seitentopf: Rake je Topf, eigene Auswertung
aus[(n, "ante" if h["ante"] else "plain")].append((topf, topf - koll, h["zeit"][:10], h["id"], len(h["sitze"])))
n_h += 1
import pruefen
w = csv.writer(open(sys.argv[2], "w", newline="", encoding="utf8"))
w.writerow(["spieler_im_topf", "kopf", "haende", "topf_min", "topf_max", "rake_max", "anteil_gleich_regel", "abweichende_ids"])
for (n, k), L in sorted(aus.items()):
abw = [x for x in L if x[1] != pruefen.rake_regel(x[0])]
w.writerow([n, k, len(L), min(x[0] for x in L), max(x[0] for x in L), max(x[1] for x in L),
round(1 - len(abw) / len(L), 3), " ".join(x[3] for x in abw[:5])])
big = [x for x in L if x[0] >= 400]
if big:
print(n, k, "Topf>=4.00:", len(big), "Rake-Verteilung", collections.Counter(x[1] for x in big).most_common(6))
print("Haende", n_h)
tage = collections.defaultdict(collections.Counter)
for (n, k), L in aus.items():
for t, r, tag, i, ns in L:
if t >= 400 and n == 2:
tage[tag][r if r in (20, 12, 5) else "andere"] += 1
for tag in sorted(tage):
print(tag, dict(tage[tag]))
bsp = [(x[0], x[1], x[3], n) for (n, k), L in aus.items() for x in L if x[2] == "2026/11/10" and x[0] >= 400 and x[1] in (12, 5)]
print(bsp[:12])
print(collections.Counter((x[0] // 100, x[1]) for (n, k), L in aus.items() if n == 2 for x in L if x[1] in (12, 5, 20) and x[0] >= 400).most_common(25))
print("nach Sitzzahl (Topf>=4.00, 2 im Topf, kein Split):", sorted(collections.Counter((x[4], str(x[1]) if x[1] in (20, 12, 5) else "andere") for (n, k), L in aus.items() if n == 2 for x in L if x[0] >= 400).items()))
print("3 im Topf:", sorted(collections.Counter((x[4], str(x[1]) if x[1] in (20, 12, 5) else "andere") for (n, k), L in aus.items() if n == 3 for x in L if x[0] >= 400).items()))