问题
I'm using an HKWorkoutSession to get heart rate data every 5 seconds in workoutBuilder didCollectDataOf
. The heart rates are reported as "beats/minute". The question is, are they calculated as moving averages, or just over the previous time interval? (I couldn't find this specified in the documentation anywhere.)
For example, if you get the following heart rates:
t=0: 69 beats/min
t=5: 71 beats/min
t=10: 72 beats/min
...
Is each value an average of beat intervals over the past 60 seconds, or is it just extrapolated from the last 5 seconds of data?
Here's what didCollectDataOf
looks like:
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) {
for type in collectedTypes {
guard let hrType = HKQuantityType.quantityType(forIdentifier: .heartRate) else {
return
}
if collectedTypes.contains(hrType) {
if let hrQuantity = workoutBuilder.statistics(for: hrType)?.mostRecentQuantity() {
let hrUnit = HKUnit(from: "count/min")
let hr = Int(hrQuantity.doubleValue(for: hrUnit))
debugPrint("\(Date()) HR: \(hr)")
}
}
}
}
回答1:
From my experience, it's not a moving average.
来源:https://stackoverflow.com/questions/59833264/is-heartrate-data-from-an-hkworkoutsession-a-moving-average