@@ -28,18 +28,6 @@ struct BLECharacteristicHandler {
2828 @AppStorage ( " lastTimeCheckCompleted " ) var lastTimeCheckCompleted : Double = 0
2929 @AppStorage ( " lastTimeStepGoalNotified " ) var lastTimeStepGoalNotified : Double = 0
3030
31- func fetchHeartPoints( ) -> [ HeartDataPoint ] {
32- let fetchRequest : NSFetchRequest < HeartDataPoint > = HeartDataPoint . fetchRequest ( )
33- fetchRequest. sortDescriptors = [ NSSortDescriptor ( key: " timestamp " , ascending: true ) ]
34-
35- do {
36- return try persistenceController. container. viewContext. fetch ( fetchRequest)
37- } catch {
38- log ( " Error fetching heart points: \( error) " , caller: " BLECharacteristicHandler " )
39- return [ ]
40- }
41- }
42-
4331 func heartRate( from characteristic: CBCharacteristic ) -> Int {
4432 guard let characteristicData = characteristic. value else { return - 1 }
4533 let byteArray = [ UInt8] ( characteristicData)
@@ -130,14 +118,14 @@ struct BLECharacteristicHandler {
130118 let timeDifference = currentTime - lastHeartRateUpdateTimestamp
131119
132120 // Check if the last data point is available and if filtering is enabled
133- if let referenceValue = fetchHeartPoints ( ) . last? . value, filterHeartRateData {
121+ if let referenceValue = chartManager . heartPoints ( ) . last? . value, filterHeartRateData {
134122 let isWithinRange = abs ( referenceValue - bleManager. heartRate) <= 25
135123
136124 // Update heart rate if within the valid range or recent enough
137125 if isWithinRange || timeDifference <= 15 {
138126 updateHeartRate ( bpm: bpm)
139127 } else {
140- log ( " Abnormal heart rate value detected: \( bpm) " , caller: " BLECharacteristicHandler " )
128+ log ( " Abnormal heart rate value detected: \( bpm) " , type : . info , caller: " BLECharacteristicHandler " )
141129 }
142130 } else {
143131 // If no last data point or filtering is not applied, update heart rate
0 commit comments