forked from openaps/oref0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemps.js
48 lines (39 loc) · 995 Bytes
/
temps.js
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
44
45
46
47
48
function filter (treatments) {
var results = [ ];
var state = { };
function temp (ev) {
if ('duration (min)' in ev) {
state.duration = ev['duration (min)'].toString( );
state.raw_duration = ev;
}
if ('rate' in ev) {
state[ev.temp] = ev.rate.toString( );
state.rate = ev['rate'];
state.raw_rate = ev;
}
if ('timestamp' in state && ev.timestamp !== state.timestamp) {
state.invalid = true;
} else {
state.timestamp = ev.timestamp;
}
if ('duration' in state && ('percent' in state || 'absolute' in state)) {
state.eventType = 'Temp Basal';
results.push(state);
state = { };
}
}
function step (current) {
switch (current._type) {
case 'TempBasalDuration':
case 'TempBasal':
temp(current);
break;
default:
results.push(current);
break;
}
}
treatments.forEach(step);
return results;
}
exports = module.exports = filter;