StasDoskalenko / react-native-google-fit

A React Native bridge module for interacting with Google Fit
MIT License
333 stars 209 forks source link

Mismatch in steps between getDailyStepCountSamples and Google Fit App #248

Closed ychinamale closed 10 months ago

ychinamale commented 3 years ago

Problem

When I call GoogleFit.getDailyStepCountSamples() to retrieve steps, I receive a step count that significantly lower than that shown in the Google Fit app.

Dev Environment

MacOS Big Sur React Native 0.63.3 Android Simulator - Nexus 5 API 19

Steps to Replicate

Set your step options and call the function. The code would look something like the following

const stepsOpt = {
    startDate: '2021-09-15T00:00:00.000Z', // the start of the day in question
    endDate: new Date().toISOString(), // you could also set this to the end of the day
    bucketUnit: 'MINUTE',
    bucketInterval: 1
}

const res = await GoogleFit.getDailyStepCountSamples(stepsOpt)
console.log(`\n\nMy step data is\n${JSON.stringify(res, null, 2)}\n\n`)

In the resulting log, observe data from any com.google.android.gms source. Look at the total steps, and the rawSteps. Compare this with the total number of steps shown in the Google Fit app for the same day (Can be found by opening the Google Fit app -> Home -> Trends/Steps -> Day -> See source data)

What I Observe

There is a mismatch between both the total steps and the rawSteps

What I Expected

Screenshot

On the left is a screenshot of log after running my code. The right is a screenshot of the raw data according to the Google Fit app.

Screenshot 2021-09-15 at 10 42 57
aboveyunhai commented 3 years ago

Try to twist around bucket unit and bucket interval to observe any change happens. It's based on api estimation so it's pretty normal to see mismatch as well as data delay/sync.

Also, for the startDate and endDate, maybe use 3rd party date libs like moment(it's in our deps so you can actually import it directly) instead of Date(). In some edge cases, Default Date() will cause wrong date range due to timezone.

BlagojeVukovicVicert commented 2 years ago

I had simillar problem with bad calculations of daily steps and I fixed it by setting starting date on start of the day, and end date by end of the day. And everything is calculating as in Google Fit app