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

ElevationGained returns empty array #111

Open
justingshreve opened this issue Jul 2, 2024 · 6 comments
Open

ElevationGained returns empty array #111

justingshreve opened this issue Jul 2, 2024 · 6 comments
Assignees

Comments

@justingshreve
Copy link

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:

  • Health Connect Version: 2.0.3
  • React Native Version: "0.73.5"
  • New architecture enabled: ?
  • Using Expo: Prebuild(Dev Client)
@matinzd matinzd self-assigned this Jul 10, 2024
@matinzd
Copy link
Owner

matinzd commented Jul 10, 2024

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
Copy link
Author

@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
Copy link
Contributor

gabrielgouv commented Aug 1, 2024

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: #125

@matinzd
Copy link
Owner

matinzd commented Aug 1, 2024

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
Copy link
Author

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
Copy link
Owner

matinzd commented Aug 1, 2024

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

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

No branches or pull requests

3 participants