diff --git a/android/src/main/java/dev/matinzd/healthconnect/HealthConnectManager.kt b/android/src/main/java/dev/matinzd/healthconnect/HealthConnectManager.kt index 074f083..968facb 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/HealthConnectManager.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/HealthConnectManager.kt @@ -148,6 +148,24 @@ class HealthConnectManager(private val applicationContext: ReactApplicationConte } } + fun aggregateGroupByDuration(record: ReadableMap, promise: Promise) { + throwUnlessClientIsAvailable(promise) { + coroutineScope.launch { + try { + val recordType = record.getString("recordType") ?: "" + val response = healthConnectClient.aggregateGroupByDuration( + ReactHealthRecord.getAggregateGroupByDurationRequest( + recordType, record + ) + ) + promise.resolve(ReactHealthRecord.parseAggregationResultGroupedByDuration(recordType, response)) + } catch (e: Exception) { + promise.rejectWithException(e) + } + } + } + } + fun aggregateGroupByPeriod(record: ReadableMap, promise: Promise) { throwUnlessClientIsAvailable(promise) { coroutineScope.launch { diff --git a/android/src/main/java/dev/matinzd/healthconnect/HealthConnectModule.kt b/android/src/main/java/dev/matinzd/healthconnect/HealthConnectModule.kt index 0001418..ea833e7 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/HealthConnectModule.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/HealthConnectModule.kt @@ -70,6 +70,11 @@ class HealthConnectModule internal constructor(context: ReactApplicationContext) return manager.aggregateRecord(record, promise) } + @ReactMethod + override fun aggregateGroupByDuration(record: ReadableMap, promise: Promise) { + return manager.aggregateGroupByDuration(record, promise) + } + @ReactMethod override fun aggregateGroupByPeriod(record: ReadableMap, promise: Promise) { return manager.aggregateGroupByPeriod(record, promise) diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt index 36dc0fd..5529997 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.ActiveCaloriesBurnedRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import com.facebook.react.bridge.ReadableArray @@ -17,6 +19,7 @@ import dev.matinzd.healthconnect.utils.energyToJsMap import dev.matinzd.healthconnect.utils.getEnergyFromJsMap import dev.matinzd.healthconnect.utils.getTimeRangeFilter import dev.matinzd.healthconnect.utils.toMapList +import dev.matinzd.healthconnect.utils.mapJsDurationToDuration import dev.matinzd.healthconnect.utils.mapJsPeriodToPeriod import java.time.Instant @@ -53,6 +56,15 @@ class ReactActiveCaloriesBurnedRecord : ReactHealthRecordImpl): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalBodyTemperatureRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalBodyTemperatureRecord.kt index bb4f5c4..71e6526 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalBodyTemperatureRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalBodyTemperatureRecord.kt @@ -1,9 +1,11 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BasalBodyTemperatureRecord import androidx.health.connect.client.records.BodyTemperatureMeasurementLocation +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.units.Temperature @@ -48,6 +50,10 @@ class ReactBasalBodyTemperatureRecord : ReactHealthRecordImpl): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalMetabolicRateRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalMetabolicRateRecord.kt index 70b1f80..6ed3369 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalMetabolicRateRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBasalMetabolicRateRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BasalMetabolicRateRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.units.Power @@ -16,6 +18,7 @@ import dev.matinzd.healthconnect.utils.convertJsToDataOriginSet import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.getTimeRangeFilter +import dev.matinzd.healthconnect.utils.mapJsDurationToDuration import dev.matinzd.healthconnect.utils.mapJsPeriodToPeriod import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant @@ -50,6 +53,15 @@ class ReactBasalMetabolicRateRecord : ReactHealthRecordImpl): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodGlucoseRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodGlucoseRecord.kt index 621c3f0..a3dcc84 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodGlucoseRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodGlucoseRecord.kt @@ -1,9 +1,11 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BloodGlucoseRecord import androidx.health.connect.client.records.MealType.MEAL_TYPE_UNKNOWN +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.units.BloodGlucose @@ -53,10 +55,18 @@ class ReactBloodGlucoseRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResult(record: AggregationResult): WritableNativeMap { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt index d956a6c..1c43b20 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BloodPressureRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.units.Pressure @@ -58,6 +60,15 @@ class ReactBloodPressureRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -94,6 +105,20 @@ class ReactBloodPressureRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt index a04ea9b..b95654c 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BodyFatRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.units.Percentage @@ -40,10 +42,18 @@ class ReactBodyFatRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt index 49807a3..7264ac2 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt @@ -1,9 +1,11 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BodyTemperatureMeasurementLocation import androidx.health.connect.client.records.BodyTemperatureRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.units.Temperature @@ -48,6 +50,10 @@ class ReactBodyTemperatureRecord : ReactHealthRecordImpl throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -56,6 +62,10 @@ class ReactBodyTemperatureRecord : ReactHealthRecordImpl throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt index d8bd886..8bed4e4 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BodyWaterMassRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -36,6 +38,10 @@ class ReactBodyWaterMassRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -44,6 +50,10 @@ class ReactBodyWaterMassRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt index e5c27ae..79c63c6 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.BoneMassRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -41,6 +43,10 @@ class ReactBoneMassRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -49,6 +55,10 @@ class ReactBoneMassRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt index ec4977f..fcc7f56 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.CervicalMucusRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -42,6 +44,10 @@ class ReactCervicalMucusRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -50,6 +56,10 @@ class ReactCervicalMucusRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt index 8967b50..71df967 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.CyclingPedalingCadenceRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -62,6 +64,15 @@ class ReactCyclingPedalingCadenceRecord : ReactHealthRecordImpl): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactDistanceRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactDistanceRecord.kt index 7c66b0a..d6c7e57 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactDistanceRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactDistanceRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.DistanceRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -47,6 +49,15 @@ class ReactDistanceRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -63,6 +74,20 @@ class ReactDistanceRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt index 3382037..17b3ab5 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.ElevationGainedRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -45,6 +47,15 @@ class ReactElevationGainedRecord : ReactHealthRecordImpl ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -61,6 +72,20 @@ class ReactElevationGainedRecord : ReactHealthRecordImpl } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt index ae8704f..be85f4a 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt @@ -1,12 +1,14 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.ExerciseLap import androidx.health.connect.client.records.ExerciseRoute import androidx.health.connect.client.records.ExerciseRouteResult import androidx.health.connect.client.records.ExerciseSegment import androidx.health.connect.client.records.ExerciseSessionRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -144,6 +146,15 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -166,6 +177,20 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt index 3156710..753a7d5 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.FloorsClimbedRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -45,6 +47,15 @@ class ReactFloorsClimbedRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -61,6 +72,20 @@ class ReactFloorsClimbedRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt index 7812689..c5d020e 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecord.kt @@ -2,9 +2,11 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.records.Record import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.ReadRecordsRequest import androidx.health.connect.client.response.InsertRecordsResponse import androidx.health.connect.client.response.ReadRecordResponse @@ -79,12 +81,24 @@ class ReactHealthRecord { return recordClass.getAggregateGroupByPeriodRequest(reactRequest) } + fun getAggregateGroupByDurationRequest(recordType: String, reactRequest: ReadableMap): AggregateGroupByDurationRequest { + val recordClass = createReactHealthRecordInstance(recordType) + + return recordClass.getAggregateGroupByDurationRequest(reactRequest) + } + fun parseAggregationResult(recordType: String, result: AggregationResult): WritableNativeMap { val recordClass = createReactHealthRecordInstance(recordType) return recordClass.parseAggregationResult(result) } + fun parseAggregationResultGroupedByDuration(recordType: String, result: List): WritableNativeArray { + val recordClass = createReactHealthRecordInstance(recordType) + + return recordClass.parseAggregationResultGroupedByDuration(result) + } + fun parseAggregationResultGroupedByPeriod(recordType: String, result: List): WritableNativeArray { val recordClass = createReactHealthRecordInstance(recordType) diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecordImpl.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecordImpl.kt index 36c2a14..cdff7d4 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecordImpl.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHealthRecordImpl.kt @@ -1,9 +1,11 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.Record import androidx.health.connect.client.request.AggregateRequest +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap @@ -14,7 +16,9 @@ interface ReactHealthRecordImpl { fun parseWriteRecord(records: ReadableArray): List fun parseRecord(record: T): WritableNativeMap fun getAggregateRequest(record: ReadableMap): AggregateRequest + fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest fun parseAggregationResult(record: AggregationResult): WritableNativeMap + fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt index d292f93..af67ad7 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.HeartRateRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -63,6 +65,15 @@ class ReactHeartRateRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -82,6 +93,20 @@ class ReactHeartRateRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt index d4d7f95..b4b1b8c 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.HeartRateVariabilityRmssdRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -40,6 +42,10 @@ class ReactHeartRateVariabilityRmssdRecord : throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -48,6 +54,10 @@ class ReactHeartRateVariabilityRmssdRecord : throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt index 6d05598..7b36e90 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.HeightRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -46,6 +48,15 @@ class ReactHeightRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -64,6 +75,20 @@ class ReactHeightRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt index bac39e0..42996ec 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.HydrationRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -45,6 +47,15 @@ class ReactHydrationRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -61,6 +72,20 @@ class ReactHydrationRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt index 1b16a8f..29849a7 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.IntermenstrualBleedingRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -37,6 +39,10 @@ class ReactIntermenstrualBleedingRecord : ReactHealthRecordImpl): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactLeanBodyMassRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactLeanBodyMassRecord.kt index 94daacc..59028c9 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactLeanBodyMassRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactLeanBodyMassRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.LeanBodyMassRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -36,6 +38,10 @@ class ReactLeanBodyMassRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -44,6 +50,10 @@ class ReactLeanBodyMassRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt index 753e4a5..ea25e5b 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.MenstruationFlowRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -40,6 +42,10 @@ class ReactMenstruationFlowRecord : ReactHealthRecordImpl): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationPeriodRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationPeriodRecord.kt index ab11c2b..1225a82 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationPeriodRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationPeriodRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.MenstruationPeriodRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -40,6 +42,10 @@ class ReactMenstruationPeriodRecord : ReactHealthRecordImpl): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactNutritionRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactNutritionRecord.kt index 2cbe287..d7f1763 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactNutritionRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactNutritionRecord.kt @@ -1,9 +1,11 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.MealType import androidx.health.connect.client.records.NutritionRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -173,6 +175,15 @@ class ReactNutritionRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -236,6 +247,20 @@ class ReactNutritionRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt index ac1adc6..e65d26f 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.OvulationTestRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -40,6 +42,10 @@ class ReactOvulationTestRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -48,6 +54,10 @@ class ReactOvulationTestRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt index 23ea818..c3998f1 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.OxygenSaturationRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import androidx.health.connect.client.units.Percentage @@ -40,6 +42,10 @@ class ReactOxygenSaturationRecord : ReactHealthRecordImpl): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactPowerRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactPowerRecord.kt index 0082c28..626deef 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactPowerRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactPowerRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.PowerRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -62,6 +64,15 @@ class ReactPowerRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -80,6 +91,20 @@ class ReactPowerRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt index fedfc3b..902c540 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.RespiratoryRateRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -37,6 +39,10 @@ class ReactRespiratoryRateRecord : ReactHealthRecordImpl throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -45,6 +51,10 @@ class ReactRespiratoryRateRecord : ReactHealthRecordImpl throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt index 5fe0368..7e43455 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.RestingHeartRateRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -46,6 +48,16 @@ class ReactRestingHeartRateRecord : ReactHealthRecordImpl): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSexualActivityRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSexualActivityRecord.kt index fa4bbe6..af690ee 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSexualActivityRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSexualActivityRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.SexualActivityRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -39,6 +41,10 @@ class ReactSexualActivityRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -47,6 +53,10 @@ class ReactSexualActivityRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt index a317368..dac9b7c 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.SleepSessionRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -63,6 +65,15 @@ class ReactSleepSessionRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -82,6 +93,20 @@ class ReactSleepSessionRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt index fae1ea4..6edde6f 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.SpeedRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -62,6 +64,15 @@ class ReactSpeedRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -80,6 +91,20 @@ class ReactSpeedRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt index e34d207..cf8edc4 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.StepsCadenceRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -62,6 +64,15 @@ class ReactStepsCadenceRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -80,6 +91,20 @@ class ReactStepsCadenceRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt index 90b6452..0675309 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.StepsRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -45,6 +47,15 @@ class ReactStepsRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -61,6 +72,20 @@ class ReactStepsRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt index 170539b..168080a 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.TotalCaloriesBurnedRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -45,6 +47,15 @@ class ReactTotalCaloriesBurnedRecord : ReactHealthRecordImpl): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactVo2MaxRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactVo2MaxRecord.kt index 6b95c2f..e6fe3d4 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactVo2MaxRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactVo2MaxRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.Vo2MaxRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -45,6 +47,10 @@ class ReactVo2MaxRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + throw AggregationNotSupported() + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { throw AggregationNotSupported() } @@ -53,6 +59,10 @@ class ReactVo2MaxRecord : ReactHealthRecordImpl { throw AggregationNotSupported() } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + throw AggregationNotSupported() + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { throw AggregationNotSupported() } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt index c8e2532..f8de290 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.WeightRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -46,6 +48,15 @@ class ReactWeightRecord : ReactHealthRecordImpl { ) } + override fun getAggregateGroupByDurationRequest(record: ReadableMap): AggregateGroupByDurationRequest { + return AggregateGroupByDurationRequest( + metrics = aggregateMetrics, + timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"), + timeRangeSlicer = mapJsDurationToDuration(record.getMap("timeRangeSlicer")), + dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter")) + ) + } + override fun getAggregateGroupByPeriodRequest(record: ReadableMap): AggregateGroupByPeriodRequest { return AggregateGroupByPeriodRequest( metrics = aggregateMetrics, @@ -64,6 +75,20 @@ class ReactWeightRecord : ReactHealthRecordImpl { } } + override fun parseAggregationResultGroupedByDuration(record: List): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt index dd6e765..bbf9747 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt @@ -1,8 +1,10 @@ package dev.matinzd.healthconnect.records import androidx.health.connect.client.aggregate.AggregationResult +import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.records.WheelchairPushesRecord +import androidx.health.connect.client.request.AggregateGroupByDurationRequest import androidx.health.connect.client.request.AggregateGroupByPeriodRequest import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray @@ -45,6 +47,15 @@ class ReactWheelchairPushesRecord : ReactHealthRecordImpl): WritableNativeArray { + return WritableNativeArray().apply { + record.forEach { + val map = WritableNativeMap().apply { + putMap("result", parseAggregationResult(it.result)) + putString("startTime", it.startTime.toString()) + putString("endTime", it.endTime.toString()) + putString("zoneOffset", it.zoneOffset.toString()) + } + pushMap(map) + } + } + } + override fun parseAggregationResultGroupedByPeriod(record: List): WritableNativeArray { return WritableNativeArray().apply { record.forEach { diff --git a/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt b/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt index ec07b5b..b595ec1 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/utils/HealthConnectUtils.kt @@ -15,6 +15,7 @@ import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.records.* import java.time.Instant import java.time.ZoneOffset +import java.time.Duration import java.time.Period import kotlin.reflect.KClass @@ -457,16 +458,31 @@ fun convertChangesTokenRequestOptionsFromJS(options: ReadableMap): ChangesTokenR ) } +fun mapJsDurationToDuration(duration: ReadableMap?): Duration { + if (duration == null) { + return Duration.ofDays(0) + } + val length = duration.getInt("length").toLong() + return when (duration.getString("duration")) { + "MILLIS" -> Duration.ofMillis(length) + "SECONDS" -> Duration.ofSeconds(length) + "MINUTES" -> Duration.ofMinutes(length) + "HOURS" -> Duration.ofHours(length) + "DAYS" -> Duration.ofDays(length) + else -> Duration.ofDays(length) + } +} + fun mapJsPeriodToPeriod(period: ReadableMap?): Period { if (period == null) { return Period.ofDays(0) } - val duration = period.getInt("duration") + val length = period.getInt("length") return when (period.getString("period")) { - "DAYS" -> Period.ofDays(duration) - "WEEKS" -> Period.ofWeeks(duration) - "MONTHS" -> Period.ofMonths(duration) - "YEARS" -> Period.ofYears(duration) - else -> Period.ofDays(duration) + "DAYS" -> Period.ofDays(length) + "WEEKS" -> Period.ofWeeks(length) + "MONTHS" -> Period.ofMonths(length) + "YEARS" -> Period.ofYears(length) + else -> Period.ofDays(length) } } diff --git a/android/src/oldarch/HealthConnectSpec.kt b/android/src/oldarch/HealthConnectSpec.kt index b54692c..88c48a7 100644 --- a/android/src/oldarch/HealthConnectSpec.kt +++ b/android/src/oldarch/HealthConnectSpec.kt @@ -38,6 +38,9 @@ abstract class HealthConnectSpec internal constructor(context: ReactApplicationC @ReactMethod abstract fun aggregateRecord(record: ReadableMap, promise: Promise); + @ReactMethod + abstract fun aggregateGroupByDuration(record: ReadableMap, promise: Promise); + @ReactMethod abstract fun aggregateGroupByPeriod(record: ReadableMap, promise: Promise); diff --git a/example/src/App.tsx b/example/src/App.tsx index eeb211a..634ff29 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -3,6 +3,7 @@ import * as React from 'react'; import { Button, StyleSheet, View } from 'react-native'; import { aggregateRecord, + aggregateGroupByDuration, aggregateGroupByPeriod, getGrantedPermissions, initialize, @@ -21,20 +22,20 @@ import { } from 'react-native-health-connect'; const getBeginningOfLast7Days = () => { - const day = new Date(); - day.setDate(day.getDate() - 7); - day.setHours(0, 0, 0, 0); - return day; + const date = new Date(); + date.setDate(date.getDate() - 7); + date.setHours(0, 0, 0, 0); + return date; }; const getBeginningOfLast14Days = () => { - const day = new Date(); - day.setDate(day.getDate() - 14); - day.setHours(0, 0, 0, 0); - return day; + const date = new Date(); + date.setDate(date.getDate() - 14); + date.setHours(0, 0, 0, 0); + return date; }; -const getTodayDate = (): Date => { +const now = () => { return new Date(); }; @@ -73,17 +74,17 @@ export default function App() { (acc: HealthConnectRecord[], _, i) => { // Step count increases by 1000 starting from the first day (7 days ago) const stepCount = startingStepCount + i * 1000; - const day = new Date(); + const date = new Date(); // Get the date for each of the last 7 days, starting from 7 days ago (excluding today) - day.setDate(day.getDate() - (days - i)); + date.setDate(date.getDate() - (days - i)); // Set start time to 9am - const startTime = new Date(day); + const startTime = new Date(date); startTime.setHours(9, 0, 0, 0); // Set end time to 11am - const endTime = new Date(day); + const endTime = new Date(date); endTime.setHours(11, 0, 0, 0); const record: HealthConnectRecord = { @@ -122,7 +123,7 @@ export default function App() { timeRangeFilter: { operator: 'between', startTime: getBeginningOfLast14Days().toISOString(), - endTime: getTodayDate().toISOString(), + endTime: now().toISOString(), }, }) .then((result) => { @@ -149,27 +150,50 @@ export default function App() { timeRangeFilter: { operator: 'between', startTime: getBeginningOfLast7Days().toISOString(), - endTime: getTodayDate().toISOString(), + endTime: now().toISOString(), }, }).then((result) => { console.log('Aggregated record: ', { result }); }); }; + const aggregateSampleGroupByDuration = () => { + aggregateGroupByDuration({ + recordType: 'Steps', + timeRangeFilter: { + operator: 'between', + startTime: getBeginningOfLast7Days().toISOString(), + endTime: now().toISOString(), + }, + timeRangeSlicer: { + duration: 'DAYS', + length: 2, + }, + }).then((result) => { + console.log( + 'Aggregated Group by Duration: ', + JSON.stringify({ result }, null, 2) + ); + }); + }; + const aggregateSampleGroupByPeriod = () => { aggregateGroupByPeriod({ recordType: 'Steps', timeRangeFilter: { operator: 'between', startTime: getBeginningOfLast7Days().toISOString(), - endTime: getTodayDate().toISOString(), + endTime: now().toISOString(), }, timeRangeSlicer: { period: 'DAYS', - duration: 1, + length: 1, }, }).then((result) => { - console.log('Aggregated Group: ', JSON.stringify({ result }, null, 2)); + console.log( + 'Aggregated Group by Period: ', + JSON.stringify({ result }, null, 2) + ); }); }; @@ -225,7 +249,11 @@ export default function App() {