matinzd / react-native-health-connect

React native library for health connect (Android only)
http://matinzd.github.io/react-native-health-connect
MIT License
195 stars 40 forks source link

ElevationGained returns empty array #111

Open justingshreve opened 1 month ago

justingshreve commented 1 month ago

Describe the bug I've logged an ExerciseSession (Samsung Health and Google Fit) which includes elevation gained. It syncs but the request to readRecords for ElevationGained returns an empty array. Distance comes back and the basic activity details, but no elevation.

To Reproduce Steps to reproduce the behavior:

  1. Log an exercise session activity
  2. Sync with Health Connect
  3. Sync with an app using react-native-health-connect
  4. Request elevation for the exercise session
  5. Empty array is returned

Expected behavior
Should return an array of elevation records, like the readRecords for 'Distance' that includes inMeters, etc.

Minimal Reproducible

  const rawActivities = await readRecords('ExerciseSession', {
    timeRangeFilter: {
      operator: 'after',
      startTime: from.toISOString()
    },
  });

  let activities = []
  // for each activity additional reads are required to pull distance and elevation
  for (const a of rawActivities) {
    const rawDistance = await readRecords('Distance', {
      timeRangeFilter: {
        operator: 'between',
        startTime: a.startTime,
        endTime: a.endTime
      }
    });
    const distance = rawDistance.reduce((acc, item) => {
      return acc += item.distance.inMeters
    }, 0)
   // distance is working great and returns values here

    const rawElevation = await readRecords('ElevationGained', {
      timeRangeFilter: {
        operator: 'between',
        startTime: a.startTime,
        endTime: a.endTime
      }
    });

    // rawElevation is empty array
    console.log('rawElevation', rawElevation)    
    const elevation = rawElevation.reduce((acc, item) => {
      return acc += item.elevation.inMeters
    }, 0)

    activities.push({ ...a, distance, elevation })
  }

Environment:

matinzd commented 1 month ago

Hey!

Are you seeing any errors in ADB in Android Studio or It just returns empty array? Did you try putting it in try catch and see if an exception happens?

justingshreve commented 1 month ago

@matinzd thanks for the response. There are no errors logged and the function successfully returns an empty array. It does not throw an error. Do you have any examples of this working?

gabrielgouv commented 3 weeks ago

I'm having the same issue with the power data...

But starting with the elevation gain case (and using Samsung Health). Google Fit doesn't have the option to add elevation manually (at least I didn't find it): I've checked Health Connect and the elevation gain data isn't there (maybe Samsung Health didn't publish it?).

In the case of power, I entered the exercise manually via Google Fit and when checking this data on my app, the array comes empty. I checked on Health Connect and the potency data was there. I opened this issue: https://github.com/matinzd/react-native-health-connect/issues/125

matinzd commented 3 weeks ago

Have you added any ElevationGained records? It seems that both you and @gabrielgouv might be assuming these values are automatically calculated based on the ExerciseSession, but that’s not the case. Health Connect should be viewed as a data store for different entities, and it doesn't automatically compute values based on other entities, as far as I know.

In both of your cases, it looks like you expect that by entering ExerciseSession data, you would also get ElevationGained and Power data from Health Connect. However, I don't believe that's the intended purpose of Health Connect.

justingshreve commented 3 weeks ago

I have used Google Fit with a device and recorded a true activity with real elevation gain (not manually entered) and exercise session data comes through, just no elevation gain. The array is empty.

matinzd commented 3 weeks ago

Did you check Health Connect app to see if ElevationGained data is there for that specific timeframe?