Skip to content
Open
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
17 changes: 12 additions & 5 deletions dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ 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="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 +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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down