|
@@ -490,7 +490,7 @@ extension MainViewController {
|
|
|
predictionData.removeAll()
|
|
predictionData.removeAll()
|
|
|
var predictionTime = lastLoopTime
|
|
var predictionTime = lastLoopTime
|
|
|
let toLoad = Int(UserDefaultsRepository.predictionToLoad.value * 12)
|
|
let toLoad = Int(UserDefaultsRepository.predictionToLoad.value * 12)
|
|
|
- var i = 0
|
|
|
|
|
|
|
+ var i = 1
|
|
|
while i <= toLoad {
|
|
while i <= toLoad {
|
|
|
if i < prediction.count {
|
|
if i < prediction.count {
|
|
|
let prediction = ShareGlucoseData(sgv: prediction[i], date: predictionTime, direction: "flat")
|
|
let prediction = ShareGlucoseData(sgv: prediction[i], date: predictionTime, direction: "flat")
|
|
@@ -1004,7 +1004,7 @@ extension MainViewController {
|
|
|
resumePump.append(entry!)
|
|
resumePump.append(entry!)
|
|
|
case "Pump Site Change":
|
|
case "Pump Site Change":
|
|
|
pumpSiteChange.append(entry!)
|
|
pumpSiteChange.append(entry!)
|
|
|
- case "CGM Sensor Start":
|
|
|
|
|
|
|
+ case "Sensor Start":
|
|
|
cgmSensorStart.append(entry!)
|
|
cgmSensorStart.append(entry!)
|
|
|
default:
|
|
default:
|
|
|
print("No Match: \(String(describing: entry))")
|
|
print("No Match: \(String(describing: entry))")
|
|
@@ -1017,6 +1017,10 @@ extension MainViewController {
|
|
|
if carbs.count > 0 { processNSCarbs(entries: carbs)}
|
|
if carbs.count > 0 { processNSCarbs(entries: carbs)}
|
|
|
if bgCheck.count > 0 { processNSBGCheck(entries: bgCheck)}
|
|
if bgCheck.count > 0 { processNSBGCheck(entries: bgCheck)}
|
|
|
if temporaryOverride.count > 0 { processNSOverrides(entries: temporaryOverride)}
|
|
if temporaryOverride.count > 0 { processNSOverrides(entries: temporaryOverride)}
|
|
|
|
|
+ if suspendPump.count > 0 { processSuspendPump(entries: suspendPump)}
|
|
|
|
|
+ if resumePump.count > 0 { processResumePump(entries: resumePump)}
|
|
|
|
|
+ if cgmSensorStart.count > 0 { processSensorStart(entries: cgmSensorStart)}
|
|
|
|
|
+ if note.count > 0 { processNotes(entries: note)}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// NS Temp Basal Response Processor
|
|
// NS Temp Basal Response Processor
|
|
@@ -1298,6 +1302,176 @@ extension MainViewController {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // NS Suspend Pump Response Processor
|
|
|
|
|
+ func processSuspendPump(entries: [[String:AnyObject]]) {
|
|
|
|
|
+ if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Process: Suspend Pump") }
|
|
|
|
|
+ // because it's a small array, we're going to destroy and reload every time.
|
|
|
|
|
+ suspendGraphData.removeAll()
|
|
|
|
|
+ var lastFoundIndex = 0
|
|
|
|
|
+ for i in 0..<entries.count {
|
|
|
|
|
+ let currentEntry = entries[entries.count - 1 - i] as [String : AnyObject]?
|
|
|
|
|
+ var date: String
|
|
|
|
|
+ if currentEntry?["timestamp"] != nil {
|
|
|
|
|
+ date = currentEntry?["timestamp"] as! String
|
|
|
|
|
+ } else if currentEntry?["created_at"] != nil {
|
|
|
|
|
+ date = currentEntry?["created_at"] as! String
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // Fix for FreeAPS milliseconds in timestamp
|
|
|
|
|
+ var strippedZone = String(date.dropLast())
|
|
|
|
|
+ strippedZone = strippedZone.components(separatedBy: ".")[0]
|
|
|
|
|
+
|
|
|
|
|
+ let dateFormatter = DateFormatter()
|
|
|
|
|
+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
|
|
|
|
+ dateFormatter.locale = Locale(identifier: "en_US")
|
|
|
|
|
+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
|
|
|
|
|
+ let dateString = dateFormatter.date(from: strippedZone)
|
|
|
|
|
+ let dateTimeStamp = dateString!.timeIntervalSince1970
|
|
|
|
|
+
|
|
|
|
|
+ let sgv = findNearestBGbyTime(needle: dateTimeStamp, haystack: bgData, startingIndex: lastFoundIndex)
|
|
|
|
|
+ lastFoundIndex = sgv.foundIndex
|
|
|
|
|
+
|
|
|
|
|
+ if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (60 * 60)) {
|
|
|
|
|
+ // Make the dot
|
|
|
|
|
+ let dot = DataStructs.timestampOnlyStruct(date: Double(dateTimeStamp), sgv: Int(sgv.sgv))
|
|
|
|
|
+ suspendGraphData.append(dot)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ updateSuspendGraph()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // NS Resume Pump Response Processor
|
|
|
|
|
+ func processResumePump(entries: [[String:AnyObject]]) {
|
|
|
|
|
+ if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Process: Resume Pump") }
|
|
|
|
|
+ // because it's a small array, we're going to destroy and reload every time.
|
|
|
|
|
+ resumeGraphData.removeAll()
|
|
|
|
|
+ var lastFoundIndex = 0
|
|
|
|
|
+ for i in 0..<entries.count {
|
|
|
|
|
+ let currentEntry = entries[entries.count - 1 - i] as [String : AnyObject]?
|
|
|
|
|
+ var date: String
|
|
|
|
|
+ if currentEntry?["timestamp"] != nil {
|
|
|
|
|
+ date = currentEntry?["timestamp"] as! String
|
|
|
|
|
+ } else if currentEntry?["created_at"] != nil {
|
|
|
|
|
+ date = currentEntry?["created_at"] as! String
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // Fix for FreeAPS milliseconds in timestamp
|
|
|
|
|
+ var strippedZone = String(date.dropLast())
|
|
|
|
|
+ strippedZone = strippedZone.components(separatedBy: ".")[0]
|
|
|
|
|
+
|
|
|
|
|
+ let dateFormatter = DateFormatter()
|
|
|
|
|
+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
|
|
|
|
+ dateFormatter.locale = Locale(identifier: "en_US")
|
|
|
|
|
+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
|
|
|
|
|
+ let dateString = dateFormatter.date(from: strippedZone)
|
|
|
|
|
+ let dateTimeStamp = dateString!.timeIntervalSince1970
|
|
|
|
|
+
|
|
|
|
|
+ let sgv = findNearestBGbyTime(needle: dateTimeStamp, haystack: bgData, startingIndex: lastFoundIndex)
|
|
|
|
|
+ lastFoundIndex = sgv.foundIndex
|
|
|
|
|
+
|
|
|
|
|
+ if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (60 * 60)) {
|
|
|
|
|
+ // Make the dot
|
|
|
|
|
+ let dot = DataStructs.timestampOnlyStruct(date: Double(dateTimeStamp), sgv: Int(sgv.sgv))
|
|
|
|
|
+ resumeGraphData.append(dot)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ updateResumeGraph()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // NS Sensor Start Response Processor
|
|
|
|
|
+ func processSensorStart(entries: [[String:AnyObject]]) {
|
|
|
|
|
+ if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Process: Sensor Start") }
|
|
|
|
|
+ // because it's a small array, we're going to destroy and reload every time.
|
|
|
|
|
+ sensorStartGraphData.removeAll()
|
|
|
|
|
+ var lastFoundIndex = 0
|
|
|
|
|
+ for i in 0..<entries.count {
|
|
|
|
|
+ let currentEntry = entries[entries.count - 1 - i] as [String : AnyObject]?
|
|
|
|
|
+ var date: String
|
|
|
|
|
+ if currentEntry?["timestamp"] != nil {
|
|
|
|
|
+ date = currentEntry?["timestamp"] as! String
|
|
|
|
|
+ } else if currentEntry?["created_at"] != nil {
|
|
|
|
|
+ date = currentEntry?["created_at"] as! String
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // Fix for FreeAPS milliseconds in timestamp
|
|
|
|
|
+ var strippedZone = String(date.dropLast())
|
|
|
|
|
+ strippedZone = strippedZone.components(separatedBy: ".")[0]
|
|
|
|
|
+
|
|
|
|
|
+ let dateFormatter = DateFormatter()
|
|
|
|
|
+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
|
|
|
|
+ dateFormatter.locale = Locale(identifier: "en_US")
|
|
|
|
|
+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
|
|
|
|
|
+ let dateString = dateFormatter.date(from: strippedZone)
|
|
|
|
|
+ let dateTimeStamp = dateString!.timeIntervalSince1970
|
|
|
|
|
+
|
|
|
|
|
+ let sgv = findNearestBGbyTime(needle: dateTimeStamp, haystack: bgData, startingIndex: lastFoundIndex)
|
|
|
|
|
+ lastFoundIndex = sgv.foundIndex
|
|
|
|
|
+
|
|
|
|
|
+ if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (60 * 60)) {
|
|
|
|
|
+ // Make the dot
|
|
|
|
|
+ let dot = DataStructs.timestampOnlyStruct(date: Double(dateTimeStamp), sgv: Int(sgv.sgv))
|
|
|
|
|
+ sensorStartGraphData.append(dot)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ updateSensorStart()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // NS Note Response Processor
|
|
|
|
|
+ func processNotes(entries: [[String:AnyObject]]) {
|
|
|
|
|
+ if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Process: Notes") }
|
|
|
|
|
+ // because it's a small array, we're going to destroy and reload every time.
|
|
|
|
|
+ noteGraphData.removeAll()
|
|
|
|
|
+ var lastFoundIndex = 0
|
|
|
|
|
+ for i in 0..<entries.count {
|
|
|
|
|
+ let currentEntry = entries[entries.count - 1 - i] as [String : AnyObject]?
|
|
|
|
|
+ var date: String
|
|
|
|
|
+ if currentEntry?["timestamp"] != nil {
|
|
|
|
|
+ date = currentEntry?["timestamp"] as! String
|
|
|
|
|
+ } else if currentEntry?["created_at"] != nil {
|
|
|
|
|
+ date = currentEntry?["created_at"] as! String
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // Fix for FreeAPS milliseconds in timestamp
|
|
|
|
|
+ var strippedZone = String(date.dropLast())
|
|
|
|
|
+ strippedZone = strippedZone.components(separatedBy: ".")[0]
|
|
|
|
|
+
|
|
|
|
|
+ let dateFormatter = DateFormatter()
|
|
|
|
|
+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
|
|
|
|
+ dateFormatter.locale = Locale(identifier: "en_US")
|
|
|
|
|
+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
|
|
|
|
|
+ let dateString = dateFormatter.date(from: strippedZone)
|
|
|
|
|
+ let dateTimeStamp = dateString!.timeIntervalSince1970
|
|
|
|
|
+
|
|
|
|
|
+ let sgv = findNearestBGbyTime(needle: dateTimeStamp, haystack: bgData, startingIndex: lastFoundIndex)
|
|
|
|
|
+ lastFoundIndex = sgv.foundIndex
|
|
|
|
|
+
|
|
|
|
|
+ guard let thisNote = currentEntry?["notes"] as? String else { continue }
|
|
|
|
|
+
|
|
|
|
|
+ if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (60 * 60)) {
|
|
|
|
|
+ // Make the dot
|
|
|
|
|
+ let dot = DataStructs.noteStruct(date: Double(dateTimeStamp), sgv: Int(sgv.sgv), note: thisNote)
|
|
|
|
|
+ noteGraphData.append(dot)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ updateNotes()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// NS BG Check Response Processor
|
|
// NS BG Check Response Processor
|
|
|
func processNSBGCheck(entries: [[String:AnyObject]]) {
|
|
func processNSBGCheck(entries: [[String:AnyObject]]) {
|
|
|
if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Process: BG Check") }
|
|
if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Process: BG Check") }
|