Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
154 lines
6.2 KiB
Python
154 lines
6.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Zieht alles Pruefmaterial aus dem Client in den Bestand (archiv/mitschrieb).
|
|
|
|
python3 korpus/bestand.py # sichern, Bestand kartieren, Beispiele schneiden
|
|
python3 korpus/bestand.py --kurz # nur sagen, was da ist
|
|
|
|
Der Client rotiert sein Log (main.N.log.gz) und schreibt je Tisch ein Unity-Log -
|
|
deshalb wird ALLES mitgeschrieben, nicht nur das Hauptlog. Es wird nur kopiert.
|
|
Ergebnis:
|
|
archiv/mitschrieb/ die Logdateien (grosse komprimiert)
|
|
archiv/mitschrieb/BESTAND.md was vorkommt: Befehle, Captions, Raeume, Sonderformen
|
|
archiv/mitschrieb/beispiele/ je Sonderform eine ganze Hand als Pruefstueck
|
|
"""
|
|
import collections
|
|
import glob
|
|
import gzip
|
|
import os
|
|
import re
|
|
import shutil
|
|
import sys
|
|
|
|
QUELLE = os.path.expanduser("~/Library/Logs/CoinPoker")
|
|
ZIEL = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "archiv", "mitschrieb")
|
|
BEISPIELE = os.path.join(ZIEL, "beispiele")
|
|
HAND = re.compile(r'gameHandId\\?":\\?"(\d+)')
|
|
GROSS = 8_000_000
|
|
|
|
# Sonderformen, die als Pruefstueck gebraucht werden: Marke -> Dateiname
|
|
FORMEN = {
|
|
"isBombpotHand": "bombpot",
|
|
"splashPotDropAmount": "splash",
|
|
"isMegaSplash": "megasplash",
|
|
"game.rit_info": "runit-twice",
|
|
"dealerCardsDoubleBoard": "doppelboard",
|
|
"game.game_alldata": "abgleich-alldata",
|
|
"game.show_cards": "showdown",
|
|
"Caption\\\\\":\\\\\"Ante": "ante",
|
|
"Caption\\\\\":\\\\\"Straddle": "straddle",
|
|
"Caption\\\\\":\\\\\"Sitout": "sitout",
|
|
}
|
|
|
|
def _text(pfad):
|
|
if pfad.endswith(".gz"):
|
|
with gzip.open(pfad, "rt", errors="replace") as h:
|
|
return h.read()
|
|
with open(pfad, errors="replace") as h:
|
|
return h.read()
|
|
|
|
|
|
def sichern():
|
|
os.makedirs(ZIEL, exist_ok=True)
|
|
neu = 0
|
|
for pfad in sorted(glob.glob(os.path.join(QUELLE, "*"))):
|
|
name = os.path.basename(pfad)
|
|
if os.path.isdir(pfad) or name.startswith("."):
|
|
continue
|
|
if name.endswith(".log") and os.path.getsize(pfad) > GROSS:
|
|
ziel = os.path.join(ZIEL, name + ".gz")
|
|
with open(pfad, "rb") as ein, gzip.open(ziel, "wb", 6) as aus:
|
|
shutil.copyfileobj(ein, aus)
|
|
else:
|
|
ziel = os.path.join(ZIEL, name)
|
|
shutil.copy2(pfad, ziel)
|
|
neu += 1
|
|
return neu
|
|
|
|
|
|
def _dateien():
|
|
"""Nur die gesicherten Logdateien - BESTAND.md und beispiele/ zaehlen nicht mit."""
|
|
return sorted(p for p in glob.glob(os.path.join(ZIEL, "*"))
|
|
if os.path.isfile(p) and os.path.basename(p) != "BESTAND.md")
|
|
|
|
|
|
def karten():
|
|
text = "".join(_text(p) for p in _dateien())
|
|
z = {
|
|
"Befehle": collections.Counter(re.findall(r'"Cmd":"((?:game|lobby|table)\.[a-z_]+)"', text)),
|
|
"Captions an Sitzen": collections.Counter(re.findall(r'Caption\\?":\\?"(\w+)\\?"', text)),
|
|
"Raeume": collections.Counter(re.sub(r"\d+$", "#", r).strip()
|
|
for r in re.findall(r'RoomName\\?":\\?"([^"\\]+)', text)),
|
|
"Sonderformen": {k: len(re.findall(k, text)) for k in
|
|
("kpokerActions", "extraTurnTime", "extraTimePreflop", "isBombpotHand",
|
|
"splashPotDropAmount", "isMegaSplash", "game.rit_info",
|
|
"potAmountListRit", "dealerCardsDoubleBoard", "potAmountListDoubleBoard",
|
|
"dealerSeatId", "hud_stats", "game.poker_odds", "isTournament", "straddle")},
|
|
}
|
|
with open(os.path.join(ZIEL, "BESTAND.md"), "w") as h:
|
|
h.write("# Bestand aus dem echten Client (CoinPoker 1.31.0)\n\n")
|
|
h.write("Erzeugt von `corpus/bestand.py` - nicht von Hand pflegen. Nur Kopien, "
|
|
"nichts am Client geaendert.\n\n")
|
|
h.write("## Nicht im Log (muss vom Tischfenster gelesen werden)\n\n")
|
|
h.write("- Das K-Poker-Menue: `kpokerActions` steht in jeder Zugzeile, ist aber "
|
|
"**immer null** - die Betraege und Prozente kennt nur die Anzeige.\n")
|
|
h.write("- Die Knopfstellen (Fold/Call/Raise, Groessen, Buy-in, Nachkauf) - siehe "
|
|
"`mock/vorlage/README.md`.\n\n")
|
|
for titel, werte in z.items():
|
|
h.write(f"## {titel}\n\n")
|
|
if isinstance(werte, dict):
|
|
for k, n in sorted(werte.items(), key=lambda x: -x[1]):
|
|
h.write(f"- `{k}`: {n}x\n")
|
|
else:
|
|
for k, n in werte.most_common(40):
|
|
h.write(f"- `{k}`: {n}x\n")
|
|
h.write("\n")
|
|
h.write("## Beispiele\n\n")
|
|
for p in sorted(glob.glob(os.path.join(BEISPIELE, "*"))):
|
|
h.write(f"- `beispiele/{os.path.basename(p)}`\n")
|
|
return z
|
|
|
|
|
|
def beispiele():
|
|
"""Je Sonderform eine ganze Hand (alle Zeilen derselben Handkennung) als Pruefstueck."""
|
|
os.makedirs(BEISPIELE, exist_ok=True)
|
|
text = "".join(_text(p) for p in _dateien() if "table_" not in os.path.basename(p))
|
|
zeilen = text.splitlines()
|
|
gemacht = {}
|
|
for marke, name in FORMEN.items():
|
|
treffer = next((z for z in zeilen if re.search(marke, z) and HAND.search(z)), None)
|
|
if not treffer:
|
|
continue
|
|
m = HAND.search(treffer)
|
|
if not m:
|
|
continue
|
|
hand = m.group(1)
|
|
block = [z for z in zeilen if hand in z]
|
|
pfad = os.path.join(BEISPIELE, f"{name}.txt")
|
|
with open(pfad, "w") as h:
|
|
h.write(f"# {name}: eine ganze echte Hand (gameHandId {hand}), roh aus dem Client.\n")
|
|
h.write(f"# Marke: {marke}\n\n")
|
|
h.write("\n".join(block) + "\n")
|
|
gemacht[name] = len(block)
|
|
return gemacht
|
|
|
|
|
|
def main():
|
|
if "--kurz" in sys.argv:
|
|
for p in _dateien():
|
|
print(f" {os.path.getsize(p)//1024:>7} KB {os.path.basename(p)}")
|
|
return 0
|
|
n = sichern()
|
|
z = karten()
|
|
b = beispiele()
|
|
print(f"gesichert: {n} Dateien")
|
|
print(f"Beispiele geschnitten: {len(b)} -> {', '.join(sorted(b))}")
|
|
fehlt = [k for k, v in z["Sonderformen"].items() if not v]
|
|
print(f"Sonderformen ohne Treffer: {', '.join(fehlt) or 'keine'}")
|
|
ohne = [n for n in FORMEN.values() if n not in b]
|
|
print(f"Ohne Pruefstueck: {', '.join(sorted(ohne)) or 'keine'}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|