From 526caa5da37b5f77d82c3f83a3a2b09a9cb47cbf Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Mon, 16 Nov 2026 13:14:26 +0100 Subject: [PATCH] Punkt 2: Hand-Historie aus dem Replay-Dienst + Replay-Scout Quelle belegt am Code des Hand-Replayers (hrweb, main.a753396d.js): POST https://nxtgenapi./pbshots/handhistory/v4/replay, {"hand_id", "game_type": "zoompoker"}, Bearer = Firebase-Token des Clients. Nur Lesen. lesen/handverlauf.py (neu): eine Hand auf unsere Namen - Tisch, Blinds, Board, je Spieler Position/Stapel/Einsatz/Ergebnis/gezeigte Karten, alle Aktionen je Strasse mit Betrag und Denkzeit (actionDuration ist Millisekunden -> Sekunden), Pot-Gewinner. je_gegner(): VPIP/PFR, Aggression nach dem Flop, Showdowns samt Karten, Ergebnis, Denkzeit. ALLIN zaehlt fuer VPIP, nicht fuer PFR/Aggression. Name handverlauf statt replay: entscheiden/replay.py (Engine-Benchmark) laege mit auf dem Pfad. werkzeuge/replay_scout.py (neu): Tisch -> Haende -> je Gegner; --log / --tisch --von --bis / --datei (offline). Deckel 200 Abrufe, 0.6 s Pause, Abbruch nach zwei Ablehnungen; Ablage geschwaerzt (sessionId/referenceNumber). Befund (22 echte Antworten vom 16.11.): der Dienst liefert JEDE Hand, auch ohne uns (Hand-Id = tableChildId + 5-stelliger Zaehler, 178786700001 kam vollstaendig); Karten nur, soweit am Tisch gezeigt - gefoldete stehen als "folded" -> None. Fall (vorher rot - lesen/handverlauf.py und werkzeuge/replay_scout.py gab es bei HEAD nicht, ModuleNotFoundError): tests/handverlauf_spec.py (20 Faelle), Beleg archiv/mitschrieb/beispiele/replay.jsonl (drei Antworten, geschwaerzt) - test_showdown_karten_und_board: Chaniii Kh7h vs Raminjeni 7s5h, 3c4d8dAsAh - test_gefoldete_karten_bleiben_unbekannt - test_denkzeit_in_sekunden: 13000 ms -> 13.0 - test_spieler_ueber_zwei_haende: PlottingRevenge 2 Haende, VPIP/PFR 0.5 - test_allin_zaehlt_nicht_als_aggression, test_return_ist_keine_entscheidung - test_anfrage_wie_der_replayer, test_bereich_hat_deckel, test_bericht_ohne_netz VERTRAG.md byte-gleich, UTF-8 ohne BOM, kein except: pass, replay_spec (Engine) unveraendert gruen. Co-Authored-By: Claude Opus 5.5 --- archiv/mitschrieb/beispiele/replay.jsonl | 3 + lesen/handverlauf.py | 206 +++++++++++++++++++++++ tests/handverlauf_spec.py | 150 +++++++++++++++++ werkzeuge/replay_scout.py | 162 ++++++++++++++++++ 4 files changed, 521 insertions(+) create mode 100644 archiv/mitschrieb/beispiele/replay.jsonl create mode 100644 lesen/handverlauf.py create mode 100644 tests/handverlauf_spec.py create mode 100644 werkzeuge/replay_scout.py diff --git a/archiv/mitschrieb/beispiele/replay.jsonl b/archiv/mitschrieb/beispiele/replay.jsonl new file mode 100644 index 00000000..8b26eb14 --- /dev/null +++ b/archiv/mitschrieb/beispiele/replay.jsonl @@ -0,0 +1,3 @@ +{"status":"success","api_version":"1.0.0","api_code":1,"response":{"data":[{"type":"cash","handDetail":{"totalPotAmount":0.05,"handId":"178786700265","summary":[{"userId":1538517,"avatarId":14,"partnerId":30001,"username":"accurate5604516","referenceNumber":"","sessionId":"","totalWin":0,"totalBets":0.02,"profitLoss":-0.02,"chipStackStart":2.97,"chipStackEnd":2.95,"position":"BB","seatIndex":1,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":-0.02,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"14","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1887895,"avatarId":9,"partnerId":30001,"username":"bright825946636","referenceNumber":"","sessionId":"","totalWin":10.08,"totalBets":0,"profitLoss":0,"chipStackStart":6.84,"chipStackEnd":6.84,"position":"UTG","seatIndex":2,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"9","activeAvatar":"internal","avatarExternalImage":""}},{"userId":575985,"avatarId":4,"partnerId":30001,"username":"vickey","referenceNumber":"","sessionId":"","totalWin":9.71,"totalBets":0.02,"profitLoss":0.03,"chipStackStart":1.66,"chipStackEnd":1.69,"position":"UTG1","seatIndex":4,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0.03,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"4","activeAvatar":"internal","avatarExternalImage":""}},{"userId":395637,"avatarId":22,"partnerId":30001,"username":"Axlteh","referenceNumber":"","sessionId":"","totalWin":9.14,"totalBets":0,"profitLoss":0,"chipStackStart":4.98,"chipStackEnd":4.98,"position":"BTN","seatIndex":5,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"22","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1883347,"avatarId":1,"partnerId":30001,"username":"KillerTom","referenceNumber":"","sessionId":"","totalWin":0.02,"totalBets":0.01,"profitLoss":-0.01,"chipStackStart":1.98,"chipStackEnd":1.97,"position":"SB","seatIndex":6,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":-0.01,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"1","activeAvatar":"internal","avatarExternalImage":""}}],"details":{"ante":{"potDetails":[],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"preflop":{"potDetails":[0.05],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[{"position":"SB","username":"KillerTom","userId":1883347,"avatarId":1,"action":"SB","newPlayerAction":"SB","amount":0.01,"chipStackStart":1.98,"chipStackEnd":1.97,"totalPot":0.01,"timestamp":1794828277,"isAutoAction":true,"isFastFold":false,"actionInitTime":1794828277,"actionResponseTime":1794828277,"actionDuration":0},{"position":"BB","username":"accurate5604516","userId":1538517,"avatarId":14,"action":"BB","newPlayerAction":"BB","amount":0.02,"chipStackStart":2.97,"chipStackEnd":2.95,"totalPot":0.03,"timestamp":1794828278,"isAutoAction":true,"isFastFold":false,"actionInitTime":1794828278,"actionResponseTime":1794828278,"actionDuration":0},{"position":"UTG","username":"bright825946636","userId":1887895,"avatarId":9,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":6.84,"chipStackEnd":6.84,"totalPot":0.03,"timestamp":1794828283,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828278,"actionResponseTime":1794828283,"actionDuration":5000},{"position":"UTG1","username":"vickey","userId":575985,"avatarId":4,"action":"RAISE","newPlayerAction":"RAISE","amount":0.05,"chipStackStart":1.66,"chipStackEnd":1.61,"totalPot":0.08,"timestamp":1794828290,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828283,"actionResponseTime":1794828290,"actionDuration":7000},{"position":"BTN","username":"Axlteh","userId":395637,"avatarId":22,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":4.98,"chipStackEnd":4.98,"totalPot":0.08,"timestamp":1794828290,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828290,"actionResponseTime":1794828290,"actionDuration":0},{"position":"SB","username":"KillerTom","userId":1883347,"avatarId":1,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":1.97,"chipStackEnd":1.97,"totalPot":0.08,"timestamp":1794828294,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828290,"actionResponseTime":1794828294,"actionDuration":4000},{"position":"BB","username":"accurate5604516","userId":1538517,"avatarId":14,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":2.95,"chipStackEnd":2.95,"totalPot":0.08,"timestamp":1794828295,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828294,"actionResponseTime":1794828295,"actionDuration":1000},{"position":"UTG1","username":"vickey","userId":575985,"avatarId":4,"action":"RETURN","newPlayerAction":"RETURN","amount":0.029999999999999902,"chipStackStart":1.61,"chipStackEnd":1.64,"totalPot":0.05,"timestamp":1794828296,"isAutoAction":true,"isFastFold":false,"actionInitTime":1794828296,"actionResponseTime":1794828296,"actionDuration":0}],"playerActionRit":[],"playerActionEvchop":[]},"flop":{"potDetails":[],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"turn":{"potDetails":[],"potDetailsDoubleboard ":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"river":{"potDetails":[],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"showdown":{"muckedPlayers":[],"potDetails":[0.05],"potWinners":[{"potAmount":0.05,"potContestants":[1883347,1538517,575985],"winnerDetails":[{"userId":575985,"amount":0.05,"timestamp":1794828300,"winType":"DEFAULT"}]}],"potDetailsRit":[],"potWinnersRit":[],"potDetailsRit2":[],"potWinnersRit2":[],"potDetailsDoubleboard":[],"potWinnersDoubleboard":[]},"splashDetails":{"isSplashDrop":null,"isSplashIllusion":false,"isMegaSplash":false,"splashDropAmount":0,"splashCollectionAmount":0,"splashSharedBonusPercentage":0,"splashSharedAmount":0,"splashContestedAmount":0,"noUsersReceivingSharedBonus":0},"doubleBoardCards":[],"isDoubleBoard":0,"isBombPot":false,"bombAnte":0},"isRit":0,"tableCard":[],"tableCardRit":[],"tableCardRit2":[]},"handId":"178786700265","ante":0,"tableCards":[],"tableRit":0,"gameType":"GAME_STATS_CASH","tableCardRit2":[],"startDatetime":"2026-11-16 11:24:37","tableInfo":{"miniGameTypeId":"Holdem","tableId":202092,"isAnonymous":false,"tableChildId":1787867,"metadata":{"theme":null,"iconImage":null},"smallBlind":0.01,"bigBlind":0.02,"ante":0,"minBuyin":0.8,"maxBuyin":2,"playersPerTable":6,"tableType":"Public","miniGameTypeActualId":1,"isBombpotConfig":false,"isFixedhandBombpot":null,"isBombpot":false,"mustShowEnabled":false,"mixedGameVariant":null},"tournamentInfo":{}}]}} +{"status":"success","api_version":"1.0.0","api_code":1,"response":{"data":[{"type":"cash","handDetail":{"totalPotAmount":0.18,"handId":"178698900637","summary":[{"userId":1860388,"avatarId":4,"partnerId":30001,"username":"Chaniii","referenceNumber":"","sessionId":"","totalWin":11.73,"totalBets":0.06,"profitLoss":0.11,"chipStackStart":3.95,"chipStackEnd":4.06,"position":"BB","seatIndex":1,"cardsFlipped":1,"isRabbitAvailed":0,"cards":["heart_13","heart_7"],"isPreflopLeft":false,"bestCards":["spade_14","heart_14","heart_13","diamond_8","heart_7"],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":"ONE_PAIR","handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0.11,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"4","activeAvatar":"internal","avatarExternalImage":""}},{"userId":403486,"avatarId":5,"partnerId":30001,"username":"w1zz","referenceNumber":"","sessionId":"","totalWin":1.11,"totalBets":0,"profitLoss":0,"chipStackStart":2.64,"chipStackEnd":2.64,"position":"UTG","seatIndex":2,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"5","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1898374,"avatarId":1,"partnerId":30001,"username":"PlottingRevenge","referenceNumber":"","sessionId":"","totalWin":2.1,"totalBets":0,"profitLoss":0,"chipStackStart":2,"chipStackEnd":2,"position":"UTG1","seatIndex":3,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"1","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1930304,"avatarId":1,"partnerId":30001,"username":"overcooked22225","referenceNumber":"","sessionId":"","totalWin":3.86,"totalBets":0.06,"profitLoss":-0.06,"chipStackStart":1.79,"chipStackEnd":1.73,"position":"BTN","seatIndex":4,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":["folded","folded","folded","folded","folded"],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":-0.06,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":true,"avatarDetails":{"avatarImg":"1","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1914418,"avatarId":18,"partnerId":30001,"username":"Raminjeni","referenceNumber":"","sessionId":"","totalWin":3.42,"totalBets":0.06,"profitLoss":-0.06,"chipStackStart":1.1,"chipStackEnd":1.04,"position":"SB","seatIndex":5,"cardsFlipped":1,"isRabbitAvailed":0,"cards":["spade_7","heart_5"],"isPreflopLeft":false,"bestCards":["spade_14","heart_14","diamond_8","spade_7","heart_5"],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":"ONE_PAIR","handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":-0.06,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"18","activeAvatar":"internal","avatarExternalImage":""}}],"details":{"ante":{"potDetails":[],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"preflop":{"potDetails":[0.18],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[{"position":"SB","username":"Raminjeni","userId":1914418,"avatarId":18,"action":"SB","newPlayerAction":"SB","amount":0.01,"chipStackStart":1.1,"chipStackEnd":1.09,"totalPot":0.01,"timestamp":1794828276,"isAutoAction":true,"isFastFold":false,"actionInitTime":1794828276,"actionResponseTime":1794828276,"actionDuration":0},{"position":"BB","username":"Chaniii","userId":1860388,"avatarId":4,"action":"BB","newPlayerAction":"BB","amount":0.02,"chipStackStart":3.95,"chipStackEnd":3.93,"totalPot":0.03,"timestamp":1794828276,"isAutoAction":true,"isFastFold":false,"actionInitTime":1794828276,"actionResponseTime":1794828276,"actionDuration":0},{"position":"UTG","username":"w1zz","userId":403486,"avatarId":5,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":2.64,"chipStackEnd":2.64,"totalPot":0.03,"timestamp":1794828283,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828276,"actionResponseTime":1794828283,"actionDuration":7000},{"position":"UTG1","username":"PlottingRevenge","userId":1898374,"avatarId":1,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":2,"chipStackEnd":2,"totalPot":0.03,"timestamp":1794828283,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828283,"actionResponseTime":1794828283,"actionDuration":0},{"position":"BTN","username":"overcooked22225","userId":1930304,"avatarId":1,"action":"RAISE","newPlayerAction":"RAISE","amount":0.06,"chipStackStart":1.79,"chipStackEnd":1.73,"totalPot":0.09,"timestamp":1794828285,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828283,"actionResponseTime":1794828285,"actionDuration":2000},{"position":"SB","username":"Raminjeni","userId":1914418,"avatarId":18,"action":"CALL","newPlayerAction":"CALL","amount":0.05,"chipStackStart":1.09,"chipStackEnd":1.04,"totalPot":0.14,"timestamp":1794828288,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828285,"actionResponseTime":1794828288,"actionDuration":3000},{"position":"BB","username":"Chaniii","userId":1860388,"avatarId":4,"action":"CALL","newPlayerAction":"CALL","amount":0.04,"chipStackStart":3.93,"chipStackEnd":3.89,"totalPot":0.18,"timestamp":1794828291,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828288,"actionResponseTime":1794828291,"actionDuration":3000}],"playerActionRit":[],"playerActionEvchop":[]},"flop":{"potDetails":[0.18],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[{"position":"SB","username":"Raminjeni","userId":1914418,"avatarId":18,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":1.04,"chipStackEnd":1.04,"totalPot":0.18,"timestamp":1794828297,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828292,"actionResponseTime":1794828297,"actionDuration":5000},{"position":"BB","username":"Chaniii","userId":1860388,"avatarId":4,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":3.89,"chipStackEnd":3.89,"totalPot":0.18,"timestamp":1794828297,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828297,"actionResponseTime":1794828297,"actionDuration":0},{"position":"BTN","username":"overcooked22225","userId":1930304,"avatarId":1,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":1.73,"chipStackEnd":1.73,"totalPot":0.18,"timestamp":1794828300,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828297,"actionResponseTime":1794828300,"actionDuration":3000}],"playerActionRit":[],"playerActionEvchop":[]},"turn":{"potDetails":[0.18],"potDetailsDoubleboard ":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[{"position":"SB","username":"Raminjeni","userId":1914418,"avatarId":18,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":1.04,"chipStackEnd":1.04,"totalPot":0.18,"timestamp":1794828301,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828300,"actionResponseTime":1794828301,"actionDuration":1000},{"position":"BB","username":"Chaniii","userId":1860388,"avatarId":4,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":3.89,"chipStackEnd":3.89,"totalPot":0.18,"timestamp":1794828306,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828301,"actionResponseTime":1794828306,"actionDuration":5000},{"position":"BTN","username":"overcooked22225","userId":1930304,"avatarId":1,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":1.73,"chipStackEnd":1.73,"totalPot":0.18,"timestamp":1794828308,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828306,"actionResponseTime":1794828308,"actionDuration":2000}],"playerActionRit":[],"playerActionEvchop":[]},"river":{"potDetails":[0.18],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[{"position":"SB","username":"Raminjeni","userId":1914418,"avatarId":18,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":1.04,"chipStackEnd":1.04,"totalPot":0.18,"timestamp":1794828310,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828309,"actionResponseTime":1794828310,"actionDuration":1000},{"position":"BB","username":"Chaniii","userId":1860388,"avatarId":4,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":3.89,"chipStackEnd":3.89,"totalPot":0.18,"timestamp":1794828330,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828327,"actionResponseTime":1794828330,"actionDuration":3000},{"position":"BTN","username":"overcooked22225","userId":1930304,"avatarId":1,"action":"CHECK","newPlayerAction":"CHECK","amount":0,"chipStackStart":1.73,"chipStackEnd":1.73,"totalPot":0.18,"timestamp":1794828334,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828330,"actionResponseTime":1794828334,"actionDuration":4000}],"playerActionRit":[],"playerActionEvchop":[]},"showdown":{"muckedPlayers":[1930304],"potDetails":[0.18],"potWinners":[{"potAmount":0.18,"potContestants":[1914418,1930304,1860388],"winnerDetails":[{"userId":1860388,"amount":0.17,"timestamp":1794828340,"winType":"ONE_PAIR"}]}],"potDetailsRit":[],"potWinnersRit":[],"potDetailsRit2":[],"potWinnersRit2":[],"potDetailsDoubleboard":[],"potWinnersDoubleboard":[]},"splashDetails":{"isSplashDrop":null,"isSplashIllusion":false,"isMegaSplash":false,"splashDropAmount":0,"splashCollectionAmount":0,"splashSharedBonusPercentage":0,"splashSharedAmount":0,"splashContestedAmount":0,"noUsersReceivingSharedBonus":0},"doubleBoardCards":[],"isDoubleBoard":0,"isBombPot":false,"bombAnte":0},"isRit":0,"tableCard":["club_3","diamond_4","diamond_8","spade_14","heart_14"],"tableCardRit":[],"tableCardRit2":[]},"handId":"178698900637","ante":0,"tableCards":["club_3","diamond_4","diamond_8","spade_14","heart_14"],"tableRit":0,"gameType":"GAME_STATS_CASH","tableCardRit2":[],"startDatetime":"2026-11-16 11:24:36","tableInfo":{"miniGameTypeId":"Holdem","tableId":202092,"isAnonymous":false,"tableChildId":1786989,"metadata":{"theme":null,"iconImage":null},"smallBlind":0.01,"bigBlind":0.02,"ante":0,"minBuyin":0.8,"maxBuyin":2,"playersPerTable":6,"tableType":"Public","miniGameTypeActualId":1,"isBombpotConfig":false,"isFixedhandBombpot":null,"isBombpot":false,"mustShowEnabled":false,"mixedGameVariant":null},"tournamentInfo":{}}]}} +{"status":"success","api_version":"1.0.0","api_code":1,"response":{"data":[{"type":"cash","handDetail":{"totalPotAmount":1.38,"handId":"178852800014","summary":[{"userId":1714329,"avatarId":3,"partnerId":30001,"username":"lasting98005466","referenceNumber":"","sessionId":"","totalWin":0.04,"totalBets":0.02,"profitLoss":-0.02,"chipStackStart":0.82,"chipStackEnd":0.8,"position":"BB","seatIndex":1,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":-0.02,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"3","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1898374,"avatarId":1,"partnerId":30001,"username":"PlottingRevenge","referenceNumber":"","sessionId":"","totalWin":0,"totalBets":0.68,"profitLoss":-0.68,"chipStackStart":2,"chipStackEnd":1.32,"position":"UTG","seatIndex":2,"cardsFlipped":1,"isRabbitAvailed":0,"cards":["spade_8","club_8"],"isPreflopLeft":false,"bestCards":["spade_8","club_8","heart_4","diamond_4","heart_12"],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":"TWO_PAIR","handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":-0.68,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"1","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1701600,"avatarId":1,"partnerId":30001,"username":"Cokabbluffin","referenceNumber":"","sessionId":"","totalWin":0.94,"totalBets":0,"profitLoss":0,"chipStackStart":2.43,"chipStackEnd":2.43,"position":"UTG1","seatIndex":3,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"1","activeAvatar":"internal","avatarExternalImage":""}},{"userId":33509,"avatarId":4,"partnerId":30001,"username":"jf563","referenceNumber":"","sessionId":"","totalWin":1.61,"totalBets":0,"profitLoss":0,"chipStackStart":2.3,"chipStackEnd":2.3,"position":"CO","seatIndex":4,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"4","activeAvatar":"internal","avatarExternalImage":""}},{"userId":1524336,"avatarId":17,"partnerId":30001,"username":"Holabear","referenceNumber":"","sessionId":"","totalWin":0.72,"totalBets":0,"profitLoss":0,"chipStackStart":2.32,"chipStackEnd":2.32,"position":"BTN","seatIndex":5,"cardsFlipped":0,"isRabbitAvailed":0,"cards":["folded","folded"],"isPreflopLeft":false,"bestCards":[],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":null,"handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"17","activeAvatar":"internal","avatarExternalImage":""}},{"userId":549489,"avatarId":1,"partnerId":30001,"username":"fomo27","referenceNumber":"","sessionId":"","totalWin":1.33,"totalBets":0.68,"profitLoss":0.63,"chipStackStart":0.68,"chipStackEnd":1.31,"position":"SB","seatIndex":6,"cardsFlipped":1,"isRabbitAvailed":0,"cards":["diamond_13","heart_13"],"isPreflopLeft":false,"bestCards":["diamond_13","heart_13","heart_4","diamond_4","heart_12"],"bestCardsRit":[],"bestCardsRit2":[],"bestCardsDoubleboard":[],"handRank":"TWO_PAIR","handRankDoubleboard":null,"handRankRit":null,"handRankRit2":null,"evChopDetailsAll":null,"splashDetails":{"splashDropAmount":0,"splashCollectionAmount":0,"nonSplashWinAmount":0.63,"splashEvchop":false,"splashEvchopFees":null,"splashSharedBonusAmount":0,"splashContestedAmount":0},"bountyDetails":null,"metadata":null,"selfBounty":0,"isMuck":false,"avatarDetails":{"avatarImg":"1","activeAvatar":"internal","avatarExternalImage":""}}],"details":{"ante":{"potDetails":[],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"preflop":{"potDetails":[0.32],"potDetailsDoubleboard":[],"equityDetails":[],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[{"position":"SB","username":"fomo27","userId":549489,"avatarId":1,"action":"SB","newPlayerAction":"SB","amount":0.01,"chipStackStart":0.68,"chipStackEnd":0.67,"totalPot":0.01,"timestamp":1794828240,"isAutoAction":true,"isFastFold":false,"actionInitTime":1794828240,"actionResponseTime":1794828240,"actionDuration":0},{"position":"BB","username":"lasting98005466","userId":1714329,"avatarId":3,"action":"BB","newPlayerAction":"BB","amount":0.02,"chipStackStart":0.82,"chipStackEnd":0.8,"totalPot":0.03,"timestamp":1794828240,"isAutoAction":true,"isFastFold":false,"actionInitTime":1794828240,"actionResponseTime":1794828240,"actionDuration":0},{"position":"UTG","username":"PlottingRevenge","userId":1898374,"avatarId":1,"action":"RAISE","newPlayerAction":"RAISE","amount":0.04,"chipStackStart":2,"chipStackEnd":1.96,"totalPot":0.07,"timestamp":1794828243,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828241,"actionResponseTime":1794828243,"actionDuration":2000},{"position":"UTG1","username":"Cokabbluffin","userId":1701600,"avatarId":1,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":2.43,"chipStackEnd":2.43,"totalPot":0.07,"timestamp":1794828244,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828243,"actionResponseTime":1794828244,"actionDuration":1000},{"position":"CO","username":"jf563","userId":33509,"avatarId":4,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":2.3,"chipStackEnd":2.3,"totalPot":0.07,"timestamp":1794828250,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828244,"actionResponseTime":1794828250,"actionDuration":6000},{"position":"BTN","username":"Holabear","userId":1524336,"avatarId":17,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":2.32,"chipStackEnd":2.32,"totalPot":0.07,"timestamp":1794828257,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828250,"actionResponseTime":1794828257,"actionDuration":7000},{"position":"SB","username":"fomo27","userId":549489,"avatarId":1,"action":"RAISE","newPlayerAction":"RAISE","amount":0.14,"chipStackStart":0.67,"chipStackEnd":0.53,"totalPot":0.21,"timestamp":1794828287,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828274,"actionResponseTime":1794828287,"actionDuration":13000},{"position":"BB","username":"lasting98005466","userId":1714329,"avatarId":3,"action":"FOLD","newPlayerAction":"FOLD","amount":0,"chipStackStart":0.8,"chipStackEnd":0.8,"totalPot":0.21,"timestamp":1794828289,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828287,"actionResponseTime":1794828289,"actionDuration":2000},{"position":"UTG","username":"PlottingRevenge","userId":1898374,"avatarId":1,"action":"CALL","newPlayerAction":"CALL","amount":0.11,"chipStackStart":1.96,"chipStackEnd":1.85,"totalPot":0.32,"timestamp":1794828292,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828289,"actionResponseTime":1794828292,"actionDuration":3000}],"playerActionRit":[],"playerActionEvchop":[]},"flop":{"potDetails":[1.38],"potDetailsDoubleboard":[],"equityDetails":[{"potId":0,"potAmount":1.38,"potUsers":[549489,1898374],"equityDetails":[{"userId":549489,"equityPercentage":91.62,"winPercentage":91.62,"tiePercentage":0,"winCount":-1,"tieCount":-1,"seatIndex":6},{"userId":1898374,"equityPercentage":8.38,"winPercentage":8.38,"tiePercentage":0,"winCount":-1,"tieCount":-1,"seatIndex":2}]}],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[{"position":"SB","username":"fomo27","userId":549489,"avatarId":1,"action":"ALLIN","newPlayerAction":"ALLIN","amount":0.53,"chipStackStart":0.53,"chipStackEnd":0,"totalPot":0.85,"timestamp":1794828298,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828292,"actionResponseTime":1794828298,"actionDuration":6000},{"position":"UTG","username":"PlottingRevenge","userId":1898374,"avatarId":1,"action":"CALL","newPlayerAction":"CALL","amount":0.53,"chipStackStart":1.85,"chipStackEnd":1.32,"totalPot":1.38,"timestamp":1794828301,"isAutoAction":false,"isFastFold":false,"actionInitTime":1794828298,"actionResponseTime":1794828301,"actionDuration":3000}],"playerActionRit":[{"username":"fomo27","userId":549489,"action":"RUN ONCE","timestamp":1794828306568,"evchopOfferTime":null}],"playerActionEvchop":[{"username":"PlottingRevenge","userId":1898374,"action":"REJECT","timestamp":1794828303645,"evchopOfferTime":1794828302050}]},"turn":{"potDetails":[1.38],"potDetailsDoubleboard ":[],"equityDetails":[{"potId":0,"potAmount":1.38,"potUsers":[549489,1898374],"equityDetails":[{"userId":549489,"equityPercentage":95.45,"winPercentage":95.45,"tiePercentage":0,"winCount":42,"tieCount":0,"seatIndex":6},{"userId":1898374,"equityPercentage":4.55,"winPercentage":4.55,"tiePercentage":0,"winCount":2,"tieCount":0,"seatIndex":2}]}],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"river":{"potDetails":[1.38],"potDetailsDoubleboard":[],"equityDetails":[{"potId":0,"potAmount":1.38,"potUsers":[549489,1898374],"equityDetails":[{"userId":549489,"equityPercentage":100,"winPercentage":100,"tiePercentage":0,"winCount":-1,"tieCount":-1,"seatIndex":6},{"userId":1898374,"equityPercentage":0,"winPercentage":0,"tiePercentage":0,"winCount":-1,"tieCount":-1,"seatIndex":2}]}],"equityDetailsRit":[],"equityDetailsRit2":[],"equityDetailsDoubleboard":[],"playerAction":[],"playerActionRit":[],"playerActionEvchop":[]},"showdown":{"muckedPlayers":[],"potDetails":[1.38],"potWinners":[{"potAmount":1.38,"potContestants":[549489,1898374,1714329],"winnerDetails":[{"userId":549489,"amount":1.31,"timestamp":1794828321,"winType":"TWO_PAIR"}]}],"potDetailsRit":[],"potWinnersRit":[],"potDetailsRit2":[],"potWinnersRit2":[],"potDetailsDoubleboard":[],"potWinnersDoubleboard":[]},"splashDetails":{"isSplashDrop":null,"isSplashIllusion":false,"isMegaSplash":false,"splashDropAmount":0,"splashCollectionAmount":0,"splashSharedBonusPercentage":0,"splashSharedAmount":0,"splashContestedAmount":0,"noUsersReceivingSharedBonus":0},"doubleBoardCards":[],"isDoubleBoard":0,"isBombPot":false,"bombAnte":0},"isRit":0,"tableCard":["heart_12","heart_4","diamond_4","club_7","club_9"],"tableCardRit":[],"tableCardRit2":[]},"handId":"178852800014","ante":0,"tableCards":["heart_12","heart_4","diamond_4","club_7","club_9"],"tableRit":0,"gameType":"GAME_STATS_CASH","tableCardRit2":[],"startDatetime":"2026-11-16 11:24:00","tableInfo":{"miniGameTypeId":"Holdem","tableId":202092,"isAnonymous":false,"tableChildId":1788528,"metadata":{"theme":null,"iconImage":null},"smallBlind":0.01,"bigBlind":0.02,"ante":0,"minBuyin":0.8,"maxBuyin":2,"playersPerTable":6,"tableType":"Public","miniGameTypeActualId":1,"isBombpotConfig":false,"isFixedhandBombpot":null,"isBombpot":false,"mustShowEnabled":false,"mixedGameVariant":null},"tournamentInfo":{}}]}} diff --git a/lesen/handverlauf.py b/lesen/handverlauf.py new file mode 100644 index 00000000..74a0a5ca --- /dev/null +++ b/lesen/handverlauf.py @@ -0,0 +1,206 @@ +"""Punkt 2 des Auftrags "Serverdaten nutzen": die Hand-Historie aus dem Replay-Dienst lesen. + +Quelle (BELEGT am Code des Hand-Replayers hrweb.coindeliveryservice.com, main.a753396d.js, und an +echten Antworten vom 16.11.2026): + + POST https://nxtgenapi./pbshots/handhistory/v4/replay + Authorization: Bearer + {"hand_id": "", "game_type": "zoompoker" | "aof" | "tournament"} (Cash heisst dort zoompoker) + +Antwort: `{"status":"success","response":{"data":[{...eine Hand...}]}}`. Je Hand: `tableInfo` +(Tisch, Blinds, Spielart), `tableCards` (Board), `handDetail.summary` (je Spieler Name, Kennung, +Position, Sitz, Stapel vorher/nachher, Einsatz, Gewinn, Karten, Muck) und `handDetail.details` +je Strasse (`ante/preflop/flop/turn/river`: `playerAction` mit Aktion, Betrag, Stapel, Denkzeit) +plus `showdown` (Pot-Gewinner). + +Was die Antwort NICHT verraet (gemessen an 22 Haenden): Karten, die am Tisch nicht gezeigt wurden. +Gefoldete und nicht gezeigte Haende stehen als `"folded"` - hier None, nie geraten. Was sie +verraet: JEDE Hand, nicht nur unsere (die Hand-Id ist `tableChildId` + fuenfstelliger Zaehler, +`hand_id`). Damit liegen Linien, Betraege, Denkzeiten und gezeigte Karten auch aus Haenden vor, in +denen wir nicht sassen. + +Aktion: `newPlayerAction` ist genauer als `action` (dort heisst auch die erste Wette nach dem Flop +RAISE); fehlt es, gilt `action`. ALLIN ist ohne Strassenstand weder sicher Erhoehung noch Mitgehen: +es zaehlt fuer VPIP (Geld freiwillig drin), aber weder fuer PFR noch fuer die Aggression. + +Abruf und Tischdurchlauf: werkzeuge/replay_scout.py. Beleg: archiv/mitschrieb/beispiele/replay.jsonl. +Spezifikation: tests/handverlauf_spec.py. (Name `handverlauf`, nicht `replay`: entscheiden/replay.py ist +der Engine-Replay-Benchmark und laege mit auf dem Pfad.) +""" +import json + +STRASSEN = ("preflop", "flop", "turn", "river") +FARBE = {"heart": "h", "diamond": "d", "club": "c", "spade": "s"} +RANG = {14: "A", 13: "K", 12: "Q", 11: "J", 10: "T"} +FREIWILLIG = ("CALL", "BET", "RAISE", "POT", "ALLIN") # Geld freiwillig in den Topf +ERHOEHT = ("BET", "RAISE", "POT") # sicher aggressiv +PASSIV = ("CALL", "CHECK") +ZWANG = ("SB", "BB", "ANTE", "STRADDLE") # Pflichteinsaetze, keine Entscheidung +KEINE_ENTSCHEIDUNG = ZWANG + ("RETURN",) # RETURN = ungecallter Rest zurueck + + +def hand_id(tisch_kind, zaehler): + """Die Hand-Id aus `tableChildId` und laufendem Zaehler (5 Stellen): 1787867, 265 -> '178786700265'.""" + return f"{int(tisch_kind)}{int(zaehler):05d}" + + +def zerlege_id(hid): + """(tableChildId, zaehler) aus einer Hand-Id - Umkehrung von `hand_id`.""" + s = str(hid) + return int(s[:-5]), int(s[-5:]) + + +def karte(roh): + """'heart_13' -> 'Kh'; 'folded', leer oder unlesbar -> None (nicht geraten).""" + if not isinstance(roh, str) or "_" not in roh: + return None + farbe, _, rang = roh.partition("_") + try: + r = int(rang) + except ValueError: + return None + if farbe not in FARBE or not 2 <= r <= 14: + return None + return RANG.get(r, str(r)) + FARBE[farbe] + + +def _karten(liste): + """Gezeigte Karten oder None, wenn auch nur eine fehlt ('folded').""" + ks = [karte(k) for k in (liste or [])] + return ks if ks and all(ks) else None + + +def _daten(antwort): + """Das Hand-Objekt aus Text, ganzer Antwort oder schon dem Datenelement - None, wenn keins.""" + if isinstance(antwort, (str, bytes)): + try: + antwort = json.loads(antwort) + except ValueError: + return None + if not isinstance(antwort, dict): + return None + if "handDetail" in antwort: + return antwort + daten = (antwort.get("response") or {}).get("data") or [] + return daten[0] if daten and isinstance(daten[0], dict) else None + + +def _aktion(a): + return a.get("newPlayerAction") or a.get("action") + + +def _sekunden(ms): + """`actionDuration` kommt in Millisekunden (5000 neben Unix-Sekunden in actionInitTime) -> Sekunden.""" + if isinstance(ms, bool) or not isinstance(ms, (int, float)): + return None + return ms / 1000.0 + + +def hand(antwort): + """Eine Hand, auf unsere Namen gebracht - None ohne lesbare Hand. + + {hand, typ, spielart, sb, bb, ante, tisch, tisch_kind, start, board, spieler, aktionen, gewinner} + spieler: {kennung: {name, sitz, position, stapel_start, stapel_ende, einsatz, ergebnis, + karten (None = nicht gezeigt), muck}} + aktionen: [{strasse, kennung, name, position, aktion, betrag, stapel_ende, topf, auto, + fastfold, dauer_s}] in Spielreihenfolge + gewinner: [{kennung, betrag, art}]""" + d = _daten(antwort) + if d is None: + return None + hd = d.get("handDetail") or {} + det = hd.get("details") or {} + ti = d.get("tableInfo") or {} + spieler = {} + for p in hd.get("summary") or []: + if p.get("userId") is None: + continue + spieler[str(p["userId"])] = { + "name": p.get("username"), "sitz": p.get("seatIndex"), "position": p.get("position"), + "stapel_start": p.get("chipStackStart"), "stapel_ende": p.get("chipStackEnd"), + "einsatz": p.get("totalBets"), "ergebnis": p.get("profitLoss"), + "karten": _karten(p.get("cards")), "muck": bool(p.get("isMuck")), + } + aktionen = [] + for strasse in ("ante",) + STRASSEN: + for a in (det.get(strasse) or {}).get("playerAction") or []: + aktionen.append({ + "strasse": strasse, "kennung": str(a["userId"]) if a.get("userId") is not None else None, + "name": a.get("username"), "position": a.get("position"), "aktion": _aktion(a), + "betrag": a.get("amount"), "stapel_ende": a.get("chipStackEnd"), "topf": a.get("totalPot"), + "auto": bool(a.get("isAutoAction")), "fastfold": bool(a.get("isFastFold")), + "dauer_s": _sekunden(a.get("actionDuration")), + }) + gewinner = [] + for pw in (det.get("showdown") or {}).get("potWinners") or []: + for w in pw.get("winnerDetails") or []: + gewinner.append({"kennung": str(w.get("userId")), "betrag": w.get("amount"), "art": w.get("winType")}) + return { + "hand": str(d.get("handId") or hd.get("handId")), "typ": d.get("type"), + "spielart": ti.get("miniGameTypeId"), "sb": ti.get("smallBlind"), "bb": ti.get("bigBlind"), + "ante": ti.get("ante"), "tisch": ti.get("tableId"), "tisch_kind": ti.get("tableChildId"), + "start": d.get("startDatetime"), + "board": [k for k in (karte(x) for x in d.get("tableCards") or []) if k], + "spieler": spieler, "aktionen": aktionen, "gewinner": gewinner, + } + + +def haende(text): + """Alle Haende aus einer Datei mit einer Antwort je Zeile (jsonl) - doppelte Hand-Ids einmal.""" + raus, gesehen = [], set() + for zeile in (text or "").splitlines(): + h = hand(zeile.strip()) if zeile.strip() else None + if h and h["hand"] not in gesehen: + gesehen.add(h["hand"]) + raus.append(h) + return raus + + +def je_gegner(haende_liste, ohne=None): + """{kennung: Zusammenfassung} ueber alle Haende - die Gegneransicht des Replay-Scouts. + + Je Spieler: name, haende, vpip/pfr (Anteil der Haende), aggression nach dem Flop + (BET/RAISE/POT unter BET/RAISE/POT/CALL/CHECK - None ohne solchen Zug, mit `aggression_zuege` + als Stichprobe), showdowns (Haende mit gezeigten Karten), gezeigt (die Karten samt Board), + ergebnis (Summe profitLoss) und denkzeit_s (Mittel der eigenen, nicht automatischen Zuege). + `ohne` = unsere Kennung oder unser Name, die fallen raus.""" + roh = {} + for h in haende_liste or (): + for kennung, p in h["spieler"].items(): + if ohne is not None and str(ohne) in (kennung, p["name"]): + continue + s = roh.setdefault(kennung, {"name": p["name"], "haende": 0, "vpip_n": 0, "pfr_n": 0, "aggr": 0, + "zuege": 0, "showdowns": 0, "gezeigt": [], "ergebnis": 0.0, + "dauer": []}) + s["name"] = p["name"] or s["name"] + s["haende"] += 1 + eigene = [a for a in h["aktionen"] if a["kennung"] == kennung] + vor = [a["aktion"] for a in eigene if a["strasse"] == "preflop"] + s["vpip_n"] += any(x in FREIWILLIG for x in vor) + s["pfr_n"] += any(x in ERHOEHT for x in vor) + for a in eigene: + if a["strasse"] in STRASSEN[1:]: + if a["aktion"] in ERHOEHT: + s["aggr"] += 1 + s["zuege"] += 1 + elif a["aktion"] in PASSIV: + s["zuege"] += 1 + if not a["auto"] and a["aktion"] not in KEINE_ENTSCHEIDUNG and isinstance(a["dauer_s"], (int, float)): + s["dauer"].append(a["dauer_s"]) + if p["karten"]: + s["showdowns"] += 1 + s["gezeigt"].append({"hand": h["hand"], "karten": p["karten"], "board": h["board"]}) + if isinstance(p["ergebnis"], (int, float)): + s["ergebnis"] += p["ergebnis"] + aus = {} + for kennung, s in roh.items(): + n = s["haende"] + aus[kennung] = { + "name": s["name"], "haende": n, + "vpip": round(s["vpip_n"] / n, 3), "pfr": round(s["pfr_n"] / n, 3), + "aggression": round(s["aggr"] / s["zuege"], 3) if s["zuege"] else None, + "aggression_zuege": s["zuege"], "showdowns": s["showdowns"], "gezeigt": s["gezeigt"], + "ergebnis": round(s["ergebnis"], 2), + "denkzeit_s": round(sum(s["dauer"]) / len(s["dauer"]), 2) if s["dauer"] else None, + } + return aus diff --git a/tests/handverlauf_spec.py b/tests/handverlauf_spec.py new file mode 100644 index 00000000..39683a6d --- /dev/null +++ b/tests/handverlauf_spec.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +"""Punkt 2: die Hand-Historie aus dem Replay-Dienst (lesen/handverlauf.py) + Tischdurchlauf +(werkzeuge/replay_scout.py). + +Beleg WOERTLICH (archiv/mitschrieb/beispiele/replay.jsonl): drei echte Antworten von +`POST /pbshots/handhistory/v4/replay` vom 16.11.2026, eine je Zeile; nur `sessionId` und +`referenceNumber` der Spieler sind geschwaerzt. Darin: + 178786700265 - unsere Hand (accurate5604516, BB), Fold-around nach Raise von vickey, kein Board + 178698900637 - ohne uns, Showdown: Chaniii Kh7h schlaegt Raminjeni 7s5h auf 3c4d8dAsAh + 178852800014 - ohne uns, PlottingRevenge 8s8c gegen fomo27 KdKh, Flop-All-in + +Geprueft wird, was die Antwort hergibt (Linien, Betraege, Denkzeit in Sekunden, gezeigte Karten) +und was sie NICHT hergibt: nicht gezeigte Karten bleiben None (`"folded"`), nie geraten. + + python3 tests/handverlauf_spec.py -v +""" +import os +import sys +import unittest + +_w = os.path.dirname(os.path.abspath(__file__)) +while _w != "/" and not os.path.isdir(os.path.join(_w, "lesen")): + _w = os.path.dirname(_w) +sys.path.append(os.path.join(_w, "lesen")) +sys.path.append(os.path.join(_w, "werkzeuge")) +import handverlauf as R +import replay_scout as SC + +BELEG = os.path.join(_w, "archiv", "mitschrieb", "beispiele", "replay.jsonl") +TEXT = open(BELEG, encoding="utf-8").read() +HAENDE = {h["hand"]: h for h in R.haende(TEXT)} +ICH = "accurate5604516" + + +class Karten(unittest.TestCase): + def test_umrechnung(self): + self.assertEqual(R.karte("heart_13"), "Kh") + self.assertEqual(R.karte("spade_14"), "As") + self.assertEqual(R.karte("club_10"), "Tc") + self.assertEqual(R.karte("diamond_2"), "2d") + + def test_nicht_gezeigt_ist_none(self): + self.assertIsNone(R.karte("folded")) + self.assertIsNone(R.karte("")) + self.assertIsNone(R.karte("heart_1")) + + +class Hand(unittest.TestCase): + def test_drei_haende(self): + self.assertEqual(sorted(HAENDE), ["178698900637", "178786700265", "178852800014"]) + + def test_tisch_und_blinds(self): + h = HAENDE["178786700265"] + self.assertEqual((h["typ"], h["spielart"], h["sb"], h["bb"]), ("cash", "Holdem", 0.01, 0.02)) + self.assertEqual(h["tisch_kind"], 1787867) + self.assertEqual(h["board"], []) + + def test_showdown_karten_und_board(self): + h = HAENDE["178698900637"] + self.assertEqual(h["board"], ["3c", "4d", "8d", "As", "Ah"]) + self.assertEqual(h["spieler"]["1860388"]["karten"], ["Kh", "7h"]) # Chaniii + self.assertEqual(h["spieler"]["1914418"]["karten"], ["7s", "5h"]) # Raminjeni + self.assertEqual(h["gewinner"], [{"kennung": "1860388", "betrag": 0.17, "art": "ONE_PAIR"}]) + + def test_gefoldete_karten_bleiben_unbekannt(self): + """Wer nicht zeigt, hat keine Karten im Replay - auch wir nicht.""" + h = HAENDE["178786700265"] + self.assertTrue(all(p["karten"] is None for p in h["spieler"].values())) + self.assertIsNone(HAENDE["178698900637"]["spieler"]["403486"]["karten"]) # w1zz, Fold + + def test_aktionen_in_reihenfolge(self): + h = HAENDE["178852800014"] + kurz = [(a["strasse"], a["name"], a["aktion"], a["betrag"]) for a in h["aktionen"]] + self.assertEqual(kurz[0], ("preflop", "fomo27", "SB", 0.01)) + self.assertEqual(kurz[2], ("preflop", "PlottingRevenge", "RAISE", 0.04)) + self.assertEqual(kurz[6], ("preflop", "fomo27", "RAISE", 0.14)) + self.assertEqual(kurz[-2:], [("flop", "fomo27", "ALLIN", 0.53), ("flop", "PlottingRevenge", "CALL", 0.53)]) + + def test_denkzeit_in_sekunden(self): + """actionDuration kommt in Millisekunden (13000) - im Leser Sekunden.""" + a = HAENDE["178852800014"]["aktionen"][6] + self.assertEqual(a["dauer_s"], 13.0) + + def test_ergebnis_je_spieler(self): + sp = HAENDE["178852800014"]["spieler"] + self.assertEqual(sp["1898374"]["ergebnis"], -0.68) + self.assertEqual(sp["549489"]["ergebnis"], 0.63) + + def test_kaputtes_bleibt_none(self): + self.assertIsNone(R.hand("kein json")) + self.assertIsNone(R.hand({"status": "success", "response": {"data": []}})) + self.assertEqual(R.haende(""), []) + + +class JeGegner(unittest.TestCase): + def setUp(self): + self.g = R.je_gegner(list(HAENDE.values()), ohne=ICH) + + def test_wir_fallen_raus(self): + self.assertNotIn("1538517", self.g) + self.assertEqual(len(self.g), 14) + + def test_spieler_ueber_zwei_haende(self): + p = self.g["1898374"] # PlottingRevenge: Fold in 637, Raise/Call in 014 + self.assertEqual((p["haende"], p["vpip"], p["pfr"]), (2, 0.5, 0.5)) + self.assertEqual((p["aggression"], p["aggression_zuege"]), (0.0, 1)) # Flop-Call + self.assertEqual(p["gezeigt"][0]["karten"], ["8s", "8c"]) + self.assertEqual(p["ergebnis"], -0.68) + self.assertEqual(p["denkzeit_s"], 2.0) # (0 + 2 + 3 + 3) / 4 + + def test_allin_zaehlt_nicht_als_aggression(self): + p = self.g["549489"] # fomo27: Raise vorflop, ALLIN auf dem Flop + self.assertEqual((p["vpip"], p["pfr"]), (1.0, 1.0)) + self.assertIsNone(p["aggression"]) + self.assertEqual(p["denkzeit_s"], 9.5) # (13 + 6) / 2, SB ist Pflicht + + def test_passiver_showdown(self): + p = self.g["1860388"] # Chaniii: Call vorflop, dreimal Check + self.assertEqual((p["vpip"], p["pfr"], p["aggression"], p["aggression_zuege"]), (1.0, 0.0, 0.0, 3)) + self.assertEqual(p["showdowns"], 1) + + def test_return_ist_keine_entscheidung(self): + self.assertEqual(self.g["575985"]["denkzeit_s"], 7.0) # vickey: Raise 7 s, RETURN zaehlt nicht + + +class Scout(unittest.TestCase): + def test_hand_id_aus_tisch_und_zaehler(self): + self.assertEqual(R.hand_id(1787867, 265), "178786700265") + self.assertEqual(R.zerlege_id("178786700265"), (1787867, 265)) + + def test_bereich(self): + self.assertEqual(SC.bereich(1787867, 263, 265), ["178786700263", "178786700264", "178786700265"]) + + def test_bereich_hat_deckel(self): + self.assertEqual(len(SC.bereich(1787867, 1, 10_000)), SC.HOECHSTENS) + + def test_anfrage_wie_der_replayer(self): + url, koerper = SC.anfrage("178786700265", "educationsacademy.com") + self.assertEqual(url, "https://nxtgenapi.educationsacademy.com/pbshots/handhistory/v4/replay") + self.assertEqual(koerper, {"hand_id": "178786700265", "game_type": "zoompoker"}) + + def test_bericht_ohne_netz(self): + """Der Bericht entsteht aus schon geholten Antworten - kein Abruf noetig.""" + zeilen = SC.bericht(R.haende(TEXT), ohne=ICH) + self.assertTrue(any("PlottingRevenge" in z and "8s8c" in z for z in zeilen)) + self.assertFalse(any(ICH in z for z in zeilen)) + + +if __name__ == "__main__": + unittest.main(verbosity=2) diff --git a/werkzeuge/replay_scout.py b/werkzeuge/replay_scout.py new file mode 100644 index 00000000..5fc6c3e0 --- /dev/null +++ b/werkzeuge/replay_scout.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 +"""Replay-Scout (Punkt 2): Tisch -> Haende -> Zusammenfassung je Gegner, aus dem Replay-Dienst. + +Holt Haende ueber denselben Aufruf wie der Hand-Replayer des Clients (lesen/handverlauf.py, +belegt am Replayer-Code): `POST https://nxtgenapi./pbshots/handhistory/v4/replay` mit +`{"hand_id", "game_type": "zoompoker"}` und dem Firebase-Token des laufenden Clients +(lesen/raumliste.token_aus_client). Nur LESEN - kein Schreibbefehl. + +Der Dienst liefert JEDE Hand, nicht nur unsere: die Hand-Id ist `tableChildId` + Zaehler, ein +Tisch laesst sich also der Reihe nach durchgehen (`--tisch`). Darum vorsichtig: hoechstens +HOECHSTENS Abrufe je Lauf, PAUSE_S zwischen zweien, Abbruch nach zwei Ablehnungen in Folge. + + python3 werkzeuge/replay_scout.py --log [--anzahl 30] # unsere letzten Haende (Client-Log) + python3 werkzeuge/replay_scout.py --tisch 1787867 --von 200 --bis 265 + python3 werkzeuge/replay_scout.py --datei archiv/mitschrieb/beispiele/replay.jsonl # ohne Netz + dazu: [--ohne accurate5604516] [--ablage archiv/replay/antworten.jsonl] [--json] + +Die Rohantworten landen (geschwaerzt: sessionId/referenceNumber) zeilenweise in `--ablage`; +spaetere Laeufe lesen sie mit `--datei` ohne neuen Abruf. Ohne Engine, laeuft headless. +""" +import json +import os +import re +import sys +import time +import urllib.error +import urllib.request + +_w = os.path.dirname(os.path.abspath(__file__)) +while _w != os.path.dirname(_w) and not os.path.isdir(os.path.join(_w, "lesen")): + _w = os.path.dirname(_w) +WURZEL = _w +if os.path.join(_w, "lesen") not in sys.path: + sys.path.insert(0, os.path.join(_w, "lesen")) +import handverlauf + +PFAD = "/pbshots/handhistory/v4/replay" +SPIELART = "zoompoker" # so nennt der Replayer Cash-Ringspiele (aof / tournament sonst) +HOECHSTENS = 200 # Abrufe je Lauf +PAUSE_S = 0.6 # zwischen zwei Abrufen +GESCHWAERZT = ("sessionId", "referenceNumber") +ABLAGE = os.path.join(WURZEL, "archiv", "replay", "antworten.jsonl") + + +def anfrage(hid, domaene): + """(url, koerper) - genau wie der Replayer (COINPOKER_APP_REPLAYER_API_URL, game_type).""" + return f"https://nxtgenapi.{domaene}{PFAD}", {"hand_id": str(hid), "game_type": SPIELART} + + +def bereich(tisch_kind, von, bis): + """Hand-Ids eines Tischs von Zaehler `von` bis `bis` (einschliesslich), hoechstens HOECHSTENS.""" + return [handverlauf.hand_id(tisch_kind, z) for z in range(int(von), int(bis) + 1)][:HOECHSTENS] + + +def aus_log(pfad, anzahl=30): + """Die letzten `anzahl` Hand-Ids aus dem Client-Log (neueste zuerst, ohne Dubletten).""" + text = open(pfad, encoding="utf-8", errors="replace").read() + ids = list(dict.fromkeys(re.findall(r'HandId[\\"]*:[\\"]*(\d{9,})', text))) + return ids[-anzahl:][::-1] + + +def schwaerzen(o): + """Sitzungsschluessel anderer Spieler raus, bevor eine Antwort abgelegt wird.""" + if isinstance(o, dict): + return {k: ("" if k in GESCHWAERZT else schwaerzen(v)) for k, v in o.items()} + if isinstance(o, list): + return [schwaerzen(v) for v in o] + return o + + +def holen(hid, token): + """(status, text) einer Hand - ueber die erste Domaene, die nicht ablehnt; (None, grund) sonst.""" + import raumliste + letzter = (None, "keine Domaene erreichbar") + for d in raumliste.DOMAENEN: + url, koerper = anfrage(hid, d) + req = urllib.request.Request(url, data=json.dumps(koerper).encode(), headers={ + "content-type": "application/json", "accept": "application/json", + "user-agent": raumliste.UA, "authorization": "Bearer " + token}) + try: + r = urllib.request.urlopen(req, timeout=25) + return r.status, r.read().decode("utf-8", "replace") + except urllib.error.HTTPError as e: + letzter = (e.code, e.read().decode("utf-8", "replace")[:200]) + if e.code in (403, 430): + continue + return letzter + except (urllib.error.URLError, TimeoutError, OSError) as e: + letzter = (None, repr(e)[:120]) + return letzter + + +def abrufen(ids, ablage=ABLAGE, token=None, pause=PAUSE_S): + """Holt die Haende, legt sie geschwaerzt ab und gibt die gelesenen Haende zurueck.""" + import raumliste + token = token or raumliste.token_aus_client() + if not token: + print("kein Token - laeuft der Client?", file=sys.stderr) + return [] + os.makedirs(os.path.dirname(ablage), exist_ok=True) + raus, abgelehnt = [], 0 + for n, hid in enumerate(ids[:HOECHSTENS]): + if n: + time.sleep(pause) + status, text = holen(hid, token) + h = handverlauf.hand(text) if status == 200 else None + if h is None: + abgelehnt += 1 + print(f"{hid}: {status} {str(text)[:100]}", file=sys.stderr) + if abgelehnt >= 2: + print("zwei Ablehnungen in Folge - Abbruch", file=sys.stderr) + break + continue + abgelehnt = 0 + with open(ablage, "a", encoding="utf-8", newline="\n") as f: + f.write(json.dumps(schwaerzen(json.loads(text)), ensure_ascii=False, separators=(",", ":")) + "\n") + raus.append(h) + return raus + + +def bericht(haende, ohne=None): + """Textzeilen: je Gegner Haende, VPIP/PFR, Aggression, Showdowns samt Karten, Ergebnis, Denkzeit.""" + g = handverlauf.je_gegner(haende, ohne=ohne) + zeilen = [f"{len(haende)} Haende, {len(g)} Gegner", + f"{'Name':<18}{'H':>4}{'VPIP':>6}{'PFR':>6}{'Aggr':>6}{'SD':>4}{'Ergebnis':>10}{'Denk s':>8} gezeigt"] + for k, p in sorted(g.items(), key=lambda kv: (-kv[1]["haende"], kv[1]["name"] or "")): + aggr = "-" if p["aggression"] is None else f"{p['aggression']:.2f}" + denk = "-" if p["denkzeit_s"] is None else f"{p['denkzeit_s']:.1f}" + gezeigt = " ".join("".join(s["karten"]) for s in p["gezeigt"]) + zeilen.append(f"{(p['name'] or k)[:17]:<18}{p['haende']:>4}{p['vpip']:>6.2f}{p['pfr']:>6.2f}" + f"{aggr:>6}{p['showdowns']:>4}{p['ergebnis']:>10.2f}{denk:>8} {gezeigt}") + return zeilen + + +def _wert(argv, schalter, vorgabe=None): + return argv[argv.index(schalter) + 1] if schalter in argv else vorgabe + + +def main(argv): + ohne = _wert(argv, "--ohne") + if "--datei" in argv: + haende = handverlauf.haende(open(_wert(argv, "--datei"), encoding="utf-8").read()) + else: + if "--tisch" in argv: + ids = bereich(_wert(argv, "--tisch"), _wert(argv, "--von", 1), _wert(argv, "--bis", 50)) + elif "--log" in argv: + sys.path.insert(0, os.path.join(WURZEL, "client")) + import umgebung + ids = aus_log(umgebung.CLIENT_LOG, int(_wert(argv, "--anzahl", 30))) + else: + print(__doc__) + return 2 + haende = abrufen(ids, ablage=_wert(argv, "--ablage", ABLAGE)) + if "--json" in argv: + print(json.dumps(handverlauf.je_gegner(haende, ohne=ohne), ensure_ascii=False, indent=1)) + else: + print("\n".join(bericht(haende, ohne=ohne))) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:]))