feat: add direct car telemetry management

This commit is contained in:
2026-07-31 23:14:40 +02:00
parent 530162cbf7
commit e347a581e1
16 changed files with 447 additions and 57 deletions
+54
View File
@@ -78,4 +78,58 @@ describe("car telemetry history", () => {
expect(store.history("24h").points).toHaveLength(1);
database.close();
});
it("clears history independently from all-time statistics", () => {
const database = openDatabase(":memory:");
const store = new CarTelemetryStore(database);
const startedAt = Date.now() - 10 * 60_000;
store.record(sample(startedAt, { speed: 20, soc: 80, range: 320, charging: 0 }));
for (let index = 1; index <= 40; index += 1) {
store.record(sample(startedAt + index * 10_000, {
speed: 110,
soc: 80 - index * 0.15,
range: 320 - index,
charging: 0
}));
}
const before = store.overview();
expect(before.lifetime.trackedDistanceKm).toBeGreaterThan(10);
expect(before.lifetime.ownRangeEstimateKm).not.toBeNull();
expect(store.clear("history")).toMatchObject({ mode: "history", deletedSamples: 41 });
const kept = store.overview();
expect(store.history("24h").points).toEqual([]);
expect(kept.storage.rawSamples).toBe(0);
expect(kept.storage.hourlyRollups).toBe(0);
expect(kept.records).toEqual(before.records);
expect(kept.lifetime).toEqual(before.lifetime);
store.record(sample(Date.now(), { speed: 30, soc: 70, range: 260, charging: 0 }));
expect(store.clear("all")).toMatchObject({ mode: "all", deletedSamples: 1 });
const reset = store.overview();
expect(store.history("all").points).toEqual([]);
expect(reset.records).toEqual({
peakSpeedKph: null,
peakSpeedAt: null,
peakChargingPowerKw: null,
peakChargingPowerAt: null,
maxObservedRangeKm: null,
maxObservedRangeAt: null
});
expect(reset.lifetime).toMatchObject({
firstSampleAt: null,
lastSampleAt: null,
sampleCount: 0,
trackedDistanceKm: 0,
drivingSeconds: 0,
chargingSeconds: 0,
chargeSessions: 0,
socUsedPercent: 0,
averageMovingSpeedKph: null,
ownRangeEstimateKm: null
});
database.close();
});
});