|
|
@@ -12,7 +12,7 @@ import UIKit
|
|
|
extension MainViewController {
|
|
|
func DeviceStatusOpenAPS(formatter: ISO8601DateFormatter, lastDeviceStatus: [String: AnyObject]?, lastLoopRecord: [String: AnyObject]) {
|
|
|
|
|
|
- if let lastLoopTime = formatter.date(from: (lastDeviceStatus?["created_at"] as! String))?.timeIntervalSince1970 {
|
|
|
+ if let lastLoopTime = formatter.date(from: (lastDeviceStatus?["created_at"] as! String))?.timeIntervalSince1970 {
|
|
|
UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
|
|
|
if lastLoopRecord["failureReason"] != nil {
|
|
|
LoopStatusLabel.text = "X"
|
|
|
@@ -20,17 +20,17 @@ extension MainViewController {
|
|
|
if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Loop Failure: X") }
|
|
|
} else {
|
|
|
var wasEnacted = false
|
|
|
- if let enacted = lastLoopRecord["enacted"] as? [String:AnyObject] {
|
|
|
+ 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))
|
|
|
+ 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))
|
|
|
}
|
|
|
- if let cobdata = lastLoopRecord["enacted"] as? [String:AnyObject] {
|
|
|
- tableData[1].value = String(format:"%.0f", cobdata["COB"] as! Double)
|
|
|
- latestCOB = String(format:"%.0f", cobdata["COB"] as! Double)
|
|
|
+ if let cobdata = lastLoopRecord["enacted"] as? [String: AnyObject] {
|
|
|
+ tableData[1].value = String(format: "%.0f", cobdata["COB"] as! Double)
|
|
|
+ latestCOB = String(format: "%.0f", cobdata["COB"] as! Double)
|
|
|
}
|
|
|
if let recbolusdata = lastLoopRecord["enacted"] as? [String: AnyObject],
|
|
|
let insulinReq = recbolusdata["insulinReq"] as? Double {
|
|
|
@@ -41,38 +41,22 @@ extension MainViewController {
|
|
|
UserDefaultsRepository.deviceRecBolus.value = 0
|
|
|
}
|
|
|
|
|
|
- if let autosensdata = lastLoopRecord["enacted"] as? [String:AnyObject] {
|
|
|
+ if let autosensdata = lastLoopRecord["enacted"] as? [String: AnyObject] {
|
|
|
let sens = autosensdata["sensitivityRatio"] as! Double * 100.0
|
|
|
- tableData[11].value = String(format:"%.0f", sens) + "%"
|
|
|
+ tableData[11].value = String(format: "%.0f", sens) + "%"
|
|
|
}
|
|
|
|
|
|
- if let eventualdata = lastLoopRecord["enacted"] as? [String:AnyObject] {
|
|
|
+ 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
|
|
|
- if let enactdata = lastLoopRecord["enacted"] as? [String:AnyObject],
|
|
|
+ if let enactdata = lastLoopRecord["enacted"] as? [String: AnyObject],
|
|
|
let predbgdata = enactdata["predBGs"] as? [String: AnyObject] {
|
|
|
let predictionTypes: [(type: String, colorName: String, dataIndex: Int)] = [
|
|
|
("ZT", "ZT", 12),
|
|
|
@@ -81,6 +65,9 @@ extension MainViewController {
|
|
|
("UAM", "UAM", 15)
|
|
|
]
|
|
|
|
|
|
+ var minPredBG = Double.infinity
|
|
|
+ var maxPredBG = -Double.infinity
|
|
|
+
|
|
|
for (type, colorName, dataIndex) in predictionTypes {
|
|
|
var predictionData = [ShareGlucoseData]()
|
|
|
if let graphdata = predbgdata[type] as? [Double] {
|
|
|
@@ -89,7 +76,11 @@ extension MainViewController {
|
|
|
|
|
|
for i in 0...toLoad {
|
|
|
if i < graphdata.count {
|
|
|
- let prediction = ShareGlucoseData(sgv: Int(round(graphdata[i])), date: predictionTime, direction: "flat")
|
|
|
+ let predictionValue = graphdata[i]
|
|
|
+ minPredBG = min(minPredBG, predictionValue)
|
|
|
+ maxPredBG = max(maxPredBG, predictionValue)
|
|
|
+
|
|
|
+ let prediction = ShareGlucoseData(sgv: Int(round(predictionValue)), date: predictionTime, direction: "flat")
|
|
|
predictionData.append(prediction)
|
|
|
predictionTime += 300
|
|
|
}
|
|
|
@@ -104,9 +95,15 @@ extension MainViewController {
|
|
|
color: color
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
+ if minPredBG != Double.infinity && maxPredBG != -Double.infinity {
|
|
|
+ tableData[9].value = "\(bgUnits.toDisplayUnits(String(minPredBG)))/\(bgUnits.toDisplayUnits(String(maxPredBG)))"
|
|
|
+ } else {
|
|
|
+ tableData[9].value = "N/A"
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if let loopStatus = lastLoopRecord["recommendedTempBasal"] as? [String:AnyObject] {
|
|
|
+ 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 {
|