cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
551 stars 681 forks source link

[Health 10.2.0] Fetched data are not accurate #982

Open AdamBrejcak opened 5 months ago

AdamBrejcak commented 5 months ago

[Health 10.2.0] Fetched data are not accurate

Device / Emulator and OS

Describe the bug

I used my personal device for testing. let's say that i went for a walk in the morning at 8am and i did 5000 steps, and this is the only time i did some exercise for today, currently it's 10pm, the issue is when I call Health().getTotalStepsInInterval or even Health().getHealthIntervalDataFromTypes (with STEPS type and READ permission), with time window from 12pm until now (10pm), this will return some steps/value, this is not correct from my perspective as it should return 0 since in given time window i did NOT do any walking/steps

To Reproduce

Implement Health package as per documentation, then use any app which will track your steps (e.g. Samsung Health or Google Fit) make sure this app is allowed in google health connect, add walikng activity (or on physical device walk), in the morning for current day, then request steps from Health package by Health().getTotalStepsInInterval or even by Health().getHealthIntervalDataFrom but only for the afternoon today, see example below

        final List<HealthDataType> types = [HealthDataType.STEPS];
        final List<HealthDataAccess> permissions = [HealthDataAccess.READ];

        final DateTime now = DateTime.now();
        final DateTime noonToday = DateTime(now.year, now.month, now.day, 12);
        final DateTime midnightToday =
            DateTime(now.year, now.month, now.day, 23, 59);

        int? stepsFromInterval =
            await Health().getTotalStepsInInterval(noonToday, midnightToday);

        List<HealthDataPoint> stepsDataFromTypes = await Health()
            .getHealthDataFromTypes(
                types: types, startTime: noonToday, endTime: midnightToday);

Main idea here is that Health package should return 0 steps if there is no exercise done in given time window

Expected behavior

I would expect in this use case that getTotalStepsInInterval and also getHealthDataFromTypes to return 0 steps/value, since only exercise i did, was done before the time window that was passed in request

Actual behavior

getTotalStepsInInterval will return some steps/value, same with getHealthDataFromTypes (seems it's somehow calculated as average value for given day without considering when the exercise was done)

Flutter doctor -v

[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.22621.2428], locale sk-SK)
    • Flutter version 3.19.6 on channel stable at C:\Users\USER\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (8 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\USER\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2023.3)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)

[√] VS Code (version 1.90.1)
    • VS Code at C:\Users\USER\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.90.0

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.2428]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 126.0.6478.61
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 125.0.2535.92

[√] Network resources
    • All expected network resources are available.
ricoberger commented 3 months ago

Hi, I think I have the similar problem, but with Apple Health and other functions.

Device / Emulator and OS

Describe the bug

I'm using the getHealthDataFromTypes function to get the values for the current data for ACTIVE_ENERGY_BURNED, BASAL_ENERGY_BURNED and DIETARY_ENERGY_CONSUMED. Besides that I'm also using the getHealthIntervalDataFromTypes function for the same data types to get the values for each day of the last 7 days.

While getHealthIntervalDataFromTypes returns the same data as shown in the Apple Health app for the current day, getHealthDataFromTypes return different values.

To Reproduce

To reproduce this, the following app can be run on an iOS device https://github.com/ricoberger/energydiff. If you have the mentioned data in Apple Health, there should be different values for Today and in the History where also the current day is shown (see screenshot). When I run the app on the emulator and insert the Health data manually I can not reproduce this problem.

1

Expected behavior

getHealthDataFromTypes and getHealthIntervalDataFromTypes should return the same data for the same time range.

Actual behavior

getHealthDataFromTypes and getHealthIntervalDataFromTypes are returning different values for the same time range. The values from getHealthDataFromTypes are the ones which are looking wrong.

Flutter doctor -v

[✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-arm64, locale de-DE)
    • Flutter version 3.24.0 on channel stable at /Users/ricoberger/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (2 weeks ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/ricoberger/Library/Android/sdk
    • Platform android-34, build-tools 33.0.1
    • ANDROID_HOME = /Users/ricoberger/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.92.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.94.0

[✓] Connected device (4 available)
    • Ricos iPhone 15 Pro Max (mobile) • 00008130-000538CE3EF0001C • ios            • iOS 17.5.1 21F90
    • macOS (desktop)                  • macos                     • darwin-arm64   • macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop)  • mac-designed-for-ipad     • darwin         • macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                     • chrome                    • web-javascript • Google Chrome 127.0.6533.120

[✓] Network resources
    • All expected network resources are available.

• No issues found!