Skip to content

Commit

Permalink
docs: add aggregate group methods (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
taisuke-j authored Oct 30, 2024
1 parent 60efc22 commit 400b849
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/docs/api/methods/10-aggregateGroupByDuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: aggregateGroupByDuration
---

# `aggregateGroupByDuration`

Reads aggregated group result by Duration according to requested read criteria. `timeRangeSlicer` needs to be specified for the Duration type (`MILLIS' | 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS`) and length. Some record types do not support aggregation.

# Method

```ts
aggregateGroupByDuration<T extends AggregateResultRecordType>(
request: AggregateGroupByDurationRequest<T>
): Promise<AggregationGroupResult<T>[]>
```

# Example

```ts
import { aggregateGroupByDuration } from 'react-native-health-connect';

const aggregateSampleData = () => {
aggregateGroupByDuration({
recordType: 'Steps',
timeRangeFilter: {
operator: 'between',
startTime: '2024-10-04T15:00:00Z',
endTime: '2024-10-12T14:57:39.714Z',
},
timeRangeSlicer: {
duration: 'DAYS',
length: 2,
},
}).then((result) => {
console.log('Aggregated Group by Duration: ', { result }); // Aggregated record: {"result": [{"endTime": "2024-10-06T15:00:00Z", "startTime": "2024-10-04T15:00:00Z", "zoneOffset": "+09:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 3000}}, {"endTime": "2024-10-08T15:00:00Z", "startTime": "2024-10-06T15:00:00Z", "zoneOffset": "+09:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 7000}}, {"endTime": "2024-10-10T15:00:00Z", "startTime": "2024-10-08T15:00:00Z", "zoneOffset": "+09:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 11000}}, {"endTime": "2024-10-12T14:57:39.714Z", "startTime": "2024-10-10T15:00:00Z", "zoneOffset": "+09:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 7000}}]}
});
};
```
38 changes: 38 additions & 0 deletions docs/docs/api/methods/11-aggregateGroupByPeriod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: aggregateGroupByPeriod
---

# `aggregateGroupByPeriod`

Reads aggregated group result by Period according to requested read criteria. `timeRangeSlicer` needs to be specified for the Period type (`'DAYS' | 'WEEKS' | 'MONTHS' | 'YEARS'`) and length. `Period` is date-based amount of time as opposed to `Duration`, which is a fixed length of time. Some record types do not support aggregation.

# Method

```ts
aggregateGroupByPeriod<T extends AggregateResultRecordType>(
request: AggregateGroupByPeriodRequest<T>
): Promise<AggregationGroupResult<T>[]>
```

# Example

```ts
import { aggregateGroupByPeriod } from 'react-native-health-connect';

const aggregateSampleData = () => {
aggregateGroupByPeriod({
recordType: 'Steps',
timeRangeFilter: {
operator: 'between',
startTime: '2024-09-03T15:00',
endTime: '2024-09-11T10:50:12.182',
},
timeRangeSlicer: {
period: 'DAYS',
length: 1,
},
}).then((result) => {
console.log('Aggregated Group by Period: ', { result }); // Aggregated record: {"result": [{"endTime": "2024-09-04T15:00", "startTime": "2024-09-03T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 1000}}, {"endTime": "2024-09-05T15:00", "startTime": "2024-09-04T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 2000}}, {"endTime": "2024-09-06T15:00", "startTime": "2024-09-05T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 3000}}, {"endTime": "2024-09-07T15:00", "startTime": "2024-09-06T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 4000}}, {"endTime": "2024-09-08T15:00", "startTime": "2024-09-07T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 5000}}, {"endTime": "2024-09-09T15:00", "startTime": "2024-09-08T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 6000}}, {"endTime": "2024-09-10T15:00", "startTime": "2024-09-09T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 7000}}, {"endTime": "2024-09-11T10:50:12.182", "startTime": "2024-09-10T15:00", "result": {"dataOrigins": [], "COUNT_TOTAL": 0}}]}
});
};
```

0 comments on commit 400b849

Please sign in to comment.