Skip to content

Commit

Permalink
Remove timestamp delta allowance and use reference timestamps in check
Browse files Browse the repository at this point in the history
Glucose events can be out of order (and are frequently). Checking for
only reference timestamps should catch all relevant events.
  • Loading branch information
tmecklem committed Oct 20, 2016
1 parent 6ce4626 commit f266ebb
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions RileyLinkKit/PumpOpsSynchronous.swift
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,6 @@ class PumpOpsSynchronous {

var events = [TimestampedGlucoseEvent]()

// Going to scan backwards in time through events, so event time should be monotonically decreasing.
let eventTimestampDeltaAllowance = TimeInterval(hours: 9)

let currentGlucosePage = try readCurrentGlucosePage()
let startPage = Int(currentGlucosePage.pageNum)
let endPage = max(startPage - 1, 0)
Expand Down Expand Up @@ -589,8 +586,8 @@ class PumpOpsSynchronous {
timestamp.timeZone = pump.timeZone

if let date = timestamp.date {
if date.timeIntervalSince(startDate) < -eventTimestampDeltaAllowance {
NSLog("Found event at (%@) to be more than %@s before startDate(%@)", date as NSDate, String(describing: eventTimestampDeltaAllowance), startDate as NSDate);
if date < startDate && event is ReferenceTimestampedGlucoseEvent {
NSLog("Found reference event at (%@) to be before startDate(%@)", date as NSDate, startDate as NSDate);
break pages
} else {
events.insert(TimestampedGlucoseEvent(glucoseEvent: event, date: date), at: 0)
Expand Down

0 comments on commit f266ebb

Please sign in to comment.