Skip to content

Commit

Permalink
align IOB calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
mgranberry committed Feb 25, 2015
1 parent 7f75ac6 commit e25c6ab
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions static/iob-cob.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,32 +272,34 @@
var scalefactor = 3.0/dia;
var peak=75;
var sens=$scope.profile[0].sens;
if (typeof time === 'undefined') {
var time = new Date();
var activityContrib, iobContrib;
var t = time;
if (typeof t === 'undefined') {
t = new Date();
}

if (treatment.insulin) {
var bolusTime=new Date(treatment.created_at);
var minAgo=scalefactor*(time-bolusTime)/1000/60;
var minAgo=scalefactor*(t-bolusTime)/1000/60;

if (minAgo < 0) {
var iobContrib=0;
var activityContrib=0;
iobContrib = 0;
activityContrib = 0;
}
if (minAgo < peak) {
var x = minAgo/5+1;
var iobContrib=treatment.insulin*(1-0.001852*x*x+0.001852*x);
var activityContrib=sens*treatment.insulin*(2/dia/60/peak)*minAgo;
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;
var iobContrib=treatment.insulin*(0.001323*x*x - .054233*x + .55556);
var activityContrib=sens*treatment.insulin*(2/dia/60-(minAgo-peak)*2/dia/60/(60*dia-peak));
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 {
var iobContrib=0;
var activityContrib=0;
iobContrib=0;
activityContrib=0;
}
return {
iobContrib: iobContrib,
Expand Down

0 comments on commit e25c6ab

Please sign in to comment.