Jonas Björkert 2 лет назад
Родитель
Сommit
f60795b21a

+ 1 - 1
LoopFollow/Controllers/Nightscout/DeviceStatus.swift

@@ -83,7 +83,7 @@ extension MainViewController {
         
     // NS Device Status Response Processor
     func updateDeviceStatusDisplay(jsonDeviceStatus: [[String:AnyObject]]) {
-        infoManager.clearInfoData(types: [.iob, .cob, .override, .battery, .pump, .target, .isf])
+        infoManager.clearInfoData(types: [.iob, .cob, .override, .battery, .pump, .target, .isf, .carbRatio])
 
         if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Process: device status") }
         if jsonDeviceStatus.count == 0 {

+ 8 - 0
LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift

@@ -1,3 +1,11 @@
+//
+//  DeviceStatusOpenAPS.swift
+//  LoopFollow
+//
+//  Created by Jonas Björkert on 2024-05-19.
+//  Copyright © 2024 Jon Fawcett. All rights reserved.
+//
+
 import Foundation
 import UIKit
 

+ 1 - 2
LoopFollow/Controllers/Nightscout/ProfileManager.swift

@@ -67,10 +67,9 @@ struct ProfileManager {
         return nil
     }
 
-    //TODO: Formatting
     func currentBasal() -> String? {
         if let basal = getCurrentValue(from: basalSchedule) {
-            return formatValue(basal)
+            return Localizer.formatToLocalizedString(basal, maxFractionDigits: 2, minFractionDigits: 0)
         }
         return nil
     }

+ 7 - 4
LoopFollow/Controllers/Nightscout/Treatments/Basals.swift

@@ -137,12 +137,11 @@ extension MainViewController {
             //if i == tempArray.count - 1 && dateTimeStamp + duration <= dateTimeUtils.getNowTimeIntervalUTC() {
             if i == tempArray.count - 1 && duration == 0.0 {
                 lastEndDot = dateTimeStamp + (30 * 60)
-                latestBasal = String(format:"%.2f", basalRate)
             } else {
                 lastEndDot = dateTimeStamp + (duration * 60)
-                latestBasal = String(format:"%.2f", basalRate)
             }
-            
+            latestBasal = Localizer.formatToLocalizedString(basalRate, maxFractionDigits: 2, minFractionDigits: 0)
+
             // Double check for overlaps of incorrectly ended TBRs and sent it to end when the next one starts if it finds a discrepancy
             if i < tempArray.count - 1 {
                 let nextEntry = tempArray[i + 1] as [String : AnyObject]?
@@ -187,7 +186,7 @@ extension MainViewController {
                 }
             }
             
-            latestBasal = String(format:"%.2f", scheduled)
+            latestBasal = Localizer.formatToLocalizedString(scheduled, maxFractionDigits: 2, minFractionDigits: 0)
             // Make the starting dot at the last ending dot
             let startDot = basalGraphStruct(basalRate: scheduled, date: Double(lastEndDot))
             basalData.append(startDot)
@@ -200,6 +199,10 @@ extension MainViewController {
         if UserDefaultsRepository.graphBasal.value {
             updateBasalGraph()
         }
+
+        if let profileBasal = profileManager.currentBasal(), profileBasal != latestBasal {
+            latestBasal = "\(profileBasal) → \(latestBasal)"
+        }
         infoManager.updateInfoData(type: .basal, value: latestBasal)
     }
 }

+ 3 - 3
LoopFollow/helpers/Localizer.swift

@@ -10,11 +10,11 @@ import Foundation
 
 
 class Localizer {
-    static func formatToLocalizedString(_ value: Double) -> String {
+    static func formatToLocalizedString(_ value: Double, maxFractionDigits: Int = 1, minFractionDigits: Int = 0) -> String {
         let numberFormatter = NumberFormatter()
         numberFormatter.numberStyle = .decimal
-        numberFormatter.maximumFractionDigits = 1
-        numberFormatter.minimumFractionDigits = 0
+        numberFormatter.maximumFractionDigits = maxFractionDigits
+        numberFormatter.minimumFractionDigits = minFractionDigits
         numberFormatter.locale = Locale.current
 
         let numberValue = NSNumber(value: value)