Konflikte: Geldstand behaelt die Trennung Chips/Echtgeld (18.11.) neben dem Kontostand und dem Chipfilter des Echtgeld-Laufs; Sitout nimmt die Windows-Regel (Stack unter 1 BB: erst nachkaufen). Mac-Fixes, auf beiden Systemen gueltig: - Trainer.swift: Ternaer mischte ShapeStyle und Color, kompilierte nicht - eval7 ueber eval7_laden in den neuen Modulen (pip-Paket verdeckte das Repo-Modul: leckfinder, ansage, trainer_coach) - Sammler liest den Client-Log ueber umgebung.client_log() (naht_wache) - decide.mit_vorwissen gibt ohne Treffer die Eingabe selbst zurueck - notaus_schliesst_nicht: Attrappe kennt desktop_dauernd Offen (rot): zugvorrang (Nachfassen vs. Invariante doppelt), pflichtfaelle (CHECK/CALL als Soll), eichung (BetOpen-Reads fehlen in der Tabelle). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
475 lines
20 KiB
Python
475 lines
20 KiB
Python
#!/usr/bin/env python3
|
|
"""Gegner-Aktionsnetz, Schritt 1: Wettknoten aus PHH/HandHQ (NL25/50) ziehen.
|
|
|
|
Ein **Wettknoten** ist wie in `messung/familie_a/bettor.py` jede Lage nach dem Flop in einem Heads-up-Topf, in der
|
|
ein Spieler setzen darf, weil auf der Strasse noch niemand gesetzt hat. Antwort `x` (Check) oder Einsatzstufe
|
|
k <= 0.40 < m <= 0.80 < g <= 1.20 < u (Anteil am Topf davor). Je Knoten ein Beispiel mit
|
|
|
|
oeffentlich Strasse, Vorflop-Aggressor (selbst/Gegner), Vorflop-Erhoehungen, Position, Aggression auf der
|
|
Strasse davor, erster Einsatz der frueheren Strassen (Topf-Anteil, wer, erhoeht?), Topf in bb,
|
|
effektiver Stack / Topf
|
|
privat Lochkarten und Brett (Text), nur wenn am Ende aufgedeckt; die Merkmale gegen das Brett rechnet
|
|
der Kern (`gegnernetz_merkmale`), damit Training und Inferenz dieselbe Rechnung haben
|
|
Spieler Kennung (gehasht, bleibt lokal), Zeit; die HUD-Zaehler kommen aus `statistik` (nur fruehere Haende)
|
|
Showdown verloren?, letzter River-Aggressor? (Muck-Korrektur wie `muck-phh.json`)
|
|
|
|
Zusaetzlich je Hand und Spieler ein Zaehler-Ereignis (Hand, VPIP, PFR, Nach-Flop-Aktionen, davon aggressiv,
|
|
Flop gesehen, Showdown, gegen Einsatz, davon gefoldet).
|
|
|
|
Ausgabe: je Teil eine .npz unter <aus>/teile/ (ausserhalb des Repos: enthaelt gehashte Spielerkennungen).
|
|
|
|
python -I lesen/gegnernetz/daten.py phh <roh> <aus> [--prozesse 16] [--stufen 25,50]
|
|
python -I lesen/gegnernetz/daten.py nl2 <client-alle.jsonl> <live-wurzel> <aus> (Teil 900, mit Siegel)
|
|
"""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import re
|
|
import struct
|
|
import sys
|
|
import zlib
|
|
|
|
import numpy as np
|
|
|
|
_hier = os.path.dirname(os.path.abspath(__file__))
|
|
_wurzel = os.path.dirname(os.path.dirname(_hier))
|
|
for _p in (os.path.join(_wurzel, "lesen"), os.path.join(_wurzel, "entscheiden")):
|
|
if _p not in sys.path:
|
|
sys.path.insert(0, _p)
|
|
import eval7_laden # noqa: E402
|
|
eval7 = eval7_laden.laden() # immer entscheiden/eval7.py, nie das pip-Paket gleichen Namens
|
|
|
|
ANTWORT = {"x": 0, "k": 1, "m": 2, "g": 3, "u": 4}
|
|
NETZ = {"PS": 0, "PTY": 1, "FTP": 2, "ABS": 3, "IPN": 4, "ONG": 5, "CP": 6}
|
|
|
|
_AKT = re.compile(r"actions = \[(.*?)\]", re.S)
|
|
_BL = re.compile(r"blinds_or_straddles = \[(.*?)\]")
|
|
_ST = re.compile(r"starting_stacks = \[(.*?)\]")
|
|
_PL = re.compile(r"players = \[(.*?)\]", re.S)
|
|
_ZEIT = re.compile(r"time = (\d+):(\d+):(\d+)")
|
|
_TAG = re.compile(r"\bday = (\d+)")
|
|
_MON = re.compile(r"\bmonth = (\d+)")
|
|
_JAHR = re.compile(r"\byear = (\d+)")
|
|
_NR = re.compile(r"\bhand = (\d+)")
|
|
|
|
# Spalten der Beispiele (float32), Reihenfolge fest: train.py liest nach Namen.
|
|
SPALTEN = ("strasse", "pfa_selbst", "pfa_gegner", "vor_erh", "ip", "vorher", "f_einsatz", "f_selbst", "f_erh",
|
|
"t_einsatz", "t_selbst", "t_erh", "topf_bb", "spr", "antwort", "groesse", "gezeigt", "verloren",
|
|
"river_aggr", "netz", "stufe")
|
|
# Zaehler je Hand und Spieler (int8)
|
|
ZAEHLER = ("haende", "vpip", "pfr", "nf_akt", "nf_aggr", "flop", "showdown", "gg_einsatz", "gg_fold")
|
|
|
|
|
|
def stufe(f):
|
|
return "k" if f <= 0.40 else "m" if f <= 0.80 else "g" if f <= 1.20 else "u"
|
|
|
|
|
|
def kennung(netz, name):
|
|
"""64-Bit-Hash der Spielerkennung je Netz (bleibt lokal)."""
|
|
return int.from_bytes(hashlib.blake2b(("%s|%s" % (netz, name)).encode("utf-8"), digest_size=8).digest(), "little",
|
|
signed=True)
|
|
|
|
|
|
def _zahlen(t):
|
|
return [float(x) for x in t.split(",") if x.strip()]
|
|
|
|
|
|
def hand_lesen(block):
|
|
"""Ein PHH-Block -> dict oder None (unlesbar)."""
|
|
m, bl, st, pl = _AKT.search(block), _BL.search(block), _ST.search(block), _PL.search(block)
|
|
if not (m and bl and st and pl):
|
|
return None
|
|
blinds = _zahlen(bl.group(1))
|
|
stacks = _zahlen(st.group(1))
|
|
namen = re.findall(r"'([^']*)'", pl.group(1))
|
|
n = len(blinds)
|
|
if n < 2 or len(stacks) != n or len(namen) != n:
|
|
return None
|
|
akt, board, gez = [], [], {}
|
|
s = 0
|
|
for roh in re.findall(r"'([^']*)'", m.group(1)):
|
|
t = roh.split()
|
|
if not t:
|
|
continue
|
|
if t[0] == "d":
|
|
if t[1] == "dh" and len(t) > 3 and "?" not in t[3]:
|
|
gez[int(t[2][1:]) - 1] = t[3]
|
|
elif t[1] == "db":
|
|
s += 1
|
|
kk = t[2]
|
|
board += [kk[j:j + 2] for j in range(0, len(kk), 2)]
|
|
continue
|
|
try:
|
|
p = int(t[0][1:]) - 1
|
|
except ValueError:
|
|
return None
|
|
if not 0 <= p < n:
|
|
return None
|
|
if t[1] == "f":
|
|
akt.append((s, p, "f", 0.0))
|
|
elif t[1] == "cc":
|
|
akt.append((s, p, "c", 0.0))
|
|
elif t[1] == "cbr":
|
|
akt.append((s, p, "r", float(t[2])))
|
|
elif t[1] == "sm" and len(t) > 2 and "?" not in t[2]:
|
|
gez[p] = t[2]
|
|
if s >= 1 and len(board) != (3, 4, 5)[min(s, 3) - 1]:
|
|
return None
|
|
z = _ZEIT.search(block)
|
|
tag, mon, jahr, nr = _TAG.search(block), _MON.search(block), _JAHR.search(block), _NR.search(block)
|
|
zeit = 0
|
|
if z and tag and mon and jahr:
|
|
zeit = ((((int(jahr.group(1)) * 12 + int(mon.group(1))) * 31 + int(tag.group(1))) * 24 + int(z.group(1))) * 60
|
|
+ int(z.group(2))) * 60 + int(z.group(3))
|
|
return {"n": n, "blinds": blinds, "stacks": stacks, "namen": namen, "akt": akt, "board": board,
|
|
"gezeigt": {p: k for p, k in gez.items() if len(k) == 4}, "strassen": s, "zeit": zeit,
|
|
"nr": int(nr.group(1)) if nr else 0}
|
|
|
|
|
|
def _wert(loch, board):
|
|
return eval7.score7([eval7.karte(loch[0:2]), eval7.karte(loch[2:4])] + [eval7.karte(c) for c in board])
|
|
|
|
|
|
def auswerten(h, ante=0.0):
|
|
"""-> (beispiele [(spieler, merkmale dict, loch, brett)], zaehler {spieler: [ZAEHLER]}). `ante`: totes Geld
|
|
(Summe der Antes) im Topf ab Vorflop; die Stacks in `h` sind dann schon ohne Ante."""
|
|
n = h["n"]
|
|
blinds = h["blinds"]
|
|
bb = max(blinds[:2]) if len(blinds) >= 2 else max(blinds)
|
|
if bb <= 0:
|
|
return [], {}
|
|
beitrag = list(blinds)
|
|
gesamt = list(blinds)
|
|
topf_vor = ante
|
|
strasse = 0
|
|
pfa = None
|
|
vor_erh = 0
|
|
aktiv = set(range(n))
|
|
aggr = [[False] * 4 for _ in range(n)]
|
|
erster = {} # strasse -> (spieler, anteil, erhoeht)
|
|
z = {p: [1, 0, 0, 0, 0, 0, 0, 0, 0] for p in range(n)}
|
|
roh = []
|
|
for s, p, art, betrag in h["akt"]:
|
|
if s != strasse:
|
|
topf_vor += sum(beitrag)
|
|
beitrag = [0.0] * n
|
|
strasse = s
|
|
if s == 1:
|
|
for q in aktiv:
|
|
z[q][5] = 1
|
|
if p not in aktiv:
|
|
continue
|
|
hoch = max(beitrag)
|
|
if s == 0:
|
|
if art == "r":
|
|
pfa = p
|
|
vor_erh += 1
|
|
z[p][1] = 1
|
|
z[p][2] = 1
|
|
gesamt[p] += betrag - beitrag[p]
|
|
beitrag[p] = betrag
|
|
elif art == "c":
|
|
if beitrag[p] < hoch - 1e-9:
|
|
z[p][1] = 1
|
|
gesamt[p] += max(hoch - beitrag[p], 0.0)
|
|
beitrag[p] = max(beitrag[p], hoch)
|
|
else:
|
|
aktiv.discard(p)
|
|
continue
|
|
offen = hoch <= 0
|
|
z[p][3] += 1
|
|
if not offen and beitrag[p] < hoch - 1e-9:
|
|
z[p][7] += 1
|
|
if art == "f":
|
|
z[p][8] += 1
|
|
if art == "f":
|
|
aktiv.discard(p)
|
|
continue
|
|
topf = topf_vor + sum(beitrag)
|
|
if offen and len(aktiv) == 2:
|
|
o = next(q for q in aktiv if q != p)
|
|
rest = [h["stacks"][q] - gesamt[q] for q in (p, o)]
|
|
antwort = "x"
|
|
gr = 0.0
|
|
if art == "r":
|
|
gr = betrag / max(topf, 1e-9)
|
|
antwort = stufe(gr)
|
|
ip = (p == 0) if n == 2 else (p > o)
|
|
f = erster.get(1)
|
|
t = erster.get(2)
|
|
m = {"strasse": s, "pfa_selbst": float(pfa == p), "pfa_gegner": float(pfa == o), "vor_erh": min(vor_erh, 3),
|
|
"ip": float(ip), "vorher": float(s > 1 and aggr[p][s - 1]),
|
|
"f_einsatz": f[1] if f and s > 1 else 0.0, "f_selbst": float(bool(f) and s > 1 and f[0] == p),
|
|
"f_erh": float(bool(f) and s > 1 and f[2]),
|
|
"t_einsatz": t[1] if t and s > 2 else 0.0, "t_selbst": float(bool(t) and s > 2 and t[0] == p),
|
|
"t_erh": float(bool(t) and s > 2 and t[2]),
|
|
"topf_bb": topf / bb, "spr": max(min(rest), 0.0) / max(topf, 1e-9),
|
|
"antwort": ANTWORT[antwort], "groesse": gr}
|
|
roh.append((p, m))
|
|
if art == "r":
|
|
if s in erster:
|
|
erster[s] = (erster[s][0], erster[s][1], True)
|
|
else:
|
|
erster[s] = (p, betrag / max(topf, 1e-9), False)
|
|
aggr[p][s] = True
|
|
z[p][4] += 1
|
|
gesamt[p] += betrag - beitrag[p]
|
|
beitrag[p] = betrag
|
|
else:
|
|
gesamt[p] += max(hoch - beitrag[p], 0.0)
|
|
beitrag[p] = max(beitrag[p], hoch)
|
|
# Showdown
|
|
ende = [p for p in range(n) if p in aktiv]
|
|
sd = h["strassen"] == 3 and len(ende) >= 2 and len(h["board"]) == 5
|
|
gez = h["gezeigt"]
|
|
verl, agg = {}, None
|
|
if sd:
|
|
for p in ende:
|
|
if z[p][5]:
|
|
z[p][6] = 1
|
|
try:
|
|
w = {p: _wert(gez[p], h["board"]) for p in ende if p in gez}
|
|
except (KeyError, IndexError):
|
|
w = {}
|
|
if w:
|
|
best = max(w.values())
|
|
verl = {p: v < best for p, v in w.items()}
|
|
for s, p, art, _ in h["akt"]:
|
|
if s == 3 and art == "r":
|
|
agg = p
|
|
out = []
|
|
for p, m in roh:
|
|
karten = gez.get(p) if sd else None
|
|
m["gezeigt"] = float(karten is not None)
|
|
m["verloren"] = float(bool(verl.get(p)))
|
|
m["river_aggr"] = float(agg == p)
|
|
brett = h["board"][:m["strasse"] + 2]
|
|
out.append((p, m, karten or "", "".join(brett)))
|
|
return out, {p: [min(v, 127) for v in z[p]] for p in range(n)}
|
|
|
|
|
|
def _idle():
|
|
if os.name == "nt":
|
|
import ctypes
|
|
ctypes.windll.kernel32.SetPriorityClass(ctypes.windll.kernel32.GetCurrentProcess(), 0x40)
|
|
|
|
|
|
def _teil(args):
|
|
roh, aus, nummern, kennziffer = args
|
|
idx = json.load(open(os.path.join(roh, "index.json")))["eintraege"]
|
|
f = open(os.path.join(roh, "handhq.bin"), "rb")
|
|
bsp_f, bsp_pid, bsp_gid, bsp_loch, bsp_brett = [], [], [], [], []
|
|
ev_pid, ev_gid, ev_zeit, ev_z = [], [], [], []
|
|
haende = 0
|
|
for j in nummern:
|
|
e = idx[j]
|
|
netz = e["name"].split("/")[2].split("-")[0]
|
|
st = int(re.search(r"_(\d+)NLH_", e["name"]).group(1))
|
|
f.seek(e["offset"])
|
|
kk = f.read(30)
|
|
if kk[:4] != b"PK\x03\x04":
|
|
continue
|
|
nl, el = struct.unpack("<HH", kk[26:30])
|
|
f.seek(e["offset"] + 30 + nl + el)
|
|
d = f.read(e["gepackt"])
|
|
text = (zlib.decompress(d, -15) if e["methode"] == 8 else d).decode("utf-8", "replace")
|
|
for i, blk in enumerate(re.split(r"\n(?=\[\d+\]\n)", text)):
|
|
h = hand_lesen(blk)
|
|
if not h:
|
|
continue
|
|
haende += 1
|
|
gid = (j << 20) | (i & 0xFFFFF)
|
|
bsp, zz = auswerten(h)
|
|
pids = [kennung(netz, nm) for nm in h["namen"]]
|
|
for p, v in zz.items():
|
|
ev_pid.append(pids[p])
|
|
ev_gid.append(gid)
|
|
ev_zeit.append(h["zeit"])
|
|
ev_z.append(v)
|
|
for p, m, loch, brett in bsp:
|
|
m["netz"] = NETZ.get(netz, 9)
|
|
m["stufe"] = st
|
|
bsp_f.append([m[c] for c in SPALTEN])
|
|
bsp_pid.append(pids[p])
|
|
bsp_gid.append(gid)
|
|
bsp_loch.append(loch)
|
|
bsp_brett.append(brett)
|
|
np.savez(os.path.join(aus, "teile", "teil-%03d.npz" % kennziffer),
|
|
f=np.asarray(bsp_f, dtype=np.float32).reshape(-1, len(SPALTEN)), pid=np.asarray(bsp_pid, dtype=np.int64),
|
|
gid=np.asarray(bsp_gid, dtype=np.int64), loch=np.asarray(bsp_loch, dtype="U4"),
|
|
brett=np.asarray(bsp_brett, dtype="U10"), ev_pid=np.asarray(ev_pid, dtype=np.int64),
|
|
ev_gid=np.asarray(ev_gid, dtype=np.int64), ev_zeit=np.asarray(ev_zeit, dtype=np.int64),
|
|
ev_z=np.asarray(ev_z, dtype=np.int8).reshape(-1, len(ZAEHLER)))
|
|
return kennziffer, haende, len(bsp_f)
|
|
|
|
|
|
def lauf_phh(roh, aus, prozesse, stufen):
|
|
import multiprocessing as mp
|
|
os.makedirs(os.path.join(aus, "teile"), exist_ok=True)
|
|
idx = json.load(open(os.path.join(roh, "index.json")))["eintraege"]
|
|
wahl = [j for j, e in enumerate(idx) if re.search(r"_(\d+)NLH_", e["name"])
|
|
and int(re.search(r"_(\d+)NLH_", e["name"]).group(1)) in stufen]
|
|
k = max(prozesse * 4, 1)
|
|
auftraege = [(roh, aus, wahl[i::k], i) for i in range(k)]
|
|
_idle()
|
|
with mp.Pool(prozesse, initializer=_idle) as pool:
|
|
summe = [0, 0]
|
|
for kz, h, b in pool.imap_unordered(_teil, auftraege):
|
|
summe[0] += h
|
|
summe[1] += b
|
|
print("Teil %d: %d Haende, %d Knoten (gesamt %d / %d)" % (kz, h, b, *summe), flush=True)
|
|
json.dump({"dateien": len(wahl), "haende": summe[0], "knoten": summe[1], "stufen": list(stufen),
|
|
"spalten": SPALTEN, "zaehler": ZAEHLER}, open(os.path.join(aus, "kopf.json"), "w", encoding="utf-8"))
|
|
|
|
|
|
# --- NL2: eigene Tische (Client-Mitschrieb, `lesen/linien.py client`) ---
|
|
|
|
_KART = {"FOLD": "f", "CHECK": "c", "CALL": "c", "BET": "r", "RAISE": "r", "ALL_IN": "r"}
|
|
_KSTR = {"PREFLOP": 0, "FLOP": 1, "TURN": 2, "RIVER": 3}
|
|
|
|
|
|
def client_hand(h, zeit):
|
|
"""Client-Hand (NL2 Cash 0.01/0.02, ohne Ante) -> dict wie `hand_lesen` oder None. Stacks stehen nicht im
|
|
Mitschrieb: 100 bb oder der eigene Gesamteinsatz, wenn groesser (All-in = genau der Einsatz)."""
|
|
import zaehler
|
|
v = [r for r in h.get("verlauf") or () if isinstance(r, dict) and r.get("seat") is not None]
|
|
if not v or any(r.get("action") == "POST_ANTE" for r in v):
|
|
return None
|
|
if not any(r.get("action") == "POST_BB" and abs(float(r.get("amount") or 0) - 0.02) < 1e-9 for r in v):
|
|
return None
|
|
sb = next((int(r["seat"]) for r in v if r.get("action") == "POST_SB"), None)
|
|
bbs = [int(r["seat"]) for r in v if r.get("action") == "POST_BB"]
|
|
ordnung = ([sb] if sb is not None else []) + [bbs[0]]
|
|
for r in v:
|
|
q = int(r["seat"])
|
|
if q not in ordnung:
|
|
ordnung.append(q)
|
|
pos = {q: i for i, q in enumerate(ordnung)}
|
|
n = len(ordnung)
|
|
if n < 2:
|
|
return None
|
|
blinds = [0.0] * n
|
|
akt, hoch, allin = [], {}, set()
|
|
for r in v:
|
|
a, st = r.get("action"), _KSTR.get(r.get("street"))
|
|
if st is None:
|
|
continue
|
|
p = pos[int(r["seat"])]
|
|
betrag = float(r.get("amount") or 0.0)
|
|
if a in ("POST_SB", "POST_BB"):
|
|
blinds[p] = max(blinds[p], betrag)
|
|
hoch[0] = max(hoch.get(0, 0.0), betrag)
|
|
continue
|
|
art = _KART.get(a)
|
|
if art is None:
|
|
continue
|
|
if art == "r":
|
|
if r.get("amount") is None or betrag <= 0:
|
|
return None
|
|
if a == "ALL_IN":
|
|
allin.add(p)
|
|
if betrag <= hoch.get(st, 0.0) + 1e-9:
|
|
art = "c"
|
|
else:
|
|
hoch[st] = betrag
|
|
akt.append((st, p, art, betrag if art == "r" else 0.0))
|
|
if not akt:
|
|
return None
|
|
# Gesamteinsatz je Spieler (Strassen-Hoechststand), daraus die Stacks
|
|
ges = [0.0] * n
|
|
proStr = {}
|
|
for st, p, art, b in akt:
|
|
d = proStr.setdefault(st, [0.0] * n)
|
|
if st == 0 and not any(d):
|
|
d[:] = list(blinds)
|
|
hoch_s = max(d)
|
|
if art == "r":
|
|
d[p] = b
|
|
elif art == "c":
|
|
d[p] = max(d[p], hoch_s)
|
|
for d in proStr.values():
|
|
for p in range(n):
|
|
ges[p] += d[p]
|
|
stacks = [ges[p] if p in allin else max(2.0, ges[p] + 1e-6) for p in range(n)]
|
|
s = max(st for st, _, _, _ in akt)
|
|
board = [zaehler.karte_text(c) for c in h.get("board") or ()]
|
|
if None in board:
|
|
return None
|
|
if s >= 1 and len(board) < (3, 4, 5)[s - 1]:
|
|
return None
|
|
board = board[:(0, 3, 4, 5)[s]]
|
|
gez = {}
|
|
for sitz, karten in (h.get("aufgedeckt") or {}).items():
|
|
k = [zaehler.karte_text(c) for c in karten or ()]
|
|
if len(k) == 2 and None not in k and int(sitz) in pos:
|
|
gez[pos[int(sitz)]] = "".join(k)
|
|
nm = h.get("kennung") or {}
|
|
namen = [nm.get(str(q), "?%s|%s" % (h.get("hand"), q)) for q in ordnung]
|
|
held = h.get("held")
|
|
return {"n": n, "blinds": blinds, "stacks": stacks, "namen": namen, "akt": akt, "board": board,
|
|
"gezeigt": gez, "strassen": s, "zeit": zeit, "nr": int(h["hand"]) if str(h.get("hand")).isdigit() else 0,
|
|
"held": pos.get(int(held)) if held is not None and int(held) in pos else None}
|
|
|
|
|
|
def lauf_nl2(client, live, aus, kennziffer=900):
|
|
"""NL2-Knoten als Teil <kennziffer> in <aus>/teile, Netz "CP", Stufe 2, mit Siegel je Knoten
|
|
(`holdout.py`: Hand ab Stichtag oder Akteur versiegelt). Eigene Knoten (Held) fallen weg; der Held zaehlt
|
|
auch nicht in die Spieler-Statistik. Zeit = Handnummer (Ordnung innerhalb NL2)."""
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import holdout
|
|
Z = holdout.zeiten(live)
|
|
grenze = holdout.grenze_aus(Z)
|
|
bsp_f, bsp_pid, bsp_gid, bsp_loch, bsp_brett, siegel = [], [], [], [], [], []
|
|
ev_pid, ev_gid, ev_zeit, ev_z = [], [], [], []
|
|
haende = 0
|
|
for i, z in enumerate(open(client, encoding="utf-8")):
|
|
roh = json.loads(z)
|
|
hand = str(roh.get("hand"))
|
|
h = client_hand(roh, int(hand) if hand.isdigit() else 0)
|
|
if not h:
|
|
continue
|
|
haende += 1
|
|
gid = (kennziffer << 20) | (i & 0xFFFFF)
|
|
hv = holdout.hand_versiegelt(hand, Z, grenze)
|
|
bsp, zz = auswerten(h)
|
|
pids = [kennung("CP", nm) for nm in h["namen"]]
|
|
for p, vv in zz.items():
|
|
if p == h["held"]:
|
|
continue
|
|
ev_pid.append(pids[p]); ev_gid.append(gid); ev_zeit.append(h["zeit"]); ev_z.append(vv)
|
|
for p, m, loch, brett in bsp:
|
|
if p == h["held"]:
|
|
continue
|
|
m["netz"] = NETZ["CP"]
|
|
m["stufe"] = 2
|
|
bsp_f.append([m[c] for c in SPALTEN]); bsp_pid.append(pids[p]); bsp_gid.append(gid)
|
|
bsp_loch.append(loch); bsp_brett.append(brett)
|
|
siegel.append(hv or holdout.gegner_versiegelt(h["namen"][p]))
|
|
os.makedirs(os.path.join(aus, "teile"), exist_ok=True)
|
|
np.savez(os.path.join(aus, "teile", "teil-%03d.npz" % kennziffer),
|
|
f=np.asarray(bsp_f, dtype=np.float32).reshape(-1, len(SPALTEN)), pid=np.asarray(bsp_pid, dtype=np.int64),
|
|
gid=np.asarray(bsp_gid, dtype=np.int64), loch=np.asarray(bsp_loch, dtype="U4"),
|
|
brett=np.asarray(bsp_brett, dtype="U10"), ev_pid=np.asarray(ev_pid, dtype=np.int64),
|
|
ev_gid=np.asarray(ev_gid, dtype=np.int64), ev_zeit=np.asarray(ev_zeit, dtype=np.int64),
|
|
ev_z=np.asarray(ev_z, dtype=np.int8).reshape(-1, len(ZAEHLER)), siegel=np.asarray(siegel, dtype=bool))
|
|
f = np.asarray(bsp_f).reshape(-1, len(SPALTEN))
|
|
gz = f[:, SPALTEN.index("gezeigt")] == 1 if len(f) else np.zeros(0, bool)
|
|
sg = np.asarray(siegel, dtype=bool)
|
|
print("NL2: %d Haende, %d Knoten (versiegelt %d), aufgedeckt %d (versiegelt %d)" %
|
|
(haende, len(f), sg.sum(), gz.sum(), (gz & sg).sum()), flush=True)
|
|
|
|
|
|
def _arg(a, name, default=None):
|
|
if "--" + name in a and a.index("--" + name) + 1 < len(a):
|
|
return a[a.index("--" + name) + 1]
|
|
return default
|
|
|
|
|
|
if __name__ == "__main__":
|
|
a = sys.argv[1:]
|
|
if a[0] == "nl2":
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
|
|
lauf_nl2(a[1], a[2], a[3])
|
|
elif a[0] == "phh":
|
|
lauf_phh(a[1], a[2], int(_arg(a, "prozesse", "16")), tuple(int(x) for x in _arg(a, "stufen", "25,50").split(",")))
|