@@ -3,41 +3,48 @@ package com.viktormykhailiv.kmp.health
33import androidx.health.connect.client.aggregate.AggregateMetric
44import androidx.health.connect.client.aggregate.AggregationResult
55import androidx.health.connect.client.records.BloodPressureRecord
6+ import androidx.health.connect.client.records.CyclingPedalingCadenceRecord
67import androidx.health.connect.client.records.HeartRateRecord
78import androidx.health.connect.client.records.HeightRecord
9+ import androidx.health.connect.client.records.PowerRecord
810import androidx.health.connect.client.records.SleepSessionRecord
911import androidx.health.connect.client.records.StepsRecord
1012import androidx.health.connect.client.records.WeightRecord
1113import com.viktormykhailiv.kmp.health.HealthDataType.BloodGlucose
1214import com.viktormykhailiv.kmp.health.HealthDataType.BloodPressure
1315import com.viktormykhailiv.kmp.health.HealthDataType.BodyFat
1416import com.viktormykhailiv.kmp.health.HealthDataType.BodyTemperature
17+ import com.viktormykhailiv.kmp.health.HealthDataType.CyclingPedalingCadence
1518import com.viktormykhailiv.kmp.health.HealthDataType.Exercise
1619import com.viktormykhailiv.kmp.health.HealthDataType.HeartRate
1720import com.viktormykhailiv.kmp.health.HealthDataType.Height
1821import com.viktormykhailiv.kmp.health.HealthDataType.LeanBodyMass
22+ import com.viktormykhailiv.kmp.health.HealthDataType.Power
1923import com.viktormykhailiv.kmp.health.HealthDataType.Sleep
2024import com.viktormykhailiv.kmp.health.HealthDataType.Steps
2125import com.viktormykhailiv.kmp.health.HealthDataType.Weight
2226import com.viktormykhailiv.kmp.health.aggregate.BloodGlucoseAggregatedRecord
2327import com.viktormykhailiv.kmp.health.aggregate.BloodPressureAggregatedRecord
2428import com.viktormykhailiv.kmp.health.aggregate.BodyFatAggregatedRecord
2529import com.viktormykhailiv.kmp.health.aggregate.BodyTemperatureAggregatedRecord
30+ import com.viktormykhailiv.kmp.health.aggregate.CyclingPedalingCadenceAggregatedRecord
2631import com.viktormykhailiv.kmp.health.aggregate.HeartRateAggregatedRecord
2732import com.viktormykhailiv.kmp.health.aggregate.HeightAggregatedRecord
2833import com.viktormykhailiv.kmp.health.aggregate.LeanBodyMassAggregatedRecord
34+ import com.viktormykhailiv.kmp.health.aggregate.PowerAggregatedRecord
2935import com.viktormykhailiv.kmp.health.aggregate.SleepAggregatedRecord
3036import com.viktormykhailiv.kmp.health.aggregate.StepsAggregatedRecord
3137import com.viktormykhailiv.kmp.health.aggregate.WeightAggregatedRecord
38+ import com.viktormykhailiv.kmp.health.units.BloodGlucose as BloodGlucoseUnit
3239import com.viktormykhailiv.kmp.health.units.Mass
3340import com.viktormykhailiv.kmp.health.units.Temperature
34- import com.viktormykhailiv.kmp.health.units.BloodGlucose as BloodGlucoseUnit
3541import com.viktormykhailiv.kmp.health.units.kilograms
3642import com.viktormykhailiv.kmp.health.units.meters
3743import com.viktormykhailiv.kmp.health.units.millimetersOfMercury
3844import com.viktormykhailiv.kmp.health.units.percent
39- import kotlin.time.Instant
45+ import com.viktormykhailiv.kmp.health.units.watts
4046import kotlin.time.Duration.Companion.seconds
47+ import kotlin.time.Instant
4148import kotlin.time.toKotlinDuration
4249
4350/* *
@@ -65,6 +72,13 @@ internal fun HealthDataType.toAggregateMetrics(): Set<AggregateMetric<Any>> = wh
6572 BodyTemperature ->
6673 throw IllegalArgumentException (" Aggregated BodyTemperature is not supported and must be aggregated manually" )
6774
75+ CyclingPedalingCadence ->
76+ setOf (
77+ CyclingPedalingCadenceRecord .RPM_AVG ,
78+ CyclingPedalingCadenceRecord .RPM_MIN ,
79+ CyclingPedalingCadenceRecord .RPM_MAX
80+ )
81+
6882 is Exercise ->
6983 throw IllegalArgumentException (" Aggregated Exercise is not supported and must be aggregated manually" )
7084
@@ -77,6 +91,9 @@ internal fun HealthDataType.toAggregateMetrics(): Set<AggregateMetric<Any>> = wh
7791 LeanBodyMass ->
7892 throw IllegalArgumentException (" Aggregated LeanBodyMass is not supported and must be aggregated manually" )
7993
94+ Power ->
95+ setOf (PowerRecord .POWER_AVG , PowerRecord .POWER_MIN , PowerRecord .POWER_MAX )
96+
8097 Sleep ->
8198 setOf (SleepSessionRecord .SLEEP_DURATION_TOTAL )
8299
@@ -129,6 +146,16 @@ internal fun AggregationResult.toHealthAggregatedRecord(
129146 is BodyTemperature ->
130147 throw IllegalArgumentException (" Aggregated BodyTemperature is not supported and must be aggregated manually" )
131148
149+ is CyclingPedalingCadence -> {
150+ CyclingPedalingCadenceAggregatedRecord (
151+ startTime = startTime,
152+ endTime = endTime,
153+ avg = get(CyclingPedalingCadenceRecord .RPM_AVG ) ? : 0.0 ,
154+ min = get(CyclingPedalingCadenceRecord .RPM_MIN ) ? : 0.0 ,
155+ max = get(CyclingPedalingCadenceRecord .RPM_MAX ) ? : 0.0 ,
156+ )
157+ }
158+
132159 is Exercise ->
133160 throw IllegalArgumentException (" Aggregated Exercise is not supported and must be aggregated manually" )
134161
@@ -155,6 +182,16 @@ internal fun AggregationResult.toHealthAggregatedRecord(
155182 is LeanBodyMass ->
156183 throw IllegalArgumentException (" Aggregated LeanBodyMass is not supported and must be aggregated manually" )
157184
185+ is Power -> {
186+ PowerAggregatedRecord (
187+ startTime = startTime,
188+ endTime = endTime,
189+ avg = get(PowerRecord .POWER_AVG )?.toPower() ? : 0 .watts,
190+ min = get(PowerRecord .POWER_MIN )?.toPower() ? : 0 .watts,
191+ max = get(PowerRecord .POWER_MAX )?.toPower() ? : 0 .watts,
192+ )
193+ }
194+
158195 is Sleep -> {
159196 SleepAggregatedRecord (
160197 startTime = startTime,
0 commit comments