107 lines
2.8 KiB
Python
107 lines
2.8 KiB
Python
|
|
#!/usr/bin/python env
|
||
|
|
import sys
|
||
|
|
import subprocess
|
||
|
|
|
||
|
|
# === AUTO INSTALL ===
|
||
|
|
def ensure_package(pkg):
|
||
|
|
try:
|
||
|
|
__import__(pkg)
|
||
|
|
except ImportError:
|
||
|
|
subprocess.check_call([sys.executable, "-m", "pip", "install", pkg])
|
||
|
|
|
||
|
|
ensure_package("pandas")
|
||
|
|
ensure_package("matplotlib")
|
||
|
|
|
||
|
|
import pandas as pd
|
||
|
|
import re
|
||
|
|
from datetime import datetime
|
||
|
|
import matplotlib.pyplot as plt
|
||
|
|
|
||
|
|
# === ARGS ===
|
||
|
|
if len(sys.argv) < 2:
|
||
|
|
print("Usage: python script.py input.txt [output.csv]")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
INPUT_FILE = sys.argv[1]
|
||
|
|
OUTPUT_FILE = sys.argv[2] if len(sys.argv) > 2 else "poker_clean.csv"
|
||
|
|
|
||
|
|
# === HELPERS ===
|
||
|
|
def clean_money(value):
|
||
|
|
if not value or value.strip() in ["-", ""]:
|
||
|
|
return 0.0
|
||
|
|
return float(value.replace("€", "").replace(",", ".").strip())
|
||
|
|
|
||
|
|
def get_category(name):
|
||
|
|
n = name.lower()
|
||
|
|
if "freeroll" in n:
|
||
|
|
return "freeroll"
|
||
|
|
if "nitro" in n:
|
||
|
|
return "nitro"
|
||
|
|
return "expresso"
|
||
|
|
|
||
|
|
def get_stake(b):
|
||
|
|
return "micro" if b <= 1 else "low" if b <= 5 else "mid" if b <= 20 else "high"
|
||
|
|
|
||
|
|
def get_session(h):
|
||
|
|
return "morning" if 6 <= h < 12 else "afternoon" if 12 <= h < 18 else "evening" if 18 <= h < 24 else "night"
|
||
|
|
|
||
|
|
# === PARSE ===
|
||
|
|
rows = []
|
||
|
|
|
||
|
|
with open(INPUT_FILE, "r", encoding="utf-8") as f:
|
||
|
|
for line in f:
|
||
|
|
if not line.strip():
|
||
|
|
continue
|
||
|
|
|
||
|
|
parts = re.split(r"\s{2,}", line.strip())
|
||
|
|
|
||
|
|
try:
|
||
|
|
dt = datetime.strptime(parts[0], "%d/%m/%Y %H:%M:%S")
|
||
|
|
name = parts[1]
|
||
|
|
buy = float(parts[2])
|
||
|
|
players = int(parts[5])
|
||
|
|
|
||
|
|
pos = None if parts[6] == "-" else parts[6]
|
||
|
|
prize = clean_money(parts[7]) if len(parts) > 7 else 0.0
|
||
|
|
net = clean_money(parts[8]) if len(parts) > 8 else 0.0
|
||
|
|
|
||
|
|
profit = net - buy
|
||
|
|
hour = dt.hour
|
||
|
|
|
||
|
|
rows.append({
|
||
|
|
"datetime": dt,
|
||
|
|
"game": name,
|
||
|
|
"buy_in": buy,
|
||
|
|
"players": players,
|
||
|
|
"position": pos,
|
||
|
|
"prize": prize,
|
||
|
|
"net": net,
|
||
|
|
"profit": profit,
|
||
|
|
"category": get_category(name),
|
||
|
|
"stake": get_stake(buy),
|
||
|
|
"hour": hour,
|
||
|
|
"day": dt.strftime("%A"),
|
||
|
|
"session": get_session(hour),
|
||
|
|
"result": "win" if pos == "1" else "itm" if prize > 0 else "loss"
|
||
|
|
})
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print("Skip:", line.strip(), "|", e)
|
||
|
|
|
||
|
|
# === DATAFRAME ===
|
||
|
|
df = pd.DataFrame(rows).sort_values("datetime")
|
||
|
|
df["cum_profit"] = df["profit"].cumsum()
|
||
|
|
|
||
|
|
df.to_csv(OUTPUT_FILE, index=False)
|
||
|
|
print("Saved:", OUTPUT_FILE)
|
||
|
|
|
||
|
|
# === 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()
|