Files

114 lines
2.7 KiB
Python
Raw Permalink Normal View History

2026-03-27 14:03:10 +00:00
#!/usr/bin/env python3
import sys
import subprocess
2026-03-27 14:07:48 +00:00
import os
2026-03-27 14:03:10 +00:00
# === AUTO INSTALL ===
def ensure(pkg):
try:
__import__(pkg)
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", pkg])
ensure("pandas")
ensure("matplotlib")
import pandas as pd
import matplotlib.pyplot as plt
# === ARGS ===
if len(sys.argv) < 2:
2026-03-27 14:07:48 +00:00
print("Usage: python graph.py data.csv [output_dir]")
2026-03-27 14:03:10 +00:00
sys.exit(1)
FILE = sys.argv[1]
2026-03-27 14:07:48 +00:00
OUTDIR = sys.argv[2] if len(sys.argv) > 2 else "graphs"
os.makedirs(OUTDIR, exist_ok=True)
2026-03-27 14:03:10 +00:00
# === LOAD ===
df = pd.read_csv(FILE)
2026-03-27 14:07:48 +00:00
required_cols = ["datetime", "profit", "buy_in"]
for col in required_cols:
2026-03-27 14:03:10 +00:00
if col not in df.columns:
print(f"Missing column: {col}")
sys.exit(1)
2026-03-27 14:07:48 +00:00
df["datetime"] = pd.to_datetime(df["datetime"], errors="coerce")
df = df.dropna(subset=["datetime"])
df = df.sort_values("datetime")
# === CLEAN NUMERIC ===
df["profit"] = pd.to_numeric(df["profit"], errors="coerce").fillna(0)
df["buy_in"] = pd.to_numeric(df["buy_in"], errors="coerce").fillna(0)
# === CUMULATIVE PROFIT ===
2026-03-27 14:03:10 +00:00
df["cum_profit"] = df["profit"].cumsum()
plt.figure()
plt.plot(df["datetime"], df["cum_profit"])
plt.title("Cumulative Profit")
plt.xlabel("Time")
plt.ylabel("")
plt.xticks(rotation=45)
plt.tight_layout()
2026-03-27 14:07:48 +00:00
plt.savefig(f"{OUTDIR}/cum_profit.png")
plt.close()
2026-03-27 14:03:10 +00:00
2026-03-27 14:07:48 +00:00
# === PROFIT PER GAME ===
2026-03-27 14:03:10 +00:00
plt.figure()
plt.scatter(range(len(df)), df["profit"])
plt.title("Profit per Game")
plt.xlabel("Game #")
plt.ylabel("")
plt.tight_layout()
2026-03-27 14:07:48 +00:00
plt.savefig(f"{OUTDIR}/profit_scatter.png")
plt.close()
# === ROI BY CATEGORY (SAFE) ===
if "category" in df.columns:
df_valid = df[df["buy_in"] > 0]
if not df_valid.empty:
roi = df_valid.groupby("category").apply(
lambda x: x["profit"].sum() / x["buy_in"].sum()
)
plt.figure()
roi.plot(kind="bar")
plt.title("ROI by Category")
plt.xlabel("Category")
plt.ylabel("ROI")
plt.tight_layout()
plt.savefig(f"{OUTDIR}/roi_category.png")
plt.close()
# === SESSION PERFORMANCE ===
2026-03-27 14:03:10 +00:00
if "session" in df.columns:
session_profit = df.groupby("session")["profit"].sum()
plt.figure()
session_profit.plot(kind="bar")
plt.title("Profit by Session")
plt.xlabel("Session")
plt.ylabel("")
plt.tight_layout()
2026-03-27 14:07:48 +00:00
plt.savefig(f"{OUTDIR}/session_profit.png")
plt.close()
2026-03-27 14:03:10 +00:00
2026-03-27 14:07:48 +00:00
# === POSITION DISTRIBUTION ===
2026-03-27 14:03:10 +00:00
if "position" in df.columns:
pos_counts = df["position"].value_counts()
plt.figure()
pos_counts.plot(kind="bar")
plt.title("Position Distribution")
plt.xlabel("Position")
plt.ylabel("Count")
plt.tight_layout()
2026-03-27 14:07:48 +00:00
plt.savefig(f"{OUTDIR}/positions.png")
plt.close()
2026-03-27 14:03:10 +00:00
2026-03-27 14:07:48 +00:00
print(f"✅ Graphs saved in: {OUTDIR}")