OvalMoney / react-native-fitness

A React Native module to interact with Apple Healthkit and Google Fit.
MIT License
343 stars 68 forks source link

Feature request - Option to filter manually entered data #47

Open antoinedelp opened 4 years ago

antoinedelp commented 4 years ago

Hi and thanks for this neat package!

I'm submitting a feature request for the possibility to left out user entered data when querying for distance/steps. This would enable to use only "real" data.

As a test, I managed to implement it in the iOs version of GetSteps by doing the following:

NSPredicate *sourcePredicate = [NSPredicate predicateWithFormat:@"metadata.%K != YES", HKMetadataKeyWasUserEntered];

HKStatisticsCollectionQuery *query = [[HKStatisticsCollectionQuery alloc] initWithQuantityType:type quantitySamplePredicate:nil options:HKStatisticsOptionCumulativeSum anchorDate:anchorDate intervalComponents:interval];

I'd like to work on that feature request, but I do not master Swift nor Java and haven't experienced working on a bridge between RN and Native. I'm more than happy to help you, let me know how I could proceed!

Cheers

pvlvukovic commented 3 years ago

Any news on this? Would be great to filter manually entered data!

pvlvukovic commented 3 years ago

Hi and thanks for this neat package!

I'm submitting a feature request for the possibility to left out user entered data when querying for distance/steps. This would enable to use only "real" data.

As a test, I managed to implement it in the iOs version of GetSteps by doing the following:

  • Declare a predicate that leaves out User Entered data

NSPredicate *sourcePredicate = [NSPredicate predicateWithFormat:@"metadata.%K != YES", HKMetadataKeyWasUserEntered];

  • Use this predicate when querying:

HKStatisticsCollectionQuery *query = [[HKStatisticsCollectionQuery alloc] initWithQuantityType:type quantitySamplePredicate:nil options:HKStatisticsOptionCumulativeSum anchorDate:anchorDate intervalComponents:interval];

I'd like to work on that feature request, but I do not master Swift nor Java and haven't experienced working on a bridge between RN and Native. I'm more than happy to help you, let me know how I could proceed!

Cheers

this seems to work, still needs testing.

Perhaps there is a solution for android also In Manager.java there are processSteps and processDistances methods

            if (!"user_input".equals(dp.getOriginalDataSource().getStreamName())) {
                caloryMap.putString("startDate", dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
                caloryMap.putString("endDate", dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)));
                caloryMap.putDouble("quantity", dp.getValue(field).asFloat());
                map.pushMap(caloryMap);
            }

            This if might solve it
IsaacInsoll commented 1 year ago

Hi, It seems like someone has already made a fork that does the 'exclude user entered data' on both the android and iOS side: https://github.com/LVGP2021/react-native-fitness

It seems like this should be exposed as an option when querying (IE: either 'get all steps' or 'get not-manually-entered-steps) rather than it being 'hard ignored' all the time.

Is this project still active? If so I might refactor that code to make it an option and then do an MR in :)

Francesco-Voto commented 1 year ago

Hi @IsaacInsoll , thanks foor your reply. Feel free to open a PR, any help will be appreciated