From bb74adf26a640ad5ae48eda49ff9bda786e158e6 Mon Sep 17 00:00:00 2001 From: Jan Jetze Date: Sun, 8 Mar 2026 11:41:33 +0100 Subject: [PATCH] fix: store actual step counts in sensor windows instead of hardcoded zero SensorWindow.stepCount was always written as 0, causing the Activities screen to show no steps for any session. Added a windowStepAccumulator that collects step events between classifier evaluations and persists the real count with each 30-second window. Co-Authored-By: Claude Opus 4.6 --- .../com/podometer/service/StepTrackingService.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/podometer/service/StepTrackingService.kt b/app/src/main/java/com/podometer/service/StepTrackingService.kt index b173da4..96897d9 100644 --- a/app/src/main/java/com/podometer/service/StepTrackingService.kt +++ b/app/src/main/java/com/podometer/service/StepTrackingService.kt @@ -34,6 +34,7 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import java.util.concurrent.atomic.AtomicInteger import kotlin.coroutines.cancellation.CancellationException import javax.inject.Inject @@ -105,6 +106,13 @@ class StepTrackingService : Service() { private var classifierJob: Job? = null private var orphanCleanupJob: Job? = null + /** + * Accumulates step counts between classifier evaluations so each + * [SensorWindow] can record how many steps occurred during its 30-second + * interval. Reset to zero each time the classifier persists a window. + */ + private val windowStepAccumulator = AtomicInteger(0) + /** * Timestamp (ms) of the most recently processed step event. Used by * [collectStepEvents] to spread burst step timestamps evenly over the @@ -266,6 +274,7 @@ class StepTrackingService : Service() { stepFrequencyTracker.recordStep(ts) } lastStepEventMs = nowMs + windowStepAccumulator.addAndGet(delta) // Skip step accumulation while cycling is active. if (cyclingSessionManager.isStepCountingPaused) { @@ -372,6 +381,7 @@ class StepTrackingService : Service() { val stepFreq = stepFrequencyTracker.computeStepFrequency(now) // Persist raw sensor window for retroactive recomputation (7-day retention). + val stepsInWindow = windowStepAccumulator.getAndSet(0) serviceScope.launch { try { sensorWindowRepository.insertWindow( @@ -379,7 +389,7 @@ class StepTrackingService : Service() { timestamp = now, magnitudeVariance = features.magnitudeVariance, stepFrequencyHz = stepFreq, - stepCount = 0, // per-window step count not tracked; reserved for future use + stepCount = stepsInWindow, ), ) } catch (e: Exception) {