metaflowltd / flutter_health_fit

A flutter plugin for using Apple HealthKit and Google Fit.
Other
88 stars 33 forks source link

Inaccurate data for Steps on Apple Health #24

Closed mirkancal closed 3 years ago

mirkancal commented 3 years ago

Hi guys, thank you for this package first of all. Getting data aggregated by days are amazing and it was much more stable on the tests that I do on my end. However I was facing inaccurate data from my users and I can reproduce it.

For example I want to get days between July 9-18, but I get only steps for July 2 and July 11 and they are incorrect anyway. I see 3K, 5K steps on the health application but API returns big numbers like 67K, 48K for those 2 days.

Maybe I'm using this package incorrectly, this is how I'm using.

  final steps = await flutterHealthFit.getStepsBySegment(
                earlierDate.millisecondsSinceEpoch,
                today.millisecondsSinceEpoch,
                today.difference(earlierDate).inDays,
                TimeUnit.days,
              );

I hardcoded earlier date(DateTime.parse('2021-07-09 10:00:00')) and today(DateTime.parse('2021-07-18 10:00:00'))

avi-mastov commented 3 years ago

Hi @mirkancal ! Thanks for using this package, and we're glad it you found it useful :) Indeed, I think you are using it not as intended. The 3rd argument is supposed to be the bucket size, so you're just creating one bucket of the entire range. That's why you're getting big numbers. All the steps between earlierDate and today sum up into one value. If you'd like to get data for each day, you need to pass 1 as the 3rd argument, and then you'll get buckets of 1 day.

mirkancal commented 3 years ago

@avi-mastov Thanks man! Amazing, I thought it was the difference between dates since you used today and yesterday in the example app. I really love this package, hope it will work with this fix.

avi-mastov commented 3 years ago

@mirkancal great! Please let us know if it worked. If it did, please close this issue :)