forked from ecc1/medtronic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpumphistory.go
43 lines (41 loc) · 1.12 KB
/
pumphistory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package medtronic
import (
"log"
"time"
)
// HistoryRecords returns the history records since the specified time.
// Note that the results may include records with a zero timestamp or
// an earlier timestamp than the cutoff (in the case of DailyTotal records).
func (pump *Pump) HistoryRecords(since time.Time) []HistoryRecord {
newer := pump.Family() >= 23
numPages := pump.HistoryPageCount()
if pump.Error() != nil {
return nil
}
results := []HistoryRecord{}
loop:
for page := 0; page < numPages && pump.Error() == nil; page++ {
data := pump.HistoryPage(page)
records, err := DecodeHistoryRecords(data, newer)
if err != nil {
pump.SetError(err)
}
for _, r := range records {
// Don't use DailyTotal timestamps to decide when to stop,
// because they appear out of order (at the end of the day).
switch r.Type() {
case DailyTotal:
case DailyTotal522:
case DailyTotal523:
default:
t := r.Time
if !t.IsZero() && t.Before(since) {
log.Printf("stopping pump history scan at %s", t.Format(UserTimeLayout))
break loop
}
}
results = append(results, r)
}
}
return results
}