Skip to content

Commit 00d0676

Browse files
authored
Skip invalid Health Connect HRV samples (#4758)
1 parent b3d0463 commit 00d0676

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/android/src/HealthConnectHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class HealthConnectHelper {
3737
private const val HEALTH_CONNECT_PROVIDER = "com.google.android.apps.healthdata"
3838
private const val PREFS_NAME = "qz_health_connect"
3939
private const val PREF_PERMISSION_PROMPT_PENDING = "permission_prompt_pending_v2"
40+
private const val MIN_HRV_RMSSD_MILLIS = 1.0
4041

4142
private var initialized = false
4243

@@ -310,7 +311,7 @@ class HealthConnectHelper {
310311
stepsCadenceSamples += StepsCadenceRecord.Sample(time = time, rate = cadence)
311312
}
312313
}
313-
if (hasHrv && hrv > 0.0) {
314+
if (hasHrv && hrv >= MIN_HRV_RMSSD_MILLIS) {
314315
hrvRecords += HeartRateVariabilityRmssdRecord(
315316
time = time,
316317
zoneOffset = zoneOffset,

src/android/tests/org/cagnulen/qdomyoszwift/HealthConnectHelperTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ class HealthConnectHelperTest {
327327
assertEquals(42.5, hrvRecords[0].heartRateVariabilityMillis, 0.001)
328328
}
329329

330+
@Test
331+
fun `buildRecords omits HeartRateVariabilityRmssdRecord when hrv is below health connect minimum`() {
332+
val samples = JSONArray().apply {
333+
put(makeSample(1_000L, hrv = 0.9067155184426361))
334+
put(makeSample(2_000L, hrv = 1.0))
335+
}
336+
val records = HealthConnectHelper.buildRecords(samples, "t", BIKE, null)
337+
val hrvRecords = records.filterIsInstance<HeartRateVariabilityRmssdRecord>()
338+
assertEquals(1, hrvRecords.size)
339+
assertEquals(1.0, hrvRecords[0].heartRateVariabilityMillis, 0.001)
340+
}
341+
330342
@Test
331343
fun `buildRecords omits HeartRateVariabilityRmssdRecord when hrv is 0`() {
332344
val samples = JSONArray().apply { put(makeSample(1_000L)) }

0 commit comments

Comments
 (0)