From 7f75ac609c259368a56e59d5252d9817edbe4f49 Mon Sep 17 00:00:00 2001 From: Matthias Granberry Date: Wed, 25 Feb 2015 12:53:30 -0600 Subject: [PATCH 1/2] allow arbitrary DIAs in profile --- static/iob-cob.html | 9 +++------ static/js/client.js | 33 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/static/iob-cob.html b/static/iob-cob.html index 535c1b263..5b35441a3 100644 --- a/static/iob-cob.html +++ b/static/iob-cob.html @@ -269,11 +269,8 @@ $scope.iob = function(treatment, time) { var dia=$scope.profile[0].dia; - if (dia == 3) { - var peak=75; - } else { - console.warn('DIA of ' + dia + 'not supported'); - } + var scalefactor = 3.0/dia; + var peak=75; var sens=$scope.profile[0].sens; if (typeof time === 'undefined') { var time = new Date(); @@ -281,7 +278,7 @@ if (treatment.insulin) { var bolusTime=new Date(treatment.created_at); - var minAgo=(time-bolusTime)/1000/60; + var minAgo=scalefactor*(time-bolusTime)/1000/60; if (minAgo < 0) { var iobContrib=0; diff --git a/static/js/client.js b/static/js/client.js index 567fbb417..44dae5631 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -1279,7 +1279,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; var BG_MIN = scaleBg(36); var BG_MAX = scaleBg(400); if (typeof predict_hr === 'undefined') { - var predict_hr = 4; + predict_hr = profile.dia; } var dt = time.getTime(); var predictedColor = 'purple'; @@ -1547,38 +1547,37 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; function iobCalc(treatment, time) { var dia=profile.dia; - if (dia == 3) { - var peak=75; - } else { - console.warn('DIA of ' + dia + 'not supported'); - } + var scaleFactor = 3.0/dia; + var peak = 75; var sens=profile.sens; - if (typeof time === 'undefined') { - var time = new Date(); + 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=(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, From e25c6abf36e83c1e40f19629170503a05ded392c Mon Sep 17 00:00:00 2001 From: Matthias Granberry Date: Wed, 25 Feb 2015 13:21:19 -0600 Subject: [PATCH 2/2] align IOB calculations --- static/iob-cob.html | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/static/iob-cob.html b/static/iob-cob.html index 5b35441a3..0ad713221 100644 --- a/static/iob-cob.html +++ b/static/iob-cob.html @@ -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,