forked from ivalkou/freeaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.js
63 lines (57 loc) · 1.97 KB
/
middleware.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
55
56
57
58
59
60
61
62
63
//enable SMB at night with High Targets and disable after 6am
var nightlySMBHT = true;
//increase insulin output with raising BG
var accelerateUAM = false;
var limit1 = 160;
var factor1 = 1.3;
var limit2 = 190;
var factor2 = 1.5;
var limit3 = 220;
var factor3 = 1.8;
var IOBlimit = 5.5;
//set a percentage profile and disable autosense
var override = false;
var overridevalue = 0.9;
function middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoir, clock) {
var hours = clock.getHours();
var lastGlucose = glucose[0].sgv;
var lastIOB = iob[0].iob;
var reason1 = "No UAM acceleration";
var reason2 = "No override";
var reasonIOB = ".";
var reasonSMB = "nightly SMB-Logic disabled"
var newRatio = autosens.ratio;
if (nightlySMBHT=true) {
if (hours >= 0 && hours <= 6) {
profile.allowSMB_with_high_temptarget = true;
reasonSMB = "SMB with HT enabled due to nighttime"
}else{
profile.allowSMB_with_high_temptarget = false
reasonSMB = "SMB with HT disabled due to daytime"
}
}
if (accelerateUAM == true) {
if (lastGlucose > limit3) {
newRatio = autosens.ratio * factor3;
}else{
if (lastGlucose > limit2) {
newRatio = autosens.ratio * factor2;
}else{
if (lastGlucose > limit1) {
newRatio = autosens.ratio * factor1;
}
}
}
autosens.ratio = newRatio;
if (lastIOB > IOBlimit) {
profile.enableSMB_always = false;
reasonIOB = ", SMB disabled with IOB=" + lastIOB;
}
reason1 = "Ratio set to " + autosens.ratio + " as last glucose value is " + lastGlucose + reasonIOB
}
if (override==true) {
autosens.ratio = overridevalue;
reason2 = "Profile override set to " + autosens.ratio*100+"%";
}
return `${reason1}, ${reason2}, ${reasonSMB}`
}