Files
yaris-obd/templates/index.html
T
2026-08-10 18:25:30 -04:00

314 lines
15 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') }}">
<style>
.dashboard-primary-row {
align-items: flex-start;
}
.dashboard-fit-card {
height: auto;
}
.dashboard-map-card #map {
height: 15rem;
}
.dashboard-map-card .card-footer {
padding-top: .65rem;
padding-bottom: .65rem;
}
.dashboard-overview-card .card-body {
padding-top: 1rem;
padding-bottom: 1rem;
}
.dashboard-overview-card .row {
row-gap: 1rem !important;
}
.dashboard-speed-card .card-body {
padding-top: .85rem;
padding-bottom: .5rem;
}
.dashboard-speed-card canvas {
height: 10rem !important;
}
@media (max-width: 1399.98px) {
.dashboard-map-card #map {
height: 13.5rem;
}
.dashboard-speed-card canvas {
height: 9rem !important;
}
}
@media (max-width: 991.98px) {
.dashboard-map-card #map {
height: 14rem;
}
.dashboard-speed-card canvas {
height: 8rem !important;
}
}
@media (max-height: 800px) and (min-width: 992px) {
.dashboard-map-card #map {
height: 12.5rem;
}
.dashboard-speed-card canvas {
height: 7.5rem !important;
}
}
</style>
{% 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 class="col-6 col-lg-3">
<div class="text-uppercase text-muted fw-bold text-xs mb-1">GPS</div>
<div id="pi-gps-status" class="h6 text-dark fw-bold mb-0">--</div>
<div id="pi-gps-detail" class="small text-muted">Waiting…</div>
</div>
</div>
</div>
</div>
{# ── GPS map + Stats + Speed history ──────────────────────────────────── #}
<div class="row g-3 mb-3 dashboard-primary-row">
<div class="col-lg-4 col-xl-3">
<div class="card shadow-sm dashboard-fit-card dashboard-map-card">
<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>
<div class="d-flex align-items-center gap-2">
<span id="gps-live-badge" class="badge text-bg-secondary">Checking…</span>
<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>
<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 id="gps-fix-detail" class="text-muted small mt-1" style="font-size:0.75rem;min-height:1rem">Waiting for GPS status…</div>
</div>
</div>
</div>
<div class="col-lg-3 col-xl-2">
<div class="card shadow-sm dashboard-fit-card dashboard-overview-card">
<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 dashboard-speed-card">
<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:10rem;"></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 %}