Is heartRate data from an HKWorkoutSession a moving average?

穿精又带淫゛_ 提交于 2021-02-11 13:56:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!