forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start getting browserify-express hooked up to expose a shared IOB module
- Loading branch information
1 parent
d616b6c
commit 7f550b8
Showing
6 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
bower_components/ | ||
node_modules/ | ||
|
||
|
||
bundle/bundle.out.js | ||
|
||
.idea/ | ||
*.iml | ||
my.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(function () { | ||
|
||
window.Nightscout = window.Nightscout || {}; | ||
|
||
window.Nightscout = { | ||
iob: require('../lib/iob')() | ||
}; | ||
|
||
console.info("Nightscout bundle ready", window.Nightscout); | ||
|
||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict'; | ||
|
||
function iobTotal(treatments, profile, time) { | ||
var iob= 0; | ||
var activity = 0; | ||
if (!treatments) return {}; | ||
if (typeof time === 'undefined') { | ||
time = new Date(); | ||
} | ||
|
||
treatments.forEach(function(treatment) { | ||
if(treatment.created_at < time) { | ||
var tIOB = iobCalc(treatment, profile, time); | ||
if (tIOB && tIOB.iobContrib) iob += tIOB.iobContrib; | ||
if (tIOB && tIOB.activityContrib) activity += tIOB.activityContrib; | ||
} | ||
}); | ||
return { | ||
iob: iob, | ||
activity: activity | ||
}; | ||
} | ||
|
||
function iobCalc(treatment, profile, time) { | ||
|
||
var dia=profile.dia; | ||
var scaleFactor = 3.0/dia; | ||
var peak = 75; | ||
var sens=profile.sens; | ||
var iobContrib, activityContrib; | ||
var t = time; | ||
if (typeof t === 'undefined') { | ||
t = new Date(); | ||
} | ||
|
||
|
||
if (treatment.insulin) { | ||
var bolusTime=new Date(treatment.created_at); | ||
var minAgo=scaleFactor*(t-bolusTime)/1000/60; | ||
|
||
if (minAgo < 0) { | ||
iobContrib=0; | ||
activityContrib=0; | ||
} | ||
if (minAgo < peak) { | ||
var x = minAgo/5+1; | ||
iobContrib=treatment.insulin*(1-0.001852*x*x+0.001852*x); | ||
activityContrib=sens*treatment.insulin*(2/dia/60/peak)*minAgo; | ||
|
||
} | ||
else if (minAgo < 180) { | ||
var x = (minAgo-75)/5; | ||
iobContrib=treatment.insulin*(0.001323*x*x - .054233*x + .55556); | ||
activityContrib=sens*treatment.insulin*(2/dia/60-(minAgo-peak)*2/dia/60/(60*dia-peak)); | ||
} | ||
else { | ||
iobContrib=0; | ||
activityContrib=0; | ||
} | ||
return { | ||
iobContrib: iobContrib, | ||
activityContrib: activityContrib | ||
}; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
function IOB(opts) { | ||
|
||
var IOB = { | ||
total: iobTotal | ||
}; | ||
|
||
return IOB; | ||
|
||
} | ||
|
||
if (window) window.IOB = IOB; | ||
|
||
module.exports = IOB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters