Skip to content

Commit fa8a26e

Browse files
committed
HealthStatsSync: stub buildWeekdayTypicalsFromData
Adds the helper signature and empty-input fast path. Subsequent commits will fill in the binning algorithm test-by-test.
1 parent f0aa39b commit fa8a26e

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

libpebble3/src/commonMain/kotlin/io/rebble/libpebblecommon/services/HealthStatsSync.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import co.touchlab.kermit.Logger
2121
import io.rebble.libpebblecommon.database.dao.DailyMovementAggregate
2222
import io.rebble.libpebblecommon.database.dao.HealthAggregates
2323
import io.rebble.libpebblecommon.database.dao.HealthDao
24+
import io.rebble.libpebblecommon.database.entity.HealthDataEntity
2425
import io.rebble.libpebblecommon.database.entity.HealthStat
2526
import io.rebble.libpebblecommon.database.entity.HealthStatDao
2627
import io.rebble.libpebblecommon.util.DataBuffer
@@ -32,6 +33,7 @@ import kotlinx.datetime.TimeZone
3233
import kotlinx.datetime.atStartOfDayIn
3334
import kotlinx.datetime.minus
3435
import kotlinx.datetime.plus
36+
import kotlinx.datetime.toLocalDateTime
3537

3638
private val logger = Logger.withTag("HealthStatsSync")
3739

@@ -178,6 +180,23 @@ private fun movementPayload(dayStartEpochSec: Long, aggregates: HealthAggregates
178180
return buffer.array()
179181
}
180182

183+
/**
184+
* Bins a flat list of HealthDataEntity rows into per-weekday 15-minute typical-step payloads.
185+
*
186+
* For each weekday with at least MIN_DAYS_FOR_TYPICAL distinct matching days in the input,
187+
* emits a 192-byte little-endian payload of 96 UShort values. A slot's value is the average
188+
* step count across the distinct matching days that had at least one row overlapping that
189+
* slot; if zero matching days covered the slot, the value is UNKNOWN_TYPICAL_STEPS so the
190+
* watch sum-skips it. Weekdays below the threshold are omitted from the result.
191+
*/
192+
internal fun buildWeekdayTypicalsFromData(
193+
allData: List<HealthDataEntity>,
194+
timeZone: TimeZone,
195+
): Map<DayOfWeek, ByteArray> {
196+
if (allData.isEmpty()) return emptyMap()
197+
return emptyMap()
198+
}
199+
181200
// Extension functions
182201
private fun Long.kilocalories(): Long = this / 1000L
183202

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.rebble.libpebblecommon.services
2+
3+
import io.rebble.libpebblecommon.database.entity.HealthDataEntity
4+
import kotlinx.datetime.TimeZone
5+
import kotlin.test.Test
6+
import kotlin.test.assertTrue
7+
8+
class HealthStatsSyncTest {
9+
@Test
10+
fun buildWeekdayTypicalsFromData_emptyInput_returnsEmptyMap() {
11+
val result = buildWeekdayTypicalsFromData(emptyList(), TimeZone.UTC)
12+
assertTrue(result.isEmpty(), "empty input should produce empty map, got keys=${result.keys}")
13+
}
14+
}
15+
16+
private fun row(timestamp: Long, steps: Int) = HealthDataEntity(
17+
timestamp = timestamp,
18+
steps = steps,
19+
orientation = 0,
20+
intensity = 0,
21+
lightIntensity = 0,
22+
activeMinutes = 0,
23+
restingGramCalories = 0,
24+
activeGramCalories = 0,
25+
distanceCm = 0,
26+
)

0 commit comments

Comments
 (0)