Add persistent car performance analytics

This commit is contained in:
2026-07-31 22:44:51 +02:00
parent 0e4ce931ec
commit 6998e8bdb7
12 changed files with 916 additions and 29 deletions
+53
View File
@@ -69,6 +69,59 @@ function migrate(database: CompanionDatabase): void {
created_at TEXT NOT NULL,
UNIQUE(target_type, target_value)
);
CREATE TABLE IF NOT EXISTS car_telemetry_samples (
recorded_at INTEGER PRIMARY KEY,
speed_kph REAL,
wheel_angle_degrees REAL,
battery_percent REAL,
range_km REAL,
battery_voltage REAL,
total_consumption_kwh REAL,
charging_status INTEGER,
charging_power_kw REAL
) WITHOUT ROWID;
CREATE TABLE IF NOT EXISTS car_telemetry_hourly (
bucket_start INTEGER PRIMARY KEY,
sample_count INTEGER NOT NULL,
speed_sum REAL NOT NULL,
speed_count INTEGER NOT NULL,
speed_max REAL,
soc_sum REAL NOT NULL,
soc_count INTEGER NOT NULL,
soc_min REAL,
soc_max REAL,
range_sum REAL NOT NULL,
range_count INTEGER NOT NULL,
range_max REAL,
charge_power_sum REAL NOT NULL,
charge_power_count INTEGER NOT NULL,
charge_power_max REAL,
distance_km REAL NOT NULL,
driving_seconds REAL NOT NULL,
charging_seconds REAL NOT NULL
) WITHOUT ROWID;
CREATE TABLE IF NOT EXISTS car_telemetry_stats (
id INTEGER PRIMARY KEY CHECK (id = 1),
first_sample_at INTEGER,
last_sample_at INTEGER,
sample_count INTEGER NOT NULL DEFAULT 0,
peak_speed_kph REAL,
peak_speed_at INTEGER,
peak_charging_power_kw REAL,
peak_charging_power_at INTEGER,
max_observed_range_km REAL,
max_observed_range_at INTEGER,
tracked_distance_km REAL NOT NULL DEFAULT 0,
driving_seconds REAL NOT NULL DEFAULT 0,
charging_seconds REAL NOT NULL DEFAULT 0,
charge_sessions INTEGER NOT NULL DEFAULT 0,
soc_used_percent REAL NOT NULL DEFAULT 0
);
INSERT OR IGNORE INTO car_telemetry_stats (id) VALUES (1);
`);
database