nanobot: 2026-09-17 18:43:01
This commit is contained in:
48
scripts/plot_ollama_weekly_usage.py
Normal file
48
scripts/plot_ollama_weekly_usage.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Plot weekly Ollama Cloud usage: x = days since start of weekly window."""
|
||||
|
||||
import sqlite3
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import matplotlib
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
DB = "db/ollama_usage.sqlite"
|
||||
OUT = "results/ollama_weekly_usage.png"
|
||||
|
||||
|
||||
def parse(ts: str) -> datetime:
|
||||
return datetime.fromisoformat(ts)
|
||||
|
||||
|
||||
def window_start(d: datetime) -> datetime:
|
||||
"""Monday 00:00 UTC of the week containing d."""
|
||||
monday = d - timedelta(days=d.weekday())
|
||||
return monday.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
|
||||
con = sqlite3.connect(DB)
|
||||
rows = con.execute(
|
||||
"SELECT ts, weekly_usage FROM samples ORDER BY ts"
|
||||
).fetchall()
|
||||
con.close()
|
||||
|
||||
samples = [(parse(r[0]), r[1] * 100) for r in rows]
|
||||
|
||||
start = window_start(samples[0][0])
|
||||
x = [(t - start).total_seconds() / 86400 for t, _ in samples]
|
||||
y = [u for _, u in samples]
|
||||
|
||||
fig, ax = plt.subplots(figsize=(14, 6), layout="constrained")
|
||||
ax.plot(x, y, color="#2563eb", lw=1.5, marker=".", ms=3)
|
||||
ax.fill_between(x, y, alpha=0.15, color="#2563eb")
|
||||
ax.set_title("Ollama Cloud — spotřeba týdenního limitu")
|
||||
ax.set_xlabel(f"dny od začátku okna (den 0 = {start.strftime('%d.%m.')} 00:00 UTC)")
|
||||
ax.set_ylabel("využití týdenního limitu (%)")
|
||||
ax.set_xticks(range(int(min(x)) + 1, int(max(x)) + 1))
|
||||
ax.set_xlim(min(x) - 0.1, max(x) + 0.1)
|
||||
ax.grid(True, alpha=0.3)
|
||||
|
||||
fig.savefig(OUT, dpi=150)
|
||||
print(f"saved {OUT}, {len(samples)} samples, window start {start.isoformat()}")
|
||||
Reference in New Issue
Block a user