|
|
@@ -14,12 +14,16 @@ extension MainViewController {
|
|
|
|
|
|
if let lastLoopTime = formatter.date(from: (lastDeviceStatus?["created_at"] as! String))?.timeIntervalSince1970 {
|
|
|
UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
|
|
|
- if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "lastLoopTime: " + String(lastLoopTime)) }
|
|
|
if lastLoopRecord["failureReason"] != nil {
|
|
|
LoopStatusLabel.text = "X"
|
|
|
latestLoopStatusString = "X"
|
|
|
if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Loop Failure: X") }
|
|
|
} else {
|
|
|
+ var wasEnacted = false
|
|
|
+ if let enacted = lastLoopRecord["enacted"] as? [String:AnyObject] {
|
|
|
+ wasEnacted = true
|
|
|
+ }
|
|
|
+
|
|
|
if let iobdata = lastLoopRecord["iob"] as? [String:AnyObject] {
|
|
|
tableData[0].value = String(format:"%.2f", (iobdata["iob"] as! Double))
|
|
|
latestIOB = String(format:"%.2f", (iobdata["iob"] as! Double))
|
|
|
@@ -42,6 +46,29 @@ extension MainViewController {
|
|
|
tableData[11].value = String(format:"%.0f", sens) + "%"
|
|
|
}
|
|
|
|
|
|
+ if let eventualdata = lastLoopRecord["enacted"] as? [String:AnyObject] {
|
|
|
+ if let eventualBGValue = eventualdata["eventualBG"] as? NSNumber {
|
|
|
+ let eventualBGStringValue = String(describing: eventualBGValue)
|
|
|
+ PredictionLabel.text = bgUnits.toDisplayUnits(eventualBGStringValue)
|
|
|
+
|
|
|
+ //This is one possible way of showing Pred. with minPredBG /eventualBG
|
|
|
+ /*
|
|
|
+ if let reasonString = eventualdata["reason"] as? String {
|
|
|
+ let regex = try! NSRegularExpression(pattern: "minPredBG (\\d+)")
|
|
|
+ if let match = regex.firstMatch(in: reasonString, range: NSRange(location: 0, length: reasonString.utf16.count)) {
|
|
|
+ if let minPredBGRange = Range(match.range(at: 1), in: reasonString) {
|
|
|
+ let minPredBGString = String(reasonString[minPredBGRange])
|
|
|
+ tableData[9].value = "\(bgUnits.toDisplayUnits(String(minPredBGString)))/\(bgUnits.toDisplayUnits(eventualBGStringValue))"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tableData[9].value = bgUnits.toDisplayUnits(eventualBGStringValue)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tableData[9].value = bgUnits.toDisplayUnits(eventualBGStringValue)
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var predictioncolor = UIColor.systemGray
|
|
|
PredictionLabel.textColor = predictioncolor
|
|
|
topPredictionBG = UserDefaultsRepository.minBGScale.value
|
|
|
@@ -78,7 +105,27 @@ extension MainViewController {
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if let loopStatus = lastLoopRecord["recommendedTempBasal"] as? [String:AnyObject] {
|
|
|
+ if let tempBasalTime = formatter.date(from: (loopStatus["timestamp"] as! String))?.timeIntervalSince1970 {
|
|
|
+ var lastBGTime = lastLoopTime
|
|
|
+ if bgData.count > 0 {
|
|
|
+ lastBGTime = bgData[bgData.count - 1].date
|
|
|
+ }
|
|
|
+ if tempBasalTime > lastBGTime && !wasEnacted {
|
|
|
+ LoopStatusLabel.text = "⏀"
|
|
|
+ latestLoopStatusString = "⏀"
|
|
|
+ } else {
|
|
|
+ LoopStatusLabel.text = "↻"
|
|
|
+ latestLoopStatusString = "↻"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LoopStatusLabel.text = "↻"
|
|
|
+ latestLoopStatusString = "↻"
|
|
|
+ }
|
|
|
}
|
|
|
+ evaluateNotLooping(lastLoopTime: lastLoopTime)
|
|
|
}
|
|
|
}
|
|
|
}
|