Files
pokerfreak/messung/limits/vergleich.py
T
mmintelandClaude Opus 5.5 02c70857d5 Motor: Messregister, Karten, Batterie, Beute, Orakel-Werkzeuge, robust.rs, Regeln decke/abbruch
Sichert den bisher ungetrackten Stand der Hauptkopie: Messregister (register.py,
REGISTER.md, KARTE-vorlage mit Pflichtfeldern decke und abbruch), Karten und
Auswerteskripte aller Motor-Messungen, Pruefbatterie und Beute-Auswertungen
(nur anonyme Summen), robust.rs, PLAN-motor (Leck-Orakel, frequenz-gebundene
Loesung, Tor-Klassen und Sammelkorb), CLAUDE.md-Regel "kein Lauf tiefer als noetig".
Grosse Rohdaten (*.bin, *.jsonl, Logs, archiv/lauf) bleiben draussen; Kopie
unter pokerfreak-daten/sicherung-2026-11-27-hauptkopie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 19:45:29 +01:00

168 lines
8.6 KiB
Python

import sys,re,glob,io,zipfile,collections,random,ctypes
import numpy as np
sys.stdout.reconfigure(encoding='utf-8')
D='D:/Projects/pokerfreak-daten/'
A=r'₮([\d.,]+)'
K=re.compile(r"CoinPoker Hand #(\d+):.*?\(₮([\d.]+)/₮([\d.]+)(?: - Ante ₮([\d.]+)[^)]*)?\) - (\S+)")
S=re.compile(r'^Seat (\d+): (.+) \('+A+' in chips\)')
P=re.compile(r'^(.+?): (posts the ante|posts small blind|posts big blind|posts straddle|posts|calls|bets|raises|checks|folds)(?: '+A+r')?(?: to '+A+')?')
f=lambda s:float(s.replace(',',''))
own={x.strip() for x in open(D+'hhdealer/eigener_name.txt',encoding='utf-8')}
def new(): return dict(p=collections.defaultdict(lambda:collections.defaultdict(lambda:[0,0.])),h=collections.defaultdict(list),n=0,tab=set(),seen=set(),rej=collections.Counter())
def hand(z,G):
m=K.match(z[0])
if not m: G['rej']['kopf']+=1;return
hid,bb=m[1],float(m[3]);ante=float(m[4] or 0)/bb
if hid in G['seen']: return
G['seen'].add(hid)
if '6-max' not in z[1]: G['rej']['not6']+=1;return
seats={}
for l in z[2:]:
s=S.match(l)
if s: seats[s[2]]=f(s[3])/bb
elif l.startswith('***'):break
st=0;con=collections.Counter();pot=0;cur=0;lvl=0;fold=set();bbn=sbn=None;pfr=None;opener=None;limp=0;checked=set();wonl=collections.Counter();shown=set();tp=rk=0;strad=False;firstbet=None;sawf=None;riverag=None
ev=[];vp=set();pf=set();acted=set()
def e(p,k,v): ev.append((p,k,v))
for l in z[2:]:
if l.startswith('*** '):
if l[4:8] in('FLOP','TURN','RIVE'):
st={'F':1,'T':2,'R':3}[l[4]];cur=0;con=collections.Counter();firstbet=None;checked=set();lvl=0
if st==1:sawf=set(seats)-fold
elif l.startswith('*** SHOW'):st=4
elif l.startswith('*** SUMM'):st=5
continue
if st==5:
t=re.match('Total pot '+A+r' \| Rake '+A,l)
if t: tp,rk=f(t[1])/bb,f(t[2])/bb
continue
if l.startswith('Uncalled'): continue
t=re.match('^(.+) collected '+A,l)
if t: wonl[t[1]]+=f(t[2])/bb;continue
t=re.match(r'^(.+?): shows \[',l)
if t: shown.add(t[1]);continue
m=P.match(l)
if not m or m[1] not in seats: continue
p,a=m[1],m[2];x=f(m[3])/bb if m[3] else 0;to=f(m[4])/bb if m[4] else 0
if a.startswith('posts'):
if a=='posts the ante': pot+=x;continue
if a in('posts straddle','posts'): strad=True
if a=='posts big blind': bbn=p
if a=='posts small blind': sbn=p
con[p]+=x;pot+=x;cur=max(cur,con[p]);continue
if st==0:
if p not in acted:
if lvl==0 and limp==0 and p!=bbn:
e(p,'RFI',a=='raises');e(p,'LIMP',a=='calls')
i=len(acted);e(p,'RFI_SB' if p==sbn else 'RFI_rest',a=='raises')
if lvl==1: e(p,'3BET',a=='raises');e(p,'CALLOPEN',a=='calls')
if lvl==1 and p==bbn and limp==0: e(p,'BBFOLD',a=='folds')
if lvl==0 and limp>0 and p!=bbn: e(p,'ISO',a=='raises')
elif lvl==2 and p==opener: e(p,'FOLD3B',a=='folds');e(p,'4BET',a=='raises')
if a in('calls','raises'): vp.add(p)
if a=='raises':
if lvl==0:
opener=p
if limp==0: e(p,'OPENSIZE',to)
if lvl==1: e(p,'3BSIZE',to/cur)
lvl+=1;pf.add(p);pfr=p
if a=='calls' and lvl==0: limp+=1
else:
s='FTR'[st-1];hu='HU' if len(sawf)==2 else 'MW'
if cur==0:
e(p,s+'BET',a=='bets')
if st==1 and p==pfr: e(p,'CBET'+hu,a=='bets')
if st==1 and p!=pfr and hu=='HU' and pfr in sawf and pfr not in checked: e(p,'DONK',a=='bets')
if a=='bets':
r=x/pot if pot else 0
e(p,s+'SIZE',min(r,3)); e(p,s+'OVB',r>1.0)
firstbet=(p,r);lvl=1
if st==3: riverag=p
else:
if lvl==1 and firstbet and p!=firstbet[0]:
r=firstbet[1];b='S' if r<.4 else 'M' if r<.8 else 'L'
e(p,s+'FOLD',a=='folds');e(p,s+'FOLD'+b,a=='folds');e(p,s+'RAISE',a=='raises')
if len(sawf)==2:e(p,s+'FOLD_HU',a=='folds')
if st==1 and firstbet[0]==pfr and hu=='HU': e(p,'FCB_HU',a=='folds')
if p in checked: e(p,'XR',a=='raises')
elif lvl>=2 and firstbet and p==firstbet[0]: e(p,'FOLDTORAISE',a=='folds')
if a=='raises':
lvl+=1
if st==3: riverag=p
if a in('bets','raises','calls'): e(p,'AGG',a!='calls')
if a=='checks': checked.add(p)
if a=='folds': fold.add(p)
if a in('calls','bets'): con[p]+=x;pot+=x;cur=max(cur,con[p])
if a=='raises': pot+=to-con[p];con[p]=to;cur=max(cur,to)
acted.add(p)
if strad: G['rej']['straddle/post']+=1;return
if len(seats)<5: G['rej']['<5 Spieler']+=1;return
if not acted: return
G['n']+=1;G['tab'].add(z[1].split("'")[1])
for p in seats:
if p==bbn and p not in acted: continue
e(p,'VPIP',p in vp);e(p,'PFR',p in pf)
if sawf and p in sawf: e(p,'WTSD',p not in fold and len(set(seats)-fold)>1)
if len(shown)>1:
for p in shown:
if p in sawf if sawf else False: e(p,'WSD',wonl[p]>0)
if p==riverag: e(p,'RIVBETWIN',wonl[p]>0)
for p,k,v in ev:
if p in own: continue
q=G['p'][p][k];q[0]+=1;q[1]+=float(v)
H=G['h'];H['stack'].append(np.median(list(seats.values())));H['deep150+'].append(np.mean([s>=150 for s in seats.values()]));H['short<60'].append(np.mean([s<60 for s in seats.values()]))
H['rake'].append(rk);H['pot'].append(tp);H['npl'].append(len(seats));H['ante'].append(ante);H['anteJa'].append(ante>0)
H['flop'].append(sawf is not None);H['mwflop'].append(len(sawf)>2 if sawf else np.nan)
def text(t,G):
z=[]
for l in t.lstrip('\ufeff').splitlines()+['CoinPoker Hand #']:
if l.startswith('CoinPoker Hand #'):
if len(z)>4: hand(z,G)
z=[]
l=l.strip()
if l: z.append(l)
R=collections.OrderedDict()
zf=zipfile.ZipFile(D+'hhdealer/zip/nl2-6max-1jahr.zip');days=sorted(zf.namelist())
R['NL2']=G=new()
for d in days[-60::8]:
y=zipfile.ZipFile(io.BytesIO(zf.read(d)))
for n in y.namelist(): text(y.read(n).decode('utf8','replace'),G)
print('NL2',d,G['n'],dict(G['rej']),file=sys.stderr,flush=True)
for L in ['NL25','NL50','NL100','NL200','NL500','NL1000','NL2000','NL5000']:
R[L]=G=new()
for x in glob.glob(D+'sammler/%s/*.txt'%L): text(open(x,encoding='utf-8').read(),G)
def merge(ls):
G=new()
for l in ls:
g=R[l];G['n']+=g['n'];G['tab']|=g['tab']
for p,q in g['p'].items():
for k,v in q.items(): G['p'][p][k][0]+=v[0];G['p'][p][k][1]+=v[1]
for k,v in g['h'].items():G['h'][k]+=v
return G
R['NL25-50']=merge(['NL25','NL50']);R['NL100-200']=merge(['NL100','NL200']);R['NL500+']=merge(['NL500','NL1000','NL2000','NL5000'])
for k,G in R.items():
top=sorted((q['VPIP'][0] for q in G['p'].values()),reverse=True)
print(k,'Haende',G['n'],'Spieler',len(G['p']),'Tische',len(G['tab']),'Top5-Anteil %.0f%%'%(100*sum(top[:5])/max(1,sum(top))),'rej',dict(G['rej']),{a:round(float(np.nanmean(b)),2) for a,b in G['h'].items()},'rake%%Topf %.1f'%(100*sum(G['h']['rake'])/max(1e-9,sum(G['h']['pot']))),'medpot %.1f'%(np.median(G['h']['pot']) if G['n'] else 0))
fz=[(q['VPIP'][0],q['VPIP'][1]/q['VPIP'][0]) for q in G['p'].values() if q['VPIP'][0]>=50]
t=sum(a for a,_ in fz) or 1
print(' Spieler>=50H:',len(fz),'Sitzanteil VPIP<20 %.0f 20-28 %.0f 28-40 %.0f >40 %.0f'%tuple(100*sum(a for a,v in fz if lo<=v<hi)/t for lo,hi in((0,.2),(.2,.28),(.28,.4),(.4,2))))
def rs(G,k):
v=np.array([q[k] for q in G['p'].values() if k in q and q[k][0]],float)
if len(v)<3: return None
n,s=v.sum(0);r=s/n;se=np.sqrt(((v[:,1]-r*v[:,0])**2).sum()*len(v)/(len(v)-1))/n
return r,se,int(n)
ks=sorted({k for G in R.values() for q in G['p'].values() for k in q})
for cols in (['NL2','NL25','NL50','NL100','NL200'],['NL2','NL25-50','NL100-200','NL500+']):
print('\n'+'stat'.ljust(11)+''.join(c.rjust(26) for c in cols))
for k in ks:
b=rs(R['NL2'],k);o=k.ljust(11)
for c in cols:
r=rs(R[c],k)
if r is None: o+='-'.rjust(26);continue
mul=1 if 'SIZE' in k else 100
z=(r[0]-b[0])/np.hypot(r[1],b[1]) if b else 0
o+=('%.2f±%.2f n%d z%+.1f'%(r[0]*mul,1.96*r[1]*mul,r[2],z)).rjust(26)
print(o)
hi=set().union(*[set(R[l]['p']) for l in list(R)[1:9]])
print('Namen in NL2-Stichprobe und oben:',len(hi&set(R['NL2']['p'])),'von',len(hi))