Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions chart.umd.min.js

Large diffs are not rendered by default.

36 changes: 32 additions & 4 deletions dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_dashboard_data(db_path=DB_PATH):
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Claude Code Usage Dashboard</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<script src="/static/chart.umd.min.js"></script>
<style>
:root {
--bg: #0f1117;
Expand Down Expand Up @@ -235,6 +235,8 @@ def get_dashboard_data(db_path=DB_PATH):
<div class="filter-sep"></div>
<div class="filter-label">Range</div>
<div class="range-group">
<button class="range-btn" data-range="today" onclick="setRange('today')">Today</button>
<button class="range-btn" data-range="3d" onclick="setRange('3d')">3d</button>
<button class="range-btn" data-range="week" onclick="setRange('week')">This Week</button>
<button class="range-btn" data-range="month" onclick="setRange('month')">This Month</button>
<button class="range-btn" data-range="prev-month" onclick="setRange('prev-month')">Prev Month</button>
Expand Down Expand Up @@ -481,8 +483,8 @@ def get_dashboard_data(db_path=DB_PATH):
const MODEL_COLORS = ['#d97757','#4f8ef7','#4ade80','#a78bfa','#fbbf24','#f472b6','#34d399','#60a5fa'];

// ── Time range ─────────────────────────────────────────────────────────────
const RANGE_LABELS = { 'week': 'This Week', 'month': 'This Month', 'prev-month': 'Previous Month', '7d': 'Last 7 Days', '30d': 'Last 30 Days', '90d': 'Last 90 Days', 'all': 'All Time' };
const RANGE_TICKS = { 'week': 7, 'month': 15, 'prev-month': 15, '7d': 7, '30d': 15, '90d': 13, 'all': 12 };
const RANGE_LABELS = { 'today': 'Today', '3d': 'Last 3 Days', 'week': 'This Week', 'month': 'This Month', 'prev-month': 'Previous Month', '7d': 'Last 7 Days', '30d': 'Last 30 Days', '90d': 'Last 90 Days', 'all': 'All Time' };
const RANGE_TICKS = { 'today': 1, '3d': 3, 'week': 7, 'month': 15, 'prev-month': 15, '7d': 7, '30d': 15, '90d': 13, 'all': 12 };
const VALID_RANGES = Object.keys(RANGE_LABELS);

function rangeIncludesToday(range) {
Expand All @@ -498,6 +500,14 @@ def get_dashboard_data(db_path=DB_PATH):
if (range === 'all') return { start: null, end: null };
const today = new Date();
const iso = d => d.toISOString().slice(0, 10);
if (range === 'today') {
const t = iso(today);
return { start: t, end: t };
}
if (range === '3d') {
const d = new Date(today); d.setDate(today.getDate() - 2);
return { start: iso(d), end: iso(today) };
}
if (range === 'week') {
const day = today.getDay();
const diffToMon = day === 0 ? 6 : day - 1;
Expand Down Expand Up @@ -742,7 +752,7 @@ def get_dashboard_data(db_path=DB_PATH):

// Hourly aggregation (filtered by model + range, then bucketed by UTC hour)
const hourlySrc = (rawData.hourly_by_model || []).filter(r =>
selectedModels.has(r.model) && (!cutoff || r.day >= cutoff)
selectedModels.has(r.model) && (!start || r.day >= start) && (!end || r.day <= end)
);
const hourlyAgg = aggregateHourly(hourlySrc, hourlyTZ);

Expand Down Expand Up @@ -1245,9 +1255,27 @@ def do_GET(self):
if self.path in ("/", "/index.html"):
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Cache-Control", "no-store, no-cache, must-revalidate")
self.send_header("Pragma", "no-cache")
self.end_headers()
self.wfile.write(HTML_TEMPLATE.encode("utf-8"))

elif self.path == "/static/chart.umd.min.js":
# Vendored Chart.js — avoids CDN being blocked by ad blockers / shields
try:
p = Path(__file__).parent / "chart.umd.min.js"
body = p.read_bytes()
self.send_response(200)
self.send_header("Content-Type", "application/javascript")
self.send_header("Content-Length", str(len(body)))
self.send_header("Cache-Control", "public, max-age=86400")
self.end_headers()
self.wfile.write(body)
except Exception as e:
self.send_response(500)
self.end_headers()
self.wfile.write(f"Chart.js missing: {e}".encode())

elif self.path == "/api/data":
data = get_dashboard_data()
body = json.dumps(data).encode("utf-8")
Expand Down