Files

136 lines
3.5 KiB
Python
Raw Permalink Normal View History

2026-03-27 13:49:27 +00:00
#!/usr/bin/env python
2026-03-27 13:56:48 +00:00
#!/usr/bin/env python3
2026-03-27 13:48:33 +00:00
import sys
import subprocess
2026-03-27 13:56:48 +00:00
import re
from datetime import datetime
2026-03-27 13:48:33 +00:00
# === AUTO INSTALL ===
2026-03-27 13:56:48 +00:00
def ensure(pkg):
2026-03-27 13:48:33 +00:00
try:
__import__(pkg)
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", pkg])
2026-03-27 13:56:48 +00:00
ensure("pandas")
ensure("matplotlib")
2026-03-27 13:48:33 +00:00
import pandas as pd
import matplotlib.pyplot as plt
# === ARGS ===
if len(sys.argv) < 2:
print("Usage: python script.py input.txt [output.csv]")
sys.exit(1)
2026-03-27 13:56:48 +00:00
INPUT = sys.argv[1]
OUTPUT = sys.argv[2] if len(sys.argv) > 2 else "poker_clean.csv"
2026-03-27 13:48:33 +00:00
# === HELPERS ===
2026-03-27 13:56:48 +00:00
def money(x):
if not x or x.strip() in ["-", ""]:
2026-03-27 13:48:33 +00:00
return 0.0
2026-03-27 13:56:48 +00:00
return float(x.replace("", "").replace(",", ".").strip())
2026-03-27 13:48:33 +00:00
2026-03-27 13:56:48 +00:00
def category(name):
2026-03-27 13:48:33 +00:00
n = name.lower()
2026-03-27 13:56:48 +00:00
if "freeroll" in n: return "freeroll"
if "nitro" in n: return "nitro"
2026-03-27 13:48:33 +00:00
return "expresso"
2026-03-27 13:56:48 +00:00
def stake(b):
2026-03-27 13:48:33 +00:00
return "micro" if b <= 1 else "low" if b <= 5 else "mid" if b <= 20 else "high"
2026-03-27 13:56:48 +00:00
def session(h):
if 6 <= h < 12: return "morning"
if 12 <= h < 18: return "afternoon"
if 18 <= h < 24: return "evening"
return "night"
2026-03-27 13:48:33 +00:00
# === PARSE ===
rows = []
2026-03-27 13:56:48 +00:00
errors = 0
2026-03-27 13:48:33 +00:00
2026-03-27 13:56:48 +00:00
with open(INPUT, encoding="utf-8") as f:
2026-03-27 13:48:33 +00:00
for line in f:
2026-03-27 13:56:48 +00:00
raw = line.strip()
if not raw:
2026-03-27 13:48:33 +00:00
continue
2026-03-27 13:56:48 +00:00
parts = re.split(r"\s{2,}", raw)
2026-03-27 13:48:33 +00:00
try:
2026-03-27 13:56:48 +00:00
# DEBUG FIRST RUN ONLY (comment after)
# print(parts)
2026-03-27 13:48:33 +00:00
dt = datetime.strptime(parts[0], "%d/%m/%Y %H:%M:%S")
name = parts[1]
2026-03-27 13:56:48 +00:00
buy = float(parts[2]) if len(parts) > 2 else 0.0
players = int(parts[5]) if len(parts) > 5 and parts[5].isdigit() else None
2026-03-27 13:48:33 +00:00
2026-03-27 13:56:48 +00:00
pos = parts[6] if len(parts) > 6 and parts[6] != "-" else None
prize = money(parts[7]) if len(parts) > 7 else 0.0
net = money(parts[8]) if len(parts) > 8 else 0.0
2026-03-27 13:48:33 +00:00
profit = net - buy
2026-03-27 13:56:48 +00:00
h = dt.hour
2026-03-27 13:48:33 +00:00
rows.append({
"datetime": dt,
"game": name,
"buy_in": buy,
"players": players,
"position": pos,
"prize": prize,
"net": net,
"profit": profit,
2026-03-27 13:56:48 +00:00
"category": category(name),
"stake": stake(buy),
"hour": h,
2026-03-27 13:48:33 +00:00
"day": dt.strftime("%A"),
2026-03-27 13:56:48 +00:00
"session": session(h),
2026-03-27 13:48:33 +00:00
"result": "win" if pos == "1" else "itm" if prize > 0 else "loss"
})
except Exception as e:
2026-03-27 13:56:48 +00:00
errors += 1
if errors < 5:
print("Skip:", raw)
print("Reason:", e)
# === VALIDATION ===
if not rows:
print("❌ No valid rows parsed. Your format is different. Enable debug print.")
sys.exit(1)
df = pd.DataFrame(rows)
if "datetime" not in df.columns:
print("❌ Broken parse. Columns:", df.columns)
sys.exit(1)
2026-03-27 13:48:33 +00:00
2026-03-27 13:56:48 +00:00
# === PROCESS ===
df = df.sort_values("datetime")
2026-03-27 13:48:33 +00:00
df["cum_profit"] = df["profit"].cumsum()
2026-03-27 13:56:48 +00:00
# === SAVE ===
df.to_csv(OUTPUT, index=False)
print(f"✅ Saved {len(df)} rows → {OUTPUT}")
print(f"⚠️ Skipped lines: {errors}")
2026-03-27 13:48:33 +00:00
2026-03-27 14:01:33 +00:00
print("Games:", len(df))
print("Total profit:", df["profit"].sum())
print("ROI:", df["profit"].sum() / df["buy_in"].sum())
print("Win rate:", (df["position"] == "1").mean())
print("ITM:", (df["prize"] > 0).mean())
2026-03-27 13:48:33 +00:00
# === GRAPH ===
plt.figure()
plt.plot(df["datetime"], df["cum_profit"])
plt.xlabel("Time")
plt.ylabel("")
plt.title("Cumulative Profit")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()