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

Wip/bwp improvements #959

Merged
merged 2 commits into from
Sep 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion lib/plugins/boluswizardpreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var _ = require('lodash');
var levels = require('../levels');
var times = require('../times');
var CONST_60_MINUTES_IN_MS = 3600000;

function init() {

Expand Down Expand Up @@ -124,7 +125,20 @@ function init() {
results.effect = iob * profile.getSensitivity(sbx.time);
results.outcome = scaled - results.effect;
var delta = 0;

var timeSinceLastMeal = 1000000000;
var now = (new Date).getTime();

for (var i = 0; i < sbx.data.treatments.length; i++) {
var treatment = sbx.data.treatments[i];
var delta = now - treatment.mills;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (delta < timeSinceLastMeal) { timeSinceLastMeal = delta;}
}

results.timeSinceLastMeal = timeSinceLastMeal;
results.mealEatenRecently = false;
if (timeSinceLastMeal < CONST_60_MINUTES_IN_MS) { results.mealEatenRecently = true; }

var target_high = profile.getHighBGTarget(sbx.time);
var sens = profile.getSensitivity(sbx.time);

Expand All @@ -137,6 +151,11 @@ function init() {

var target_low = profile.getLowBGTarget(sbx.time);

results.belowLowTarget = false;
if (scaled < target_low) {
results.belowLowTarget = true;
}

if (results.outcome < target_low) {
delta = Math.abs(results.outcome - target_low);
results.bolusEstimate = delta / sens * -1;
Expand Down Expand Up @@ -197,6 +216,7 @@ function pushInfo(prop, info, sbx) {
});
} else if (prop) {
info.push({label: 'Insulin on Board', value: prop.displayIOB + 'U'});
info.push({label: 'Current target', value: 'Low: '+sbx.data.profile.getLowBGTarget(sbx.time) + ' High: ' + sbx.data.profile.getHighBGTarget(sbx.time)});
info.push({label: 'Sensitivity', value: '-' + sbx.data.profile.getSensitivity(sbx.time) + ' ' + sbx.settings.units + '/U'});
info.push({label: 'Expected effect', value: prop.displayIOB + ' x -' + sbx.data.profile.getSensitivity(sbx.time) + ' = -' + prop.effectDisplay + ' ' + sbx.settings.units});
info.push({label: 'Expected outcome', value: sbx.lastScaledSGV() + '-' + prop.effectDisplay + ' = ' + prop.outcomeDisplay + ' ' + sbx.settings.units});
Expand All @@ -205,7 +225,20 @@ function pushInfo(prop, info, sbx) {
var carbEquivalent = Math.ceil(Math.abs(sbx.data.profile.getCarbRatio() * prop.bolusEstimateDisplay));
info.unshift({label: 'Carb Equivalent', value: prop.bolusEstimateDisplay + 'U * ' + sbx.data.profile.getCarbRatio() + ' = ' + carbEquivalent + 'g'});
info.unshift({label: 'Current Carb Ratio', value: '1U / ' + sbx.data.profile.getCarbRatio() + ' g'});
info.unshift({label: '-BWP', value: prop.bolusEstimateDisplay + 'U, maybe covered by carbs?'});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (prop.mealEatenRecently) info.unshift({label: 'Meal eaten recently', value: 'excess IOB is probably your meal bolus?'});

if (!prop.belowLowTarget) {
info.unshift({label: '-BWP', value: 'Excess insulin equivalent ' + prop.bolusEstimateDisplay + 'U more than needed to reach low target, not account for carbs'});
}

if (prop.belowLowTarget) {
if (prop.iob > 0) {
info.unshift({label: '-BWP', value: 'Excess insulin equivalent ' + prop.bolusEstimateDisplay + 'U more than needed to reach low target, MAKE SURE IOB IS COVERED BY CARBS'});
} else {
info.unshift({label: '-BWP', value: prop.bolusEstimateDisplay + 'U reduction needed in active insulin to reach low target, too much basal?'});
}
}
}
} else {
info.push({label: 'Notice', value: 'required info missing'});
Expand Down
2 changes: 1 addition & 1 deletion lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function init (env, ctx, server) {

function emitData (delta) {
if (lastData.cals) {
console.log('running websocket.emitData', ctx.data.lastUpdated, delta.recentsgvs && delta.sgvdataupdate.length);
console.log('running websocket.emitData', ctx.data.lastUpdated);
io.emit('dataUpdate', delta);
}
}
Expand Down