Skip to content

Conversation

@sebalopezz
Copy link
Contributor

If you use query, you will probably find that the number of steps (or other types of data) do not match those shown by the Google Fit and Apple Health apps. If you wanted to accurately compute the user's data then use: queryAggregateData

iOS (Apple Health)

The query method is over-counting steps because it simply sums the results of an HKSampleQuery. A sample query will return all samples matching the given predicate, including overlapping samples from multiple sources. If you wanted to accurately compute the user's step count using HKSampleQuery, you'd have to detect overlapping samples and avoid counting them, which would be tedious and difficult to do correctly.
Health uses HKStatisticsQuery and HKStatisticsCollectionQuery to compute aggregate values. These queries calculate the sum (and other aggregate values) for you, and do so efficiently. Most importantly, though, they de-duplicate overlapping samples to avoid over-counting.
The documentation for HKStatisticsCollectionQuery includes sample code.

Android (Google Fit)

The Fit app does some additional processing on top of the steps. It estimates steps based on the activity when none are recorded.
You need to use a custom DataSource of the package com.google.android.gms.
You can find the solution on the Google Fit API FAQ page.

@sebalopezz
Copy link
Contributor Author

In case you accept this PR, please also publish a new version to npm because I'm sure more N6-using folks will encounter some issues like #30 . A major version bump would be a good idea.
Cheers,
Sebastian Lopez

@sebalopezz
Copy link
Contributor Author

Hey @EddyVerbruggen would you please consider merging this? I don't mind if not, then I'll know I'll have to ship it some other way in my app. Thx!

@cjohn001
Copy link
Member

cjohn001 commented Mar 6, 2022

included in merge vor 2.0.0

@cjohn001 cjohn001 closed this Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants