From c1493cedec998beb7d5cf95bc087e4442ea68231 Mon Sep 17 00:00:00 2001 From: Leon <44861470+Fruhji@users.noreply.github.com> Date: Thu, 7 May 2026 16:09:25 +0200 Subject: [PATCH] feat: add Today range button to dashboard --- dashboard.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/dashboard.py b/dashboard.py index ebf8d5f..73b5881 100644 --- a/dashboard.py +++ b/dashboard.py @@ -235,6 +235,7 @@ def get_dashboard_data(db_path=DB_PATH):
Range
+ @@ -481,8 +482,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', '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, '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) { @@ -498,6 +499,10 @@ 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 === 'week') { const day = today.getDay(); const diffToMon = day === 0 ? 6 : day - 1; @@ -742,7 +747,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); @@ -1242,13 +1247,15 @@ def log_message(self, format, *args): pass def do_GET(self): - if self.path in ("/", "/index.html"): + from urllib.parse import urlparse + parsed_path = urlparse(self.path).path + if parsed_path in ("/", "/index.html"): self.send_response(200) self.send_header("Content-Type", "text/html; charset=utf-8") self.end_headers() self.wfile.write(HTML_TEMPLATE.encode("utf-8")) - elif self.path == "/api/data": + elif parsed_path == "/api/data": data = get_dashboard_data() body = json.dumps(data).encode("utf-8") self.send_response(200)