react-native-health-connect icon indicating copy to clipboard operation
react-native-health-connect copied to clipboard

How to use AggregateGroupByPeriodRequest and AggregateGroupByDurationRequest?

Open nightskyhub opened this issue 2 years ago • 6 comments

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.

nightskyhub avatar Apr 05 '23 09:04 nightskyhub

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);
});

matinzd avatar Apr 05 '23 09:04 matinzd

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

nightskyhub avatar Apr 05 '23 10:04 nightskyhub

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 avatar Apr 05 '23 10:04 matinzd

@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

chganesh avatar Jul 18 '23 04:07 chganesh

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

cannyRamji avatar Sep 26 '23 11:09 cannyRamji

Hello @matinzd, Is there a plan to fulfil this feature?

shesellsanctuary avatar May 29 '24 11:05 shesellsanctuary

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 avatar Sep 06 '24 22:09 matinzd

@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

taisuke-j avatar Sep 11 '24 12:09 taisuke-j