Files
pokerfreak/messung/basis/teile_spots.py
T

54 lines
2.8 KiB
Python

# Spots fuer die Profil-Zerlegung, so wie der Laeufer sie live schickt (Stand 23.11.):
# - Profil aus den hhDealer-Zaehlungen der anderen Tageshaelfte OHNE gezaehlte Reads (GEGNER_ZAEHLUNG ist live aus):
# neu_lesen_ohne_zaehl (nachpruefung/lesen.py)
# - VORWISSEN wie entscheiden/decide.mit_vorwissen: Spielerschluessel `vw` an den Gegner, draht.anreichern mit dem
# Live-Speicher, Art und OHNE aus der Schalterdatei, danach `vw` weg (der Kern seedet aus dem Anfragetext).
# python -B -X utf8 teile_spots.py -> ~/pokerfreak-regulars/gewinnerspots/teile_live/<satz>/spots.jsonl
# ~/pokerfreak-regulars/gewinnerspots/teile_ohne_vw/<satz>/spots.jsonl
import collections, json, os, sys
sys.dont_write_bytecode = True
HIER = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HIER)
import arme as AR # noqa: E402
sys.path.insert(0, os.path.join(AR.KN.LIVE, "lesen", "vorwissen"))
import draht # noqa: E402
QUELLE = os.path.join(AR.GS, "neu_lesen_ohne_zaehl")
def main():
sch = AR.KN.roentgen.lies_schalter(os.environ["KERN_SCHALTER"])
q = draht.Quelle(sch["VORWISSEN"], 10 ** 6)
sp = q.speicher(True)
print("Speicher", {k: v for k, v in sp.items() if k not in ("spieler", "reads", "pool")}, len(sp["spieler"]))
art = sch.get("VORWISSEN_ART", "pool")
ohne = tuple(x.strip() for x in sch.get("VORWISSEN_OHNE", "").split(",") if x.strip())
st = collections.Counter()
for satz in sorted(os.listdir(QUELLE)):
aus = {v: open(os.path.join(AR.GS, v, satz, "spots.jsonl"), "w", encoding="utf-8", newline="\n")
for v in ("teile_live", "teile_ohne_vw") if os.makedirs(os.path.join(AR.GS, v, satz), exist_ok=True) is None}
for z in open(os.path.join(QUELLE, satz, "spots.jsonl"), encoding="utf-8"):
s = json.loads(z)
for v in s["req"]["villains"]:
p = v.get("profile")
if isinstance(p, dict) and p.get("vw"):
v["vw"] = p.pop("vw")
ohne_vw = json.loads(json.dumps(s))
for v in ohne_vw["req"]["villains"]:
v.pop("vw", None)
zeile = draht.anreichern(json.dumps(s["req"], ensure_ascii=True), sp, art, ohne)
r = json.loads(zeile)
for v in r["villains"]:
if v.pop("vw", None) is not None:
st["vw_gesucht"] += 1
st["vw_treffer"] += "vorwissen" in (v.get("profile") or {})
s["req"] = r
aus["teile_live"].write(json.dumps(s, separators=(",", ":")) + "\n")
aus["teile_ohne_vw"].write(json.dumps(ohne_vw, separators=(",", ":")) + "\n")
for f in aus.values():
f.close()
print(satz, dict(st), flush=True)
if __name__ == "__main__":
main()