- Dashboard: recenter button in GPS card header (hidden until first fix) - Dashboard: estimated location name under lat/lon via Nominatim reverse geocode (throttled 30s) - History: recenter button fits map back to trip bounds - Both buttons use crosshairs icon, hidden until data is available Co-authored-by: Copilot <[email protected]>
239 lines
13 KiB
HTML
239 lines
13 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Dashboard - Yaris OBD{% endblock %}
|
|
|
|
{% block styles %}
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='vendor/leaflet/leaflet.css') }}">
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<h3 class="text-dark mb-3 fw-bold">Dashboard</h3>
|
|
|
|
{# ── OBD stat cards ──────────────────────────────────────────────────── #}
|
|
<div class="row g-2 mb-3">
|
|
<div class="col-6 col-sm-4 col-xl-2">
|
|
<div class="card shadow-sm border-start-primary h-100">
|
|
<div class="card-body py-2 px-3">
|
|
<div class="text-uppercase text-primary fw-bold text-xs mb-1">OBD</div>
|
|
<div id="obd-status" class="fw-bold mb-0 text-dark obd-val">—</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-sm-4 col-xl-2">
|
|
<div class="card shadow-sm border-start-success h-100">
|
|
<div class="card-body py-2 px-3">
|
|
<div class="text-uppercase text-success fw-bold text-xs mb-1">Speed</div>
|
|
<div id="obd-speed" class="fw-bold h5 mb-0 text-dark">—</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-sm-4 col-xl-2">
|
|
<div class="card shadow-sm border-start-info h-100">
|
|
<div class="card-body py-2 px-3">
|
|
<div class="text-uppercase text-info fw-bold text-xs mb-1">RPM</div>
|
|
<div id="obd-rpm" class="fw-bold h5 mb-0 text-dark">—</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-sm-4 col-xl-2">
|
|
<div class="card shadow-sm border-start-warning h-100">
|
|
<div class="card-body py-2 px-3">
|
|
<div class="text-uppercase text-warning fw-bold text-xs mb-1">Coolant</div>
|
|
<div id="obd-coolant" class="fw-bold h5 mb-0 text-dark">—</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-sm-4 col-xl-2">
|
|
<div class="card shadow-sm border-start-danger h-100">
|
|
<div class="card-body py-2 px-3">
|
|
<div class="text-uppercase text-danger fw-bold text-xs mb-1">Throttle</div>
|
|
<div id="obd-throttle" class="fw-bold h5 mb-0 text-dark">—</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-sm-4 col-xl-2">
|
|
<div class="card shadow-sm border-start-primary h-100">
|
|
<div class="card-body py-2 px-3">
|
|
<div class="text-uppercase text-primary fw-bold text-xs mb-1">Fuel</div>
|
|
<div id="obd-fuel" class="fw-bold h5 mb-0 text-dark">—</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{# ── Pi health ───────────────────────────────────────────────────────── #}
|
|
<div class="card shadow-sm mb-3" id="pi-health-card">
|
|
<div class="card-header d-flex flex-wrap justify-content-between align-items-center gap-2 py-2">
|
|
<h6 class="text-primary fw-bold m-0">Pi health</h6>
|
|
<span id="pi-health-updated" class="small text-muted">Loading…</span>
|
|
</div>
|
|
<div class="card-body py-2">
|
|
<div id="pi-health-warning" class="alert alert-warning py-2 mb-2" role="alert" hidden></div>
|
|
<div id="pi-health-error" class="alert alert-danger py-2 mb-2" role="alert" hidden></div>
|
|
<div class="row g-2">
|
|
<div class="col-6 col-lg-3">
|
|
<div class="text-uppercase text-muted fw-bold text-xs mb-1">CPU temp</div>
|
|
<div id="pi-temperature" class="h6 text-dark fw-bold mb-0">--</div>
|
|
</div>
|
|
<div class="col-6 col-lg-3">
|
|
<div class="text-uppercase text-muted fw-bold text-xs mb-1">Memory</div>
|
|
<div id="pi-memory" class="h6 text-dark fw-bold mb-0">--</div>
|
|
</div>
|
|
<div class="col-6 col-lg-3">
|
|
<div class="text-uppercase text-muted fw-bold text-xs mb-1">Disk</div>
|
|
<div id="pi-disk" class="h6 text-dark fw-bold mb-0">--</div>
|
|
</div>
|
|
<div class="col-6 col-lg-3">
|
|
<div class="text-uppercase text-muted fw-bold text-xs mb-1">Uptime</div>
|
|
<div id="pi-uptime" class="h6 text-dark fw-bold mb-0">--</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{# ── GPS map + Stats + Speed history ──────────────────────────────────── #}
|
|
<div class="row g-3 mb-3">
|
|
<div class="col-lg-4 col-xl-3">
|
|
<div class="card shadow-sm h-100">
|
|
<div class="card-header py-2 d-flex justify-content-between align-items-center">
|
|
<h6 class="text-primary fw-bold m-0">Live GPS</h6>
|
|
<button id="btn-recenter" class="btn btn-outline-secondary btn-sm" type="button" title="Recenter map" hidden>
|
|
<i class="fas fa-crosshairs" aria-hidden="true"></i>
|
|
</button>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div id="map"></div>
|
|
</div>
|
|
<div class="card-footer py-2 bg-white border-top">
|
|
<div class="d-flex gap-4 mb-1">
|
|
<div>
|
|
<div class="text-xs text-muted fw-bold text-uppercase">Lat</div>
|
|
<div id="gpsLocationX" class="fw-semibold small">—</div>
|
|
</div>
|
|
<div>
|
|
<div class="text-xs text-muted fw-bold text-uppercase">Lon</div>
|
|
<div id="gpsLocationY" class="fw-semibold small">—</div>
|
|
</div>
|
|
</div>
|
|
<div id="gps-location-name" class="text-muted small" style="font-size:0.75rem;min-height:1rem"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3 col-xl-2">
|
|
<div class="card shadow-sm h-100">
|
|
<div class="card-header py-2">
|
|
<h6 class="text-primary fw-bold m-0">Overview</h6>
|
|
</div>
|
|
<div class="card-body py-3 px-3" id="stats-body">
|
|
<div class="row g-3">
|
|
<div class="col-6 col-lg-12">
|
|
<div class="text-xs text-muted fw-bold text-uppercase mb-1">Trips</div>
|
|
<div class="fw-bold fs-5 text-dark" id="stat-trips">—</div>
|
|
</div>
|
|
<div class="col-6 col-lg-12">
|
|
<div class="text-xs text-muted fw-bold text-uppercase mb-1">Total distance</div>
|
|
<div class="fw-bold fs-5 text-dark" id="stat-km">—</div>
|
|
</div>
|
|
<div class="col-6 col-lg-12">
|
|
<div class="text-xs text-muted fw-bold text-uppercase mb-1">Drive time</div>
|
|
<div class="fw-bold fs-5 text-dark" id="stat-time">—</div>
|
|
</div>
|
|
<div class="col-6 col-lg-12">
|
|
<div class="text-xs text-muted fw-bold text-uppercase mb-1">Top speed ever</div>
|
|
<div class="fw-bold fs-5 text-dark" id="stat-topspeed">—</div>
|
|
</div>
|
|
<div class="col-6 col-lg-12">
|
|
<div class="text-xs text-muted fw-bold text-uppercase mb-1">Odometer</div>
|
|
<div class="fw-bold fs-5 text-dark" id="stat-odometer">—</div>
|
|
</div>
|
|
<div class="col-6 col-lg-12">
|
|
<div class="text-xs text-muted fw-bold text-uppercase mb-1">Videos on Pi</div>
|
|
<div class="fw-bold fs-5 text-dark" id="stat-videos">—</div>
|
|
</div>
|
|
<div class="col-6 col-lg-12">
|
|
<div class="text-xs text-muted fw-bold text-uppercase mb-1">Active DTC</div>
|
|
<div class="fw-bold fs-5" id="stat-dtc">—</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-5 col-xl-7">
|
|
<div class="card shadow-sm h-100">
|
|
<div class="card-header py-2 d-flex align-items-center gap-2">
|
|
<h6 class="text-primary fw-bold m-0 me-auto">Speed history</h6>
|
|
<span class="text-xs text-muted fw-bold text-uppercase">Now</span>
|
|
<span id="speed-now-badge" class="fw-bold text-dark" style="min-width:3rem;text-align:right;">—</span>
|
|
<span class="text-xs text-muted fw-bold text-uppercase ms-2 speed-max-group">Max</span>
|
|
<span id="speed-max-badge" class="fw-bold text-danger speed-max-group" style="min-width:3rem;text-align:right;">—</span>
|
|
<button class="btn btn-link btn-sm p-0 text-muted ms-1" id="speed-graph-toggle" type="button"
|
|
aria-expanded="false" aria-controls="speed-graph-body">
|
|
<i class="fas fa-chevron-down"></i>
|
|
</button>
|
|
</div>
|
|
<div class="collapse" id="speed-graph-body">
|
|
<div class="card-body pb-2 pt-3 px-3">
|
|
<canvas id="speedGraph" style="height:13rem;"></canvas>
|
|
</div>
|
|
<div class="card-footer py-2 d-flex gap-4 bg-white border-top small text-muted">
|
|
<div><span class="fw-bold text-uppercase" style="font-size:.65rem;">Avg (session)</span> <span id="speed-avg-badge" class="text-dark fw-semibold">—</span></div>
|
|
<div><span class="fw-bold text-uppercase" style="font-size:.65rem;">Points</span> <span id="speed-points-badge" class="text-dark fw-semibold">0</span></div>
|
|
<div class="ms-auto"><span id="speed-last-time" class="text-muted" style="font-size:.7rem;"></span></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script src="{{ url_for('static', filename='js/chart.min.js') }}"></script>
|
|
<script src="{{ url_for('static', filename='vendor/socketio/socket.io.min.js') }}"></script>
|
|
<script src="{{ url_for('static', filename='vendor/leaflet/leaflet.js') }}"></script>
|
|
<script src="{{ url_for('static', filename='js/yaris.js') }}"></script>
|
|
<script>
|
|
// Speed graph toggle
|
|
(function () {
|
|
const btn = document.getElementById('speed-graph-toggle');
|
|
const body = document.getElementById('speed-graph-body');
|
|
if (!btn || !body) return;
|
|
const bsCollapse = new bootstrap.Collapse(body, {toggle: false});
|
|
body.addEventListener('show.bs.collapse', function () {
|
|
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-odometer').textContent = d.odometer_km != null ? Math.round(d.odometer_km).toLocaleString() + ' km' : '—';
|
|
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(() => {});
|
|
})();
|
|
</script>
|
|
{% endblock %} |