Skip to content

Commit

Permalink
feat: add support to elevation gained aggregation (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielgouv authored Aug 4, 2024
1 parent 6965097 commit f513500
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ class ReactElevationGainedRecord : ReactHealthRecordImpl<ElevationGainedRecord>
}

override fun getAggregateRequest(record: ReadableMap): AggregateRequest {
throw AggregationNotSupported()
return AggregateRequest(
metrics = setOf(
ElevationGainedRecord.ELEVATION_GAINED_TOTAL
),
timeRangeFilter = record.getTimeRangeFilter("timeRangeFilter"),
dataOriginFilter = convertJsToDataOriginSet(record.getArray("dataOriginFilter"))
)
}

override fun parseAggregationResult(record: AggregationResult): WritableNativeMap {
throw AggregationNotSupported()
return WritableNativeMap().apply {
putMap("ELEVATION_GAINED_TOTAL", lengthToJsMap(record[ElevationGainedRecord.ELEVATION_GAINED_TOTAL]))
putArray("dataOrigins", convertDataOriginsToJsArray(record.dataOrigins))
}
}
}
8 changes: 7 additions & 1 deletion src/types/aggregate.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ interface PowerAggregateResult extends BaseAggregate {
POWER_MAX: PowerResult;
}

interface ElevationGainedAggregateResult extends BaseAggregate {
recordType: 'ElevationGained';
ELEVATION_GAINED_TOTAL: LengthResult;
}

export type AggregateRecordResult =
| ActiveCaloriesBurnedAggregateResult
| BasalMetabolicRateAggregateResult
Expand All @@ -195,7 +200,8 @@ export type AggregateRecordResult =
| WheelchairPushesAggregateResult
| StepsCadenceAggregateResult
| TotalCaloriesBurnedAggregateResult
| PowerAggregateResult;
| PowerAggregateResult
| ElevationGainedAggregateResult;

export type AggregateResultRecordType = AggregateRecordResult['recordType'];

Expand Down

0 comments on commit f513500

Please sign in to comment.