-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
54 lines (52 loc) · 1.5 KB
/
utils.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
49
50
51
52
53
54
const dir2Char = {
NONE: '⇼'
, DoubleUp: '⇈'
, SingleUp: '↑'
, FortyFiveUp: '↗'
, Flat: '→'
, FortyFiveDown: '↘'
, SingleDown: '↓'
, DoubleDown: '⇊'
, 'NOT COMPUTABLE': '-'
, 'RATE OUT OF RANGE': '⇕'
};
const utils = {
displayUnits: function(serverSettings) {
if (serverSettings) {
if (serverSettings.units == 'mmol') {
return 'mmol/L';
}
}
return 'mg/dL';
},
displaySgv: function(serverSettings, sgv) {
if (serverSettings) {
if (serverSettings.units == 'mmol') {
return Math.round(sgv * 10.0 / 18.0) / 10.0;
}
return sgv;
}
return sgv;
},
displayDelta: function(serverSettings, sgv0, sgv1) {
if (serverSettings) {
if (serverSettings.units == 'mmol') {
const sgv0diplay = Math.round(sgv0 * 100.0 / 18.0) / 100.0;
const sgv1diplay = Math.round(sgv1 * 100.0 / 18.0) / 100.0;
return utils.formatDelta(sgv0diplay - sgv1diplay);
}
return utils.formatDelta(sgv0 - sgv1);
}
return utils.formatDelta(sgv0 - sgv1);
},
formatDelta: function(delta) {
if (delta >= 0) {
return '+' + Math.round(delta * 100) / 100;
}
return Math.round(delta * 100) / 100;
},
displayDirection: function(direction) {
return dir2Char[direction] || '-';
}
}
module.exports = utils;