Skip to content

Commit 5cd3c1b

Browse files
committed
fix(history): retain 200 trip summaries
1 parent 1674eb9 commit 5cd3c1b

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ All notable changes to this project are documented here. Format follows
2323
- **Trip history can be pruned without bypassing its atomic persistence boundary.**
2424
`EnergyTripHistoryStore` can remove one start-time-identified trip or replace the history with
2525
a valid empty v2 envelope; both operations preserve the same unique-temp-file rewrite used by
26-
appends, so a UI never deletes the only valid file before its replacement exists.
26+
appends, so a UI never deletes the only valid file before its replacement exists. The default
27+
summary bound is 200 trips; the existing byte ceiling still drops old sample tracks first.
2728

2829
- **A public post-AAOS 9 capacity signal can be tested without becoming product data.**
2930
`EV_CURRENT_BATTERY_CAPACITY` describes real-time usable capacity rather than the pack's nominal

‎lib/src/main/java/com/evsuite/hardware/telemetry/EnergyTripHistoryStore.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ data class TripHistoryFile(
4242
*/
4343
class EnergyTripHistoryStore(
4444
private val target: File,
45-
private val maxTrips: Int = 50,
45+
private val maxTrips: Int = 200,
4646
private val maxBytes: Int = 512 * 1024,
4747
private val gson: Gson = Gson(),
4848
) {

‎lib/src/test/java/com/evsuite/hardware/telemetry/TripHistoryStoreTest.kt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ class TripHistoryStoreTest {
141141
assertEquals(30, store.read().size)
142142
}
143143

144+
@Test fun `the default history retains two hundred summaries newest first`() {
145+
val directory = tempDirectory()
146+
val store = EnergyTripHistoryStore(File(directory, "trips.json"))
147+
148+
repeat(201) { trip -> assertTrue(store.append(summary(trip.toLong()))) }
149+
150+
val starts = store.readSummaries().map { it.startedAtMs }
151+
assertEquals(200, starts.size)
152+
assertEquals(200L, starts.first())
153+
assertEquals(1L, starts.last())
154+
}
155+
144156
@Test fun `a four hour trip is decimated rather than truncated`() {
145157
val track = TripSampleTrack(startIntervalMs = 5_000L, maxSamples = 64)
146158
// Four hours at 1 Hz: 14 400 reads, of which the track would keep 2 880 at 5 s.

0 commit comments

Comments
 (0)