Skip to content

Commit

Permalink
Merge branch 'wip/plugins' of https://github.com/sulkaharo/cgm-remote…
Browse files Browse the repository at this point in the history
…-monitor into wip/show-plugins
  • Loading branch information
jasoncalabrese committed May 25, 2015
2 parents ff7f54d + d89436a commit fc7a6f6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
14 changes: 8 additions & 6 deletions lib/plugins/boluswizardpreview.js
Expand Up @@ -15,7 +15,7 @@ function init() {

var sgv = this.env.sgv;

var bat = 0.0;
var bolusEstimate = 0.0;

// TODO: MMOL -- Jason: if we assume sens is in display units, we don't need to do any conversion
sgv = this.scaleBg(sgv);
Expand All @@ -27,19 +27,21 @@ function init() {

if (outcome > this.profile.target_high) {
delta = outcome - this.profile.target_high;
bat = delta / this.profile.sens;
bolusEstimate = delta / this.profile.sens;
}

if (outcome < this.profile.target_low) {
delta = Math.abs(outcome - this.profile.target_low);
bat = delta / this.profile.sens * -1;
bolusEstimate = delta / this.profile.sens * -1;
}

bat = nsutils.toFixed((bat * 100) / 100);
bolusEstimate = this.roundInsulinForDisplayFormat(bolusEstimate);
outcome = this.roundBGToDisplayFormat(outcome);
var displayIOB = this.roundInsulinForDisplayFormat(this.iob.iob);

// display text
var info = [{label: 'Expected effect', value: '-' + Math.round(effect)}, {label: 'Expected outcome', value: Math.round(outcome)}];
this.updatePillText(bat + 'U', 'BWP', info);
var info = [{label: 'Insulin on Board', value: displayIOB + 'U'}, {label: 'Expected effect', value: '-' + this.roundBGToDisplayFormat(effect) + ' ' + this.getBGUnits()}, {label: 'Expected outcome', value: outcome + ' ' + this.getBGUnits()}];
this.updatePillText(bolusEstimate + 'U', 'BWP', info);

};

Expand Down
7 changes: 6 additions & 1 deletion lib/plugins/cannulaage.js
Expand Up @@ -16,6 +16,7 @@ function init() {
var age = 0;
var found = false;
var treatmentDate = null;
var message = '';

for (var t in this.env.treatments) {
if (this.env.treatments.hasOwnProperty(t)) {
Expand All @@ -31,13 +32,17 @@ function init() {
} else {
if (hours < age) {
age = hours;
if (treatment.notes) { message = treatment.notes; }
}
}
}
}
}

this.updatePillText(age + 'h', 'CAGE', [{label: 'Inserted', value: moment(treatmentDate).format('lll')}]);
var labels = [{label: 'Inserted:', value: moment(treatmentDate).format('lll')}];
if (message != '') labels.push({label: 'Notes:', value: message});

this.updatePillText(age + 'h', 'CAGE', labels);

};

Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/iob.js
Expand Up @@ -91,11 +91,11 @@ function init() {

if (this.iob.lastBolus) {
var when = moment(new Date(this.iob.lastBolus.created_at)).format('lll');
var amount = nsutils.toFixed(Number(this.iob.lastBolus.insulin)) + 'U';
var amount = this.roundInsulinForDisplayFormat(Number(this.iob.lastBolus.insulin)) + 'U';
info = [{label: 'Last Bolus', value: amount + ' @ ' + when }]
}

this.updatePillText(this.iob.display + 'U', 'IOB', info);
this.updatePillText(this.roundInsulinForDisplayFormat(this.iob.display) + 'U', 'IOB', info, true);
};

return iob();
Expand Down
35 changes: 34 additions & 1 deletion lib/plugins/pluginbase.js
Expand Up @@ -50,6 +50,36 @@ function updatePillText(updatedText, label, info, major) {
}
}

function roundInsulinForDisplayFormat(iob, roundingStyle) {

if (iob == 0) return 0;

if (roundingStyle === undefined) roundingStyle = 'generic';

if (roundingStyle == 'medtronic') {
var denominator = 0.1;
var digits = 1;
if (iob > 0.5 && iob < 1) { denominator = 0.05; digits = 2;}
if (iob <= 0.5) { denominator = 0.025; digits = 3;}
return (Math.floor(iob / denominator) * denominator).toFixed(digits);
}

return (Math.floor(iob / 0.01) * 0.01).toFixed(2);

}

function getBGUnits() {
if (browserSettings.units == 'mmol') return 'mmol/L';
return "mg/dl";
}

function roundBGToDisplayFormat(bg) {
if (browserSettings.units == 'mmol') {
return Math.round(bg * 10) / 10;
}
return Math.round(bg);
}

function scaleBg(bg) {
if (browserSettings.units == 'mmol') {
return Nightscout.units.mgdlToMMOL(bg);
Expand All @@ -62,7 +92,10 @@ function PluginBase() {
return {
setEnv: setEnv,
scaleBg: scaleBg,
updatePillText: updatePillText
updatePillText: updatePillText,
roundBGToDisplayFormat: roundBGToDisplayFormat,
roundInsulinForDisplayFormat: roundInsulinForDisplayFormat,
getBGUnits: getBGUnits
};
}

Expand Down

0 comments on commit fc7a6f6

Please sign in to comment.