react-native-health-connect
react-native-health-connect copied to clipboard
How to use AggregateGroupByPeriodRequest and AggregateGroupByDurationRequest?
How can we aggregate steps data for day. Let's say I want to fetch data for past 7 days and want count of total steps per day.
Hi
Yes! You can find it in the documentation below:
https://matinzd.github.io/react-native-health-connect/docs/api/methods/aggregateRecord
Each record type has its own result type. You can try Steps record and see what results you'll get. If you want tota steps count for each day, you need to chunk below example into 7 different days.
Example:
aggregateRecord({
recordType: 'Steps',
timeRangeFilter: {
operator: 'between',
startTime: new Date(
new Date().getTime() - 7 * 24 * 60 * 60 * 1000 // 7 days
).toISOString(),
endTime: new Date().toISOString(),
},
}).then((result) => {
console.log(result.COUNT_TOTAL);
});
Thanks for the quick reply. Can we use AggregateGroupByDurationRequest or AggregateGroupByPeriodRequest ?
https://developer.android.com/guide/health-and-fitness/health-connect/common-workflows/aggregate-data#buckets
https://developer.android.com/guide/health-and-fitness/health-connect/common-workflows/aggregate-data#duration
https://developer.android.com/guide/health-and-fitness/health-connect/common-workflows/aggregate-data#period
Thanks for pointing these out. I think these were added in the recent versions and it's not supported yet. I will add those to the roadmap.
@matinzd @nightskyhub How can we aggregate steps data for day and All vitals . Let's say I want to fetch data for past 7 and 30 days and want count of total steps per day.
i want display all vitals and steps and burned calories sleep ...etc is is possible to display all this stuff please help on this
thanks in advance
Hi @matinzd, When we can expect this feature, we are facing performance issue due to this. iOS by default provide payload in 1 Hour range
https://github.com/matinzd/react-native-health-connect/issues/16#issuecomment-1497233505
Hello @matinzd, Is there a plan to fulfil this feature?
If someone is up for sponsoring I will dedicate some time to implement it. Otherwise you can fork the project and add it yourself.
@matinzd Just made a PR integrating aggregateGroupByPeriod API. Would be great if you could take a look
https://github.com/matinzd/react-native-health-connect/pull/157