|
@@ -618,6 +618,7 @@ extension MainViewController {
|
|
|
}
|
|
}
|
|
|
if jsonDeviceStatus[keyPath: "message"] != nil { return }
|
|
if jsonDeviceStatus[keyPath: "message"] != nil { return }
|
|
|
let basal = try jsonDeviceStatus[keyPath: "store.Default.basal"] as! NSArray
|
|
let basal = try jsonDeviceStatus[keyPath: "store.Default.basal"] as! NSArray
|
|
|
|
|
+ basalProfile.removeAll()
|
|
|
for i in 0..<basal.count {
|
|
for i in 0..<basal.count {
|
|
|
let dict = basal[i] as! Dictionary<String, Any>
|
|
let dict = basal[i] as! Dictionary<String, Any>
|
|
|
do {
|
|
do {
|
|
@@ -638,7 +639,6 @@ extension MainViewController {
|
|
|
// Make temporary array with all values of yesterday and today
|
|
// Make temporary array with all values of yesterday and today
|
|
|
let yesterdayStart = dateTimeUtils.getTimeIntervalMidnightYesterday()
|
|
let yesterdayStart = dateTimeUtils.getTimeIntervalMidnightYesterday()
|
|
|
let todayStart = dateTimeUtils.getTimeIntervalMidnightToday()
|
|
let todayStart = dateTimeUtils.getTimeIntervalMidnightToday()
|
|
|
- basalScheduleData.removeAll()
|
|
|
|
|
|
|
|
|
|
var basal2Day: [DataStructs.basal2DayProfile] = []
|
|
var basal2Day: [DataStructs.basal2DayProfile] = []
|
|
|
// Run twice to add in order yesterday then today.
|
|
// Run twice to add in order yesterday then today.
|
|
@@ -671,13 +671,30 @@ extension MainViewController {
|
|
|
|
|
|
|
|
let now = dateTimeUtils.nowMinus24HoursTimeInterval()
|
|
let now = dateTimeUtils.nowMinus24HoursTimeInterval()
|
|
|
var firstPass = true
|
|
var firstPass = true
|
|
|
|
|
+ basalScheduleData.removeAll()
|
|
|
for i in 0..<basal2Day.count {
|
|
for i in 0..<basal2Day.count {
|
|
|
var timeYesterday = dateTimeUtils.getTimeInterval24HoursAgo()
|
|
var timeYesterday = dateTimeUtils.getTimeInterval24HoursAgo()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // This processed everything after the first one.
|
|
|
|
|
+ if firstPass == false
|
|
|
|
|
+ && basal2Day[i].startDate <= dateTimeUtils.getNowTimeIntervalUTC() {
|
|
|
|
|
+ let startDot = basalGraphStruct(basalRate: basal2Day[i].basalRate, date: basal2Day[i].startDate)
|
|
|
|
|
+ basalScheduleData.append(startDot)
|
|
|
|
|
+ var endDate = basal2Day[i].endDate
|
|
|
|
|
+
|
|
|
|
|
+ // if it's the last one in the profile or date is greater than now, set it to the last BG dot
|
|
|
|
|
+ if i == basal2Day.count - 1 || endDate > dateTimeUtils.getNowTimeIntervalUTC() {
|
|
|
|
|
+ endDate = Double(dateTimeUtils.getNowTimeIntervalUTC())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let endDot = basalGraphStruct(basalRate: basal2Day[i].basalRate, date: endDate)
|
|
|
|
|
+ basalScheduleData.append(endDot)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// we need to manually set the first one
|
|
// we need to manually set the first one
|
|
|
// Check that this is the first one and there are no existing entries
|
|
// Check that this is the first one and there are no existing entries
|
|
|
- if basalScheduleData.count == 0 {
|
|
|
|
|
|
|
+ if firstPass == true {
|
|
|
// check that the timestamp is > the current entry and < the next entry
|
|
// check that the timestamp is > the current entry and < the next entry
|
|
|
if timeYesterday >= basal2Day[i].startDate && timeYesterday < basal2Day[i].endDate {
|
|
if timeYesterday >= basal2Day[i].startDate && timeYesterday < basal2Day[i].endDate {
|
|
|
// Set the start time to match the BG start
|
|
// Set the start time to match the BG start
|
|
@@ -688,26 +705,12 @@ extension MainViewController {
|
|
|
var endDate = basal2Day[i].endDate
|
|
var endDate = basal2Day[i].endDate
|
|
|
let endDot = basalGraphStruct(basalRate: basal2Day[i].basalRate, date: endDate)
|
|
let endDot = basalGraphStruct(basalRate: basal2Day[i].basalRate, date: endDate)
|
|
|
basalScheduleData.append(endDot)
|
|
basalScheduleData.append(endDot)
|
|
|
|
|
+ firstPass = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // process the rest after the first line segment of 2 dots
|
|
|
|
|
- // check if it's > 24 hours ago an <= 30 minutes from now.
|
|
|
|
|
- if !firstPass
|
|
|
|
|
- && basal2Day[i].startDate < dateTimeUtils.getNowTimeIntervalUTC() + ( 60 * 30 ) {
|
|
|
|
|
- let startDot = basalGraphStruct(basalRate: basal2Day[i].basalRate, date: basal2Day[i].startDate)
|
|
|
|
|
- basalScheduleData.append(startDot)
|
|
|
|
|
- var endDate = basal2Day[i].endDate
|
|
|
|
|
-
|
|
|
|
|
- // if it's the last one in the profile or date is greater than now, set it to the last BG dot
|
|
|
|
|
- if i == basal2Day.count - 1 || endDate > dateTimeUtils.getNowTimeIntervalUTC() {
|
|
|
|
|
- endDate = Double(dateTimeUtils.getNowTimeIntervalUTC())
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- let endDot = basalGraphStruct(basalRate: basal2Day[i].basalRate, date: endDate)
|
|
|
|
|
- basalScheduleData.append(endDot)
|
|
|
|
|
- }
|
|
|
|
|
- firstPass = false
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if UserDefaultsRepository.graphBasal.value {
|
|
if UserDefaultsRepository.graphBasal.value {
|