Hi,
I am currently developing feature that is using Health Kit to get data from apple watch. I noticed that all Workout Data I created from my Apple Watch SE doesn't have metadata mentioning about average HR value, but in the Health App on workout detail report, we are able to see the "Average Heart Rate" on Related Samples.
I did some research about how to get the average Heart Rate (HR) from a workout session and the answer I could find was fetching the HR samples from the workout start - end, or using Statistic Discrete Average HR query during workout session start - end. I tried to compare both average HR value from those two queries result. From many workouts I had checked, the average HR value that almost gives consistency / almost same is Discrete Collection Average HR query.
But I found some issues :
- on some Workouts, the average HR value I get from statistic discrete average HR is not same as what shown in the Health App.
- On the Workout sample below, the end time shows wrong date, but in the workout graph, it shows correct end time.
- I noticed that the list of HR data of the "Average Heart Rate" on Related Sample section doesn't show some of HR data that has Heart Rate Context "Workout".
- On the Workout sample below, I tried to use discrete average HR query and HR samples query. the HR samples queries didn't give correct value of average HR. I also tried to calculate manually the average HR value from the list Heart Rate Data on the Related Samples "Average Heart Rate" only able to get average Workout HR: 83.31270358306189.
Detail Sample Workout from Apple Health:
"Workout Type": Running
"Start Time": 3 Oct 2022 08.12.10
"End Time" : 3 Oct 2022 23:59:59
"Duration": 27m 51,96s
"average HR": 86 bpm
Heart Rate Samples Query :
Logic: Sum all HR value and divided by the total HR data
'averageWorkoutHR': 83.31270358306189
Statistic Discrete Average HR Query
'Discrete Average:' [{
"value":85.8568822930529,
"startDate":"2022-10-03T08:12:10.000+0700",
"endDate":"2022-10-03T08:40:01.000+0700"
}, {
"value":74.33866717330343,
"startDate":"2022-10-03T08:40:01.000+0700",
"endDate":"2022-10-03T09:07:52.000+0700"
}]'
My questions are:
- what is the best practice to get the same average HR value as what Health app shown in the Workout Session "Average Heart Rate" on related sample section?
- Why Apple Health store wrong end time for the workout session?
I attached here for the pictures and the json file for all the HR samples I get from the HR Samples Query
HR sample Queries during workout session:
Workout Sample:
HR Sample Related Sample