|
@@ -27,20 +27,50 @@ extension MainViewController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- func findNearestBolusbyTime(needle: TimeInterval, haystack: [bolusGraphStruct], startingIndex: Int) -> (offset: Bool, foundIndex: Int) {
|
|
|
|
|
|
|
+ func findNearestBolusbyTime(timeWithin: Int, needle: TimeInterval, haystack: [bolusGraphStruct], startingIndex: Int) -> (offset: Bool, foundIndex: Int) {
|
|
|
|
|
|
|
|
// If we can't find a match or things fail, put it at 100 BG
|
|
// If we can't find a match or things fail, put it at 100 BG
|
|
|
for i in startingIndex..<haystack.count {
|
|
for i in startingIndex..<haystack.count {
|
|
|
// i has reached the end without a result. return 0
|
|
// i has reached the end without a result. return 0
|
|
|
let timeDiff = needle - haystack[i].date
|
|
let timeDiff = needle - haystack[i].date
|
|
|
- if timeDiff <= 300 && timeDiff >= -300 { return (true, i)}
|
|
|
|
|
|
|
+ if timeDiff <= Double(timeWithin) && timeDiff >= Double(-timeWithin) { return (true, i)}
|
|
|
|
|
|
|
|
if i == haystack.count - 1 { return (false, 0) }
|
|
if i == haystack.count - 1 { return (false, 0) }
|
|
|
- if timeDiff < -300 { return (false, 0)}
|
|
|
|
|
|
|
+ if timeDiff < Double(-timeWithin) { return (false, 0)}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return (false, 0 )
|
|
return (false, 0 )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ func findNextCarbTime(timeWithin: Int, needle: TimeInterval, haystack: [carbGraphStruct], startingIndex: Int) -> Bool {
|
|
|
|
|
+
|
|
|
|
|
+ if startingIndex > haystack.count - 2 { return false }
|
|
|
|
|
+ if haystack[startingIndex + 1].date - needle < Double(timeWithin) {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ func findNextBolusTime(timeWithin: Int, needle: TimeInterval, haystack: [bolusGraphStruct], startingIndex: Int) -> Bool {
|
|
|
|
|
+
|
|
|
|
|
+ var last = false
|
|
|
|
|
+ var next = true
|
|
|
|
|
+ if startingIndex > haystack.count - 2 { return false }
|
|
|
|
|
+ if startingIndex == 0 { return false }
|
|
|
|
|
+
|
|
|
|
|
+ // Nothing to right that requires shift
|
|
|
|
|
+ if haystack[startingIndex + 1].date - needle > Double(timeWithin) {
|
|
|
|
|
+ return false
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Nothing to left preventing shift
|
|
|
|
|
+ if needle - haystack[startingIndex - 1].date > Double(timeWithin) {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|