diff --git a/templates/base.html b/templates/base.html index b2627a7..376d92d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -68,7 +68,7 @@ -
+
{% block content %}{% endblock %}
diff --git a/templates/index.html b/templates/index.html index 22fc274..ca4716e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -91,9 +91,9 @@ -{# ── GPS map (with inline coords footer) ─────────────────────────────── #} +{# ── GPS map + Stats + Speed history ──────────────────────────────────── #}
-
+
Live GPS
@@ -113,16 +113,50 @@
-
+
-
+
+
Overview
+
+
+
+
+
Trips
+
—
+
+
+
Total distance
+
—
+
+
+
Drive time
+
—
+
+
+
Top speed ever
+
—
+
+
+
Videos on Pi
+
—
+
+
+
Active DTC
+
—
+
+
+
+
+
+
+
+
Speed history
- {# Live speed badge — visible even when graph is collapsed #} Now - — - Max - — - @@ -158,11 +192,37 @@ btn.setAttribute('aria-expanded', 'true'); btn.querySelector('i').className = 'fas fa-chevron-up'; }); + body.addEventListener('shown.bs.collapse', function () { + if (window.speedChart) window.speedChart.resize(); + }); body.addEventListener('hide.bs.collapse', function () { btn.setAttribute('aria-expanded', 'false'); btn.querySelector('i').className = 'fas fa-chevron-down'; }); btn.addEventListener('click', function () { bsCollapse.toggle(); }); + // Auto-expand on desktop; stay collapsed on mobile + if (window.innerWidth >= 768) { + bsCollapse.show(); + } + })(); + + // Overview stats card + (function () { + function fmtDuration(s) { + const h = Math.floor(s / 3600); + const m = Math.floor((s % 3600) / 60); + return h > 0 ? h + 'h ' + m + 'm' : m + 'm'; + } + fetch('/api/stats').then(r => r.json()).then(d => { + document.getElementById('stat-trips').textContent = d.trip_count; + document.getElementById('stat-km').textContent = d.total_km.toFixed(1) + ' km'; + document.getElementById('stat-time').textContent = d.total_duration_s > 0 ? fmtDuration(d.total_duration_s) : '—'; + document.getElementById('stat-topspeed').textContent = d.all_time_max_speed > 0 ? d.all_time_max_speed + ' km/h' : '—'; + document.getElementById('stat-videos').textContent = d.video_count; + const dtcEl = document.getElementById('stat-dtc'); + dtcEl.textContent = d.active_dtc; + dtcEl.className = 'fw-bold fs-5 ' + (d.active_dtc > 0 ? 'text-danger' : 'text-success'); + }).catch(() => {}); })(); {% endblock %} \ No newline at end of file