Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev branch - prepping next release #22

Merged
merged 40 commits into from Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5368206
Format mm glucose for oref0 tools
bewest Nov 13, 2015
5046478
delete old ununused openaps-js scripts
scottleibrand Nov 14, 2015
a514f05
first attempt at a read-only ns-uploader (oref1) setup script
scottleibrand Nov 14, 2015
ae1aafd
prompt for NIGHTSCOUT_HOST and API_SECRET; do preflight
scottleibrand Nov 14, 2015
782aeda
put ENV vars above commands that use them
scottleibrand Nov 14, 2015
73147ad
show latest-ns-treatment-time in openaps upload output
scottleibrand Nov 14, 2015
769aa3e
helps to actually query the pump
scottleibrand Nov 14, 2015
c40409c
don't log comm errors
scottleibrand Nov 14, 2015
7f5421d
make API_SECRET take $3
bewest Nov 15, 2015
e4c84d3
Merge branch 'dev' of github.com:openaps/oref0 into dev
bewest Nov 15, 2015
2b4d63a
rename to ns-uploader-setup.sh
scottleibrand Nov 16, 2015
0c4726d
fix description
scottleibrand Nov 16, 2015
a2bbba5
duration 0 == no temp, not rate 0. thx @LorelaiL
scottleibrand Nov 16, 2015
afe45c3
spacing
scottleibrand Nov 16, 2015
ee49299
spacing
scottleibrand Nov 16, 2015
ee8ce6e
fix 0>0
scottleibrand Nov 16, 2015
306ee74
show whether Delta or Avg. Delta was most responsible for not temping
scottleibrand Nov 16, 2015
14cff9c
fix test to accommodate Avg. Delta
scottleibrand Nov 16, 2015
0d51dfa
fix bug with diaratio that was having the backwards effect; some clea…
jasoncalabrese Nov 18, 2015
69862af
Merge branch 'dev' of https://github.com/openaps/oref0 into wip/iob-test
jasoncalabrese Nov 18, 2015
d416bc2
fix bolus iob since it was compensating for the dia scaling bug
jasoncalabrese Nov 18, 2015
08cdc23
Merge pull request #26 from jasoncalabrese/wip/iob-test
scottleibrand Nov 18, 2015
6544b3b
a couple basic IOB test to make sure 3hr and 4hr dia's work
jasoncalabrese Nov 18, 2015
1abc2c7
Merge pull request #27 from jasoncalabrese/wip/iob-test
scottleibrand Nov 18, 2015
95049d9
a little test clean up
jasoncalabrese Nov 18, 2015
b12c376
Merge pull request #28 from jasoncalabrese/wip/iob-test
scottleibrand Nov 18, 2015
b2bcf50
don't add uploader crontab line if it already exists
scottleibrand Nov 19, 2015
f71457a
pull logrotate scripts from github in case oref0 isn't in ~/src/oref0
scottleibrand Nov 19, 2015
d995168
Merge pull request #24 from openaps/wip/oref1-ns-uploader
scottleibrand Nov 19, 2015
e4ac719
#29: better low glucose suspend threshold
scottleibrand Nov 23, 2015
daf56f8
Merge pull request #25 from openaps/reason-fixes
scottleibrand Nov 24, 2015
8f8d67e
should temp to 0 when LOW w/ positive IOB
scottleibrand Nov 24, 2015
d61468a
should temp to 0 when LOW w/ negative IOB
scottleibrand Nov 24, 2015
bc4c66a
1 more test to make sure we temp to 0 when LOW
jasoncalabrese Nov 24, 2015
76acfc6
Merge pull request #31 from jasoncalabrese/wip/low-no-iob
scottleibrand Nov 24, 2015
90048fd
fix -0 typo
jasoncalabrese Nov 24, 2015
fdfa1c8
Merge pull request #32 from jasoncalabrese/wip/low-no-iob
scottleibrand Nov 24, 2015
4560d0b
first meal-assist test case
scottleibrand Nov 25, 2015
7273786
only cancel temp if running (duration > 0)
scottleibrand Nov 25, 2015
67aba64
bolus snooze tests should go with meal assist ones for now
scottleibrand Nov 25, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions bin/mm-format-oref0-glucose.sh
@@ -0,0 +1,18 @@
#!/bin/bash

# Author: Ben West @bewest
# Maintainer: @tghoward

# Written for decocare v0.0.18. Will need updating the the decocare json format changes.
HISTORY=${1-glucosehistory.json}
OUTPUT=${2-/dev/fd/1}
#TZ=${3-$(date +%z)}

cat $HISTORY | \
json -e "this.medtronic = this._type;" | \
json -e "this.dateString = this.date + '$(date +%z)'" | \
json -e "this.date = new Date(this.dateString).getTime();" | \
json -e "this.type = (this.name == 'GlucoseSensorData') ? 'sgv' : 'pumpdata'" | \
json -e "this.device = 'openaps://medtronic/pump/cgm'" \
> $OUTPUT

1 change: 1 addition & 0 deletions bin/ns-dedupe-treatments.sh
Expand Up @@ -76,6 +76,7 @@ done
}

export API_SECRET
test -n "$3" && API_SECRET=$3
case "$1" in
--list)
list $2
Expand Down
134 changes: 134 additions & 0 deletions bin/ns-uploader-setup.sh
@@ -0,0 +1,134 @@
#!/bin/bash

# This script sets up a read-only openaps environment that uploads pump history data to nightscout
# by defining the required devices, reports, and aliases.
#
# Released under MIT license. See the accompanying LICENSE.txt file for
# full terms and conditions
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

die() {
echo "$@"
exit 1
}

self=$(basename $0)
if [[ $# -lt 2 ]]; then
openaps device show pump 2>/dev/null >/dev/null || die "Usage: $self <directory> <pump serial #>"
fi
directory=`mkdir -p $1; cd $1; pwd`
serial=$2

echo -n Setting up oref0 in $directory for pump $serial

if [[ $# -gt 3 ]]; then
diyps_url=$4
echo -n ", DIYPS URL $diyps_url"
fi
echo

read -p "Continue? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then

( ( cd $directory 2>/dev/null && git status ) || ( openaps init $directory ) ) || die "Can't init $directory"
cd $directory || die "Can't cd $directory"

#sudo cp ~/src/oref0/logrotate.openaps /etc/logrotate.d/openaps
sudo bash -c "curl -s https://raw.githubusercontent.com/openaps/oref0/master/logrotate.openaps > /etc/logrotate.d/openaps"
#sudo cp ~/src/oref0/logrotate.rsyslog /etc/logrotate.d/rsyslog
sudo bash -c "curl -s https://raw.githubusercontent.com/openaps/oref0/master/logrotate.rsyslog > /etc/logrotate.d/rsyslog"

test -d /var/log/openaps || sudo mkdir /var/log/openaps && sudo chown $USER /var/log/openaps

openaps vendor add openapscontrib.timezones

# don't re-create devices if they already exist
openaps device show 2>/dev/null > /tmp/openaps-devices

# add devices
grep -q pump.ini .gitignore 2>/dev/null || echo pump.ini >> .gitignore
git add .gitignore
grep pump /tmp/openaps-devices || openaps device add pump medtronic $serial || die "Can't add pump"
grep cgm /tmp/openaps-devices || openaps device add cgm dexcom || die "Can't add CGM"
git add cgm.ini
grep ns-glucose /tmp/openaps-devices || openaps device add ns-glucose process 'bash -c "curl -s $NIGHTSCOUT_HOST/api/v1/entries/sgv.json | json -e \"this.glucose = this.sgv\""' || die "Can't add ns-glucose"
git add ns-glucose.ini
grep oref0 /tmp/openaps-devices || openaps device add oref0 process oref0 || die "Can't add oref0"
git add oref0.ini
grep iob /tmp/openaps-devices || openaps device add iob process --require "pumphistory profile clock" oref0 calculate-iob || die "Can't add iob"
git add iob.ini
grep tz /tmp/openaps-devices || openaps device add tz timezones || die "Can't add tz"
git add tz.ini
#grep latest-treatments /tmp/openaps-devices || openaps device add latest-treatments process nightscout 'latest-openaps-treatment $NIGHTSCOUT_HOST' || die "Can't add latest-treatments"
#git add latest-treatments.ini

# don't re-create reports if they already exist
openaps report show 2>/dev/null > /tmp/openaps-reports

# add reports for frequently-refreshed monitoring data
ls monitor 2>/dev/null >/dev/null || mkdir monitor || die "Can't mkdir monitor"
grep monitor/glucose.json /tmp/openaps-reports || openaps report add monitor/glucose.json JSON cgm iter_glucose 5 || die "Can't add glucose.json"
grep monitor/ns-glucose.json /tmp/openaps-reports || openaps report add monitor/ns-glucose.json text ns-glucose shell || die "Can't add ns-glucose.json"
grep settings/model.json /tmp/openaps-reports || openaps report add settings/model.json JSON pump model || die "Can't add model"
grep monitor/clock.json /tmp/openaps-reports || openaps report add monitor/clock.json JSON pump read_clock || die "Can't add clock.json"
grep monitor/clock-zoned.json /tmp/openaps-reports || openaps report add monitor/clock-zoned.json JSON tz clock monitor/clock.json || die "Can't add clock-zoned.json"
grep monitor/temp_basal.json /tmp/openaps-reports || openaps report add monitor/temp_basal.json JSON pump read_temp_basal || die "Can't add temp_basal.json"
grep monitor/reservoir.json /tmp/openaps-reports || openaps report add monitor/reservoir.json JSON pump reservoir || die "Can't add reservoir.json"
grep monitor/pumphistory.json /tmp/openaps-reports || openaps report add monitor/pumphistory.json JSON pump iter_pump_hours 4 || die "Can't add pumphistory.json"
grep monitor/pumphistory-zoned.json /tmp/openaps-reports || openaps report add monitor/pumphistory-zoned.json JSON tz rezone monitor/pumphistory.json || die "Can't add pumphistory-zoned.json"
grep monitor/iob.json /tmp/openaps-reports || openaps report add monitor/iob.json text iob shell monitor/pumphistory-zoned.json settings/profile.json monitor/clock-zoned.json || die "Can't add iob.json"

# add reports for infrequently-refreshed settings data
ls settings 2>/dev/null >/dev/null || mkdir settings || die "Can't mkdir settings"
grep settings/bg_targets.json /tmp/openaps-reports || openaps report add settings/bg_targets.json JSON pump read_bg_targets || die "Can't add bg_targets.json"
grep settings/insulin_sensitivities.json /tmp/openaps-reports || openaps report add settings/insulin_sensitivities.json JSON pump read_insulin_sensitivities || die "Can't add insulin_sensitivities.json"
grep settings/basal_profile.json /tmp/openaps-reports || openaps report add settings/basal_profile.json JSON pump read_selected_basal_profile || die "Can't add basal_profile.json"
grep settings/settings.json /tmp/openaps-reports || openaps report add settings/settings.json JSON pump read_settings || die "Can't add settings.json"

# add aliases to get data
openaps alias add invoke "report invoke" || die "Can't add invoke"
openaps alias add preflight '! bash -c "rm -f monitor/clock.json && openaps report invoke monitor/clock.json >/dev/null 2>/dev/null && grep -q T monitor/clock.json && echo PREFLIGHT OK || ( mm-stick warmup || sudo oref0-reset-usb; echo PREFLIGHT FAIL; sleep 120; exit 1 )"' || die "Can't add preflight"
openaps alias add monitor-cgm "report invoke monitor/glucose.json" || die "Can't add monitor-cgm"
openaps alias add get-ns-glucose "report invoke monitor/ns-glucose.json" || die "Can't add get-ns-glucose"
openaps alias add monitor-pump "report invoke monitor/clock.json monitor/temp_basal.json monitor/pumphistory.json monitor/pumphistory-zoned.json monitor/clock-zoned.json" || die "Can't add monitor-pump"
openaps alias add get-settings "report invoke settings/model.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json settings/settings.json" || die "Can't add get-settings"
openaps alias add get-bg '! bash -c "openaps monitor-cgm 2>/dev/null || ( openaps get-ns-glucose && grep -q glucose monitor/ns-glucose.json && mv monitor/ns-glucose.json monitor/glucose.json )"' || die "Can't add get-bg"
openaps alias add gather '! bash -c "rm monitor/*; ( openaps get-bg && openaps get-settings >/dev/null && openaps monitor-pump ) 2>/dev/null"' || die "Can't add gather"
openaps alias add wait-for-bg '! bash -c "cp monitor/glucose.json monitor/last-glucose.json; while(diff -q monitor/last-glucose.json monitor/glucose.json); do echo -n .; sleep 10; openaps get-bg >/dev/null; done"'

# upload treatments to nightscout
ls upload 2>/dev/null >/dev/null || mkdir upload || die "Can't mkdir upload"
openaps alias add latest-ns-treatment-time '! bash -c "nightscout latest-openaps-treatment $NIGHTSCOUT_HOST | json created_at"' || die "Can't add latest-ns-treatment-time"
openaps alias add format-latest-nightscout-treatments '! bash -c "nightscout cull-latest-openaps-treatments monitor/pumphistory-zoned.json settings/model.json $(openaps latest-ns-treatment-time) > upload/latest-treatments.json"' || die "Can't add format-latest-nightscout-treatments"
openaps alias add upload-recent-treatments '! bash -c "openaps format-latest-nightscout-treatments && test $(json -f upload/latest-treatments.json -a created_at eventType | wc -l ) -gt 0 && (ns-upload $NIGHTSCOUT_HOST $API_SECRET treatments.json upload/latest-treatments.json ) || echo \"No recent treatments to upload\""' || die "Can't add upload-recent-treatments"
openaps alias add upload '! bash -c "openaps preflight && ( openaps monitor-pump && openaps upload-recent-treatments && openaps get-settings) 2>/dev/null >/dev/null && echo -n \"Uploaded; most recent treatment event @ \" && openaps latest-ns-treatment-time || echo \"Error; could not upload\""' || die "Can't add upload"

read -p "Schedule oref1 (openaps nightscout uploader) in cron? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Nightscout hostname? "
NIGHTSCOUT_HOST=$REPLY
read -p "Hashed API secret? "
API_SECRET=$REPLY
read -p "Upload to $NIGHTSCOUT_HOST using API secret $API_SECRET, correct? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
(crontab -l; echo NIGHTSCOUT_HOST=$NIGHTSCOUT_HOST) | crontab -
(crontab -l; echo API_SECRET=$API_SECRET) | crontab -
fi
# add crontab entries
(crontab -l; crontab -l | grep -q PATH || echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') | crontab -
(crontab -l; crontab -l | grep -q killall || echo '* * * * * killall -g --older-than 10m openaps') | crontab -
(crontab -l; crontab -l | grep -q "reset-git" || echo "* * * * * cd $directory && oref0-reset-git") | crontab -
(crontab -l; crontab -l | grep -q uploader || echo "* * * * * cd $directory && ( ps aux | grep -v grep | grep -q 'openaps ' && echo OpenAPS already running || openaps upload ) 2>&1 | tee -a /var/log/openaps/uploader.log") | crontab -
crontab -l
fi

fi
8 changes: 4 additions & 4 deletions bin/oref0-calculate-iob.js
Expand Up @@ -21,16 +21,16 @@
var generate = require('oref0/lib/iob');

if (!module.parent) {
var iob_input = process.argv.slice(2, 3).pop()
var profile_input = process.argv.slice(3, 4).pop()
var clock_input = process.argv.slice(4, 5).pop()
var iob_input = process.argv.slice(2, 3).pop();
var profile_input = process.argv.slice(3, 4).pop();
var clock_input = process.argv.slice(4, 5).pop();

if (!iob_input || !profile_input) {
console.log('usage: ', process.argv.slice(0, 2), '<pumphistory.json> <profile.json> <clock.json>');
process.exit(1);
}

var cwd = process.cwd()
var cwd = process.cwd();
var all_data = require(cwd + '/' + iob_input);
var profile_data = require(cwd + '/' + profile_input);
var clock_data = require(cwd + '/' + clock_input);
Expand Down
27 changes: 18 additions & 9 deletions bin/oref0-determine-basal.js
Expand Up @@ -163,11 +163,12 @@ function init() {
console.log(JSON.stringify(rT));
return rT;
}
var threshold = profile.min_bg - 30;
// min_bg of 90 -> threshold of 70, 110 -> 80, and 130 -> 90
var threshold = profile.min_bg - 0.5*(profile.min_bg-50);

if (bg < threshold) { // low glucose suspend mode: BG is < ~80
rT.reason = "BG " + bg + "<" + threshold;
if ((glucose_status.delta < 0 && glucose_status.avgdelta < 0) || (glucose_status.delta < bgi && glucose_status.avgdelta < bgi)) {
if ((glucose_status.delta <= 0 && glucose_status.avgdelta <= 0) || (glucose_status.delta < bgi && glucose_status.avgdelta < bgi)) {
// BG is still falling / rising slower than predicted
console.error(rT.reason);
return determinebasal.setTempBasal(0, 30, profile, rT, offline);
Expand All @@ -191,7 +192,11 @@ function init() {
rT.reason = "Eventual BG " + eventualBG + "<" + profile.min_bg;
// if 5m or 15m avg BG is rising faster than BGI/2
if (glucose_status.delta > bgi/2 && glucose_status.avgdelta > bgi/2) {
rT.reason += ", but Delta " + tick + " > BGI " + bgi + " / 2";
if (glucose_status.delta > glucose_status.avgdelta) {
rT.reason += ", but Delta " + tick + " > BGI " + bgi + " / 2";
} else {
rT.reason += ", but Avg. Delta " + glucose_status.avgdelta + " > BGI " + bgi + " / 2";
}
if (currenttemp.duration > 0) { // if there is currently any temp basal running
rT.reason = rT.reason += "; cancel";
return determinebasal.setTempBasal(0, 0, profile, rT, offline); // cancel temp
Expand All @@ -205,14 +210,14 @@ function init() {
if (snoozeBG > profile.min_bg) { // if adding back in the bolus contribution BG would be above min
// if BG is falling and high-temped, or rising and low-temped, cancel
// compare against zero here, not BGI, because BGI will be highly negative from boluses and no carbs
if (glucose_status.delta < 0 && currenttemp.rate > profile.current_basal) {
if (glucose_status.delta < 0 && currenttemp.duration > 0 && currenttemp.rate > profile.current_basal) {
rT.reason += tick + ", and temp " + currenttemp.rate + " > basal " + profile.current_basal;
return determinebasal.setTempBasal(0, 0, profile, rT, offline); // cancel temp
} else if (glucose_status.delta > 0 && currenttemp.rate < profile.current_basal) {
} else if (glucose_status.delta > 0 && currenttemp.duration > 0 && currenttemp.rate < profile.current_basal) {
rT.reason += tick + ", and temp " + currenttemp.rate + " < basal " + profile.current_basal;
return determinebasal.setTempBasal(0, 0, profile, rT, offline); // cancel temp
}
rT.reason += "bolus snooze: eventual BG range " + eventualBG + "-" + snoozeBG;
rT.reason += ", bolus snooze: eventual BG range " + eventualBG + "-" + snoozeBG;
console.error(rT.reason);
console.log(JSON.stringify(rT));
return rT;
Expand All @@ -225,7 +230,7 @@ function init() {
rate = Math.round( rate * 1000 ) / 1000;
// if required temp < existing temp basal
if (typeof currenttemp.rate !== 'undefined' && (currenttemp.duration > 0 && rate > currenttemp.rate - 0.1)) {
rT.reason += "temp " + currenttemp.rate + " <~ req " + rate + "U/hr";
rT.reason += ", temp " + currenttemp.rate + " <~ req " + rate + "U/hr";
console.error(rT.reason);
console.log(JSON.stringify(rT));
return rT;
Expand All @@ -235,7 +240,11 @@ function init() {
}
// if eventual BG is above min but BG is falling faster than BGI/2
if (glucose_status.delta < bgi/2 || glucose_status.avgdelta < bgi/2) {
rT.reason = "Eventual BG " + eventualBG + ">" + profile.min_bg + " but Delta " + tick + " < BGI " + bgi + " / 2";
if (glucose_status.delta < glucose_status.avgdelta) {
rT.reason = "Eventual BG " + eventualBG + ">" + profile.min_bg + " but Delta " + tick + " < BGI " + bgi + " / 2";
} else {
rT.reason = "Eventual BG " + eventualBG + ">" + profile.min_bg + " but Avg. Delta " + glucose_status.avgdelta + " < BGI " + bgi + " / 2";
}
if (currenttemp.duration > 0) { // if there is currently any temp basal running
rT.reason = rT.reason += "; cancel";
return determinebasal.setTempBasal(0, 0, profile, rT, offline); // cancel temp
Expand Down Expand Up @@ -292,7 +301,7 @@ function init() {
rT.reason = currenttemp.duration + "@" + currenttemp.rate + " > req " + insulinReq + "U";
return determinebasal.setTempBasal(rate, 30, profile, rT, offline);
}
if (typeof currenttemp.rate == 'undefined' || currenttemp.rate == 0) { // no temp is set
if (typeof currenttemp.duration == 'undefined' || currenttemp.duration == 0) { // no temp is set
rT.reason += "no temp, setting " + rate + "U/hr";
return determinebasal.setTempBasal(rate, 30, profile, rT, offline);
}
Expand Down
1 change: 0 additions & 1 deletion bin/pebble.sh

This file was deleted.

1 change: 0 additions & 1 deletion bin/pumpsettings.sh

This file was deleted.

47 changes: 21 additions & 26 deletions lib/iob/calculate.js
@@ -1,45 +1,40 @@

function iobCalc(treatment, time, dia) {
var diaratio = dia / 3;
var diaratio = 3.0 / dia;
var peak = 75 ;
var end = 180 ;
//var sens = profile_data.sens;
if (typeof time === 'undefined') {
var time = new Date();
time = new Date();
}

var results = {};

if (treatment.insulin) {
var bolusTime=new Date(treatment.date);
var minAgo=(time-bolusTime)/1000/60 * diaratio;
var bolusTime = new Date(treatment.date);
var minAgo = diaratio * (time-bolusTime) / 1000 / 60;
var iobContrib = 0;
var activityContrib = 0;

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

results = {
iobContrib: iobContrib,
activityContrib: activityContrib
};
}
else {
return '';
}

return results;
}

exports = module.exports = iobCalc;