cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
550 stars 678 forks source link

[Health 6.0.0] Incorrect dataType for Swimming activity pulled from Google Fit #1063

Closed agilst closed 2 weeks ago

agilst commented 4 weeks ago

Remember to specify the plugin name in the title!

Device / Emulator and OS

Please complete the following information for each phone and/or emulator you're experiencing this bug on:

Description

Swimming activity on Google Fit always pulled as double activities with the same value, the first one as DISTANCE_DELTA and the other one is WORKOUT - OTHER.

// First activity
I/flutter (29481):     HealthActivity - 
I/flutter (29481):     value: 800.0,
I/flutter (29481):     unit: METER,
I/flutter (29481):     dateFrom: 2024-10-24 09:18:00.000,
I/flutter (29481):     dateTo: 2024-10-24 09:48:00.001,
I/flutter (29481):     dataType: DISTANCE_DELTA,
I/flutter (29481):     platform: PlatformType.ANDROID,
I/flutter (29481):     deviceId: SP1A.210812.016,
I/flutter (29481):     sourceId: ,
I/flutter (29481):     sourceName: com.google.android.apps.fitness

// Second activity
I/flutter (29481):     HealthActivity - 
I/flutter (29481):     value: workoutActivityType: OTHER,
I/flutter (29481):            totalEnergyBurned: 249,
I/flutter (29481):            totalEnergyBurnedUnit: KILOCALORIE,
I/flutter (29481):            totalDistance: 800,
I/flutter (29481):            totalDistanceUnit: METER,
I/flutter (29481):     unit: NO_UNIT,
I/flutter (29481):     dateFrom: 2024-10-24 09:18:00.000,
I/flutter (29481):     dateTo: 2024-10-24 09:48:00.000,
I/flutter (29481):     dataType: WORKOUT,
I/flutter (29481):     platform: PlatformType.ANDROID,
I/flutter (29481):     deviceId: SP1A.210812.016,
I/flutter (29481):     sourceId: ,
I/flutter (29481):     sourceName: com.google.android.apps.fitness

On top of that, the dateTo has .001 millisecond different. can it be fetched as single data with a correct dataType?

To Reproduce

Fetch data as usual

List<HealthActivity> healthPoints =
    (await health.getHealthDataFromTypes(
  now.subtract(Duration(days: 30)),
  now,
  HealthRecord.recordClassTypes,
))
        .map((e) => e.activity)
        .toList();

healthPoints.removeWhere((e) => e.distance < 0.1);
healthPoints.sort((a, b) => b.dateTo.compareTo(a.dateTo));
print('${healthPoints}');

Expected behavior

Doubled data should be pulled as single data with a correct dataType

Screenshots

unnamed-2

iarata commented 3 weeks ago

Could you confirm if you are using the health version 6 and not the latest? is it possible to test with the latest release? However, I can't see why this is a problem. The health package is designed to handle different types of health data which includes distance and workout activities which are two separate things.

The date format is correct and we are using ISO 8601 date format which you can easily convert to other types if you need to.

agilst commented 2 weeks ago

Yes, I was using the health version 6 and indeed there are some duplicate data with different WorkoutType pulled from Apple Health. However, I can mark this as solved as I have upgraded the health package to latest version and confirm no duplicate data.

uuid: E8245A64-1DB9-4364-9EBC-A90B3DB9A51E,
    value: WorkoutHealthValue - workoutActivityType: SWIMMING_OPEN_WATER,
           totalEnergyBurned: null,
           totalEnergyBurnedUnit: KILOCALORIE,
           totalDistance: 213,
           totalDistanceUnit: METER
           totalSteps: null,
           totalStepsUnit: null,
    unit: NO_UNIT,
    dateFrom: 2024-10-14 16:37:00.000,
    dateTo: 2024-10-14 18:37:00.000,
    dataType: WORKOUT,
    platform: HealthPlatformType.appleHealth,
    deviceId: C2F97EBB-B5B6-477B-8BB1-637EBFD037D0,
    sourceId: com.apple.Health,
    sourceName: Health
    recordingMethod: RecordingMethod.unknown
    workoutSummary: null
    metadata: null