fix: restore /api/stats route, remove dead player code, fix modal scroll
- app_sql.py: add get_overview_stats() with single SQL query (trip count, total km, duration, max speed, active DTC count) - app.py: add /api/stats route (was missing after scp overwrote the file) - local-videos.js: remove leftover old closePlayer/playVideo/renderFiles duplicate block that still had scrollIntoView and references to the old panel elements; new modal-based code is the only path now Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -317,6 +317,32 @@ def refresh_trips(force=False):
|
||||
return conn.execute("SELECT COUNT(*) FROM trips").fetchone()[0]
|
||||
|
||||
|
||||
def get_overview_stats():
|
||||
conn = get_conn()
|
||||
with _conn_lock:
|
||||
row = conn.execute("""
|
||||
SELECT COUNT(*), COALESCE(SUM(DISTANCE_KM),0),
|
||||
COALESCE(SUM(DURATION_SECONDS),0), COALESCE(MAX(MAX_SPEED_KMH),0)
|
||||
FROM trips
|
||||
""").fetchone()
|
||||
dtc_row = conn.execute("""
|
||||
SELECT COUNT(*) FROM dtc_codes WHERE cleared_at IS NULL
|
||||
""").fetchone() if _table_exists(conn, "dtc_codes") else (0,)
|
||||
return {
|
||||
"trip_count": row[0],
|
||||
"total_km": row[1],
|
||||
"total_duration_s": row[2],
|
||||
"all_time_max_speed": row[3],
|
||||
"active_dtc": dtc_row[0] if dtc_row else 0,
|
||||
}
|
||||
|
||||
|
||||
def _table_exists(conn, name):
|
||||
return conn.execute(
|
||||
"SELECT 1 FROM sqlite_master WHERE type='table' AND name=?", (name,)
|
||||
).fetchone() is not None
|
||||
|
||||
|
||||
def list_trips():
|
||||
refresh_trips()
|
||||
conn = get_conn()
|
||||
|
||||
Reference in New Issue
Block a user