Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Health: 11.1.0] getHealthIntervalDataFromTypes(...) giving error for returning quantity data type aggregated values (Testing on IOS) #1087

Open
Kam5678 opened this issue Nov 26, 2024 · 1 comment
Labels
bugfix a bug fix

Comments

@Kam5678
Copy link

Kam5678 commented Nov 26, 2024

Plugin Name

Health

Plugin Version

11.1.0

Device

Iphone 14 Pro Max

Operating System

IOS 18.1.1

Describe the bug

The bug is that getHealthIntervalDataFromTypes() doesn't support all quantity type objects queries.

It was also a bit confusing which HealthDataType variables are supported but I believe IOS Health documentation states it:
All quantity type objects:
https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier

In my case when i was testing it worked for the following variables:

  • HealthDataType.DISTANCE_WALKING_RUNNING
  • HealthDataType.ACTIVE_ENERGY_BURNED
  • HealthDataType.BASAL_ENERGY_BURNED
  • HealthDataType.FLIGHTS_CLIMBED

But when it came to using HealthDataType.HEART_RATE I run into the following error in Xcode:

Thread 1: "Statistics option HKStatisticsOptionCumulativeSum is not compatible with discrete data type HKQuantityTypeIdentifierHeartRate"

image

Steps to Reproduce

   List<HealthDataPoint> heartRateData;
        heartRateData = await Health().getHealthIntervalDataFromTypes(
            startDate: leftBound,
            endDate: rightBound,
            types: [HealthDataType.HEART_RATE],
            interval: 43200);

Expected Behavior

I would get the data that is aggregated for the day. In this case assuming left bound is November.25 12am and right bound is November.25 11:59pm, this above query should return a list of two HealthDataPoints such that the first point represents the average bpm for the first 12 hours, and the second for the average bpm for the later 12ish hours.

Actual Behavior

**Instead I see the following error in Xcode:
Thread 1: "Statistics option HKStatisticsOptionCumulativeSum is not compatible with discrete data type HKQuantityTypeIdentifierHeartRate"**

If I am misunderstanding something any guidance would be very helpful!

Flutter Doctor Output

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.0, on macOS 14.5 23F79 darwin-arm64, locale en-CA)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.88.1)
[✓] Connected device (6 available)
[✓] Network resources

• No issues found!

Additional Information

Additional resources I looked at:
https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier
https://developer.apple.com/documentation/healthkit/hkstatisticscollectionquery
https://developer.apple.com/documentation/healthkit/queries/executing_statistics_collection_queries

@Kam5678 Kam5678 added the bugfix a bug fix label Nov 26, 2024
@iarata iarata changed the title [<Health> <11.1.0>] getHealthIntervalDataFromTypes(...) giving error for returning quantity data type aggregated values (Testing on IOS) [Health: 11.1.0] getHealthIntervalDataFromTypes(...) giving error for returning quantity data type aggregated values (Testing on IOS) Nov 27, 2024
@Kam5678
Copy link
Author

Kam5678 commented Nov 28, 2024

        HealthDataType.HEIGHT,
        HealthDataType.BODY_TEMPERATURE,
        HealthDataType.BLOOD_PRESSURE_DIASTOLIC,
        HealthDataType.BLOOD_PRESSURE_SYSTOLIC,
        HealthDataType.RESPIRATORY_RATE,
        HealthDataType.ELECTRODERMAL_ACTIVITY

I also tested the above variables and got the same error. I believe this is happening due to the way we query on this line inside the SwiftHealthPlugin.swift file**(Line: 1093)**:
image

    let query = HKStatisticsCollectionQuery(quantityType: quantityType, quantitySamplePredicate: predicate, options: [.cumulativeSum, .separateBySource], anchorDate: dateFrom, intervalComponents: interval)

Looking at the following link as reference, depending on the dataType we have to specifiy in option if we want a .cumulativeSum or .discreteAverage I believe(Heart rate for example, and the above variables in this comment would only take .discreteAverage):

https://developer.apple.com/documentation/healthkit/hkstatisticsoptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix a bug fix
Projects
None yet
Development

No branches or pull requests

1 participant