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

fix: Unit conversion fixes #4923

Merged
merged 1 commit into from
Sep 15, 2019
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
22 changes: 19 additions & 3 deletions lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,21 @@ function init (client, d3) {

renderer.addTreatmentCircles = function addTreatmentCircles () {
function treatmentTooltip (d) {
var targetBottom = d.targetBottom;
var targetTop = d.targetTop;

if (client.settings.units === 'mmol') {
targetBottom = Math.round(targetBottom / 18.0 * 10) / 10;
targetTop = Math.round(targetTop / 18.0 * 10) / 10;
}

return '<strong>' + translate('Time') + ':</strong> ' + client.formatTime(new Date(d.mills)) + '<br/>' +
(d.eventType ? '<strong>' + translate('Treatment type') + ':</strong> ' + translate(client.careportal.resolveEventName(d.eventType)) + '<br/>' : '') +
(d.reason ? '<strong>' + translate('Reason') + ':</strong> ' + translate(d.reason) + '<br/>' : '') +
(d.glucose ? '<strong>' + translate('BG') + ':</strong> ' + d.glucose + (d.glucoseType ? ' (' + translate(d.glucoseType) + ')' : '') + '<br/>' : '') +
(d.enteredBy ? '<strong>' + translate('Entered By') + ':</strong> ' + d.enteredBy + '<br/>' : '') +
(d.targetTop ? '<strong>' + translate('Target Top') + ':</strong> ' + d.targetTop + '<br/>' : '') +
(d.targetBottom ? '<strong>' + translate('Target Bottom') + ':</strong> ' + d.targetBottom + '<br/>' : '') +
(d.targetTop ? '<strong>' + translate('Target Top') + ':</strong> ' + targetTop + '<br/>' : '') +
(d.targetBottom ? '<strong>' + translate('Target Bottom') + ':</strong> ' + targetBottom + '<br/>' : '') +
(d.duration ? '<strong>' + translate('Duration') + ':</strong> ' + Math.round(d.duration) + ' min<br/>' : '') +
(d.notes ? '<strong>' + translate('Notes') + ':</strong> ' + d.notes : '');
}
Expand Down Expand Up @@ -517,6 +525,14 @@ function init (client, d3) {
}

function treatmentTooltip () {
var glucose = treatment.glucose;
if (client.settings.units != client.ddata.profile.data[0].units) {
glucose *= (client.settings.units === 'mmol' ? 0.055 : 18);
var decimals = (client.settings.units === 'mmol' ? 10 : 1);

glucose = Math.round(glucose * decimals) / decimals;
}

client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9);
client.tooltip.html('<strong>' + translate('Time') + ':</strong> ' + client.formatTime(new Date(treatment.mills)) + '<br/>' + '<strong>' + translate('Treatment type') + ':</strong> ' + translate(client.careportal.resolveEventName(treatment.eventType)) + '<br/>' +
(treatment.carbs ? '<strong>' + translate('Carbs') + ':</strong> ' + treatment.carbs + '<br/>' : '') +
Expand All @@ -525,7 +541,7 @@ function init (client, d3) {
(treatment.absorptionTime > 0 ? '<strong>' + translate('Absorption Time') + ':</strong> ' + (Math.round(treatment.absorptionTime / 60.0 * 10) / 10) + 'h' + '<br/>' : '') +
(treatment.insulin ? '<strong>' + translate('Insulin') + ':</strong> ' + treatment.insulin + '<br/>' : '') +
(treatment.enteredinsulin ? '<strong>' + translate('Combo Bolus') + ':</strong> ' + treatment.enteredinsulin + 'U, ' + treatment.splitNow + '% : ' + treatment.splitExt + '%, ' + translate('Duration') + ': ' + treatment.duration + '<br/>' : '') +
(treatment.glucose ? '<strong>' + translate('BG') + ':</strong> ' + treatment.glucose + (treatment.glucoseType ? ' (' + translate(treatment.glucoseType) + ')' : '') + '<br/>' : '') +
(treatment.glucose ? '<strong>' + translate('BG') + ':</strong> ' + glucose + (treatment.glucoseType ? ' (' + translate(treatment.glucoseType) + ')' : '') + '<br/>' : '') +
(treatment.enteredBy ? '<strong>' + translate('Entered By') + ':</strong> ' + treatment.enteredBy + '<br/>' : '') +
(treatment.notes ? '<strong>' + translate('Notes') + ':</strong> ' + treatment.notes : '') +
boluscalcTooltip(treatment)
Expand Down
11 changes: 10 additions & 1 deletion lib/plugins/basalprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ function init (ctx) {

var tzMessage = profile.getTimezone() ? profile.getTimezone() : 'Timezone not set in profile';

var sensitivity = profile.getSensitivity(sbx.time);

if (sbx.settings.units != profile.data[0].units) {
sensitivity *= (sbx.settings.units === 'mmol' ? 0.055 : 18);
var decimals = (sbx.settings.units === 'mmol' ? 10 : 1);

sensitivity = Math.round(sensitivity * decimals) / decimals;
}

var info = [{label: translate('Current basal'), value: prop.display}
, {label: translate('Sensitivity'), value: profile.getSensitivity(sbx.time) + ' ' + sbx.settings.units + ' / U'}
, {label: translate('Sensitivity'), value: sensitivity + ' ' + sbx.settings.units + ' / U'}
, {label: translate('Current Carb Ratio'), value: '1 U / ' + profile.getCarbRatio(sbx.time) + 'g'}
, {label: translate('Basal timezone'), value: tzMessage}
, {label: '------------', value: ''}
Expand Down
6 changes: 5 additions & 1 deletion lib/plugins/openaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,13 @@ function init (ctx) {

function addSuggestion () {
if (prop.lastSuggested) {
var bg = prop.lastSuggested.bg;
if (sbx.data.profile.data[0].units === 'mmol') {
bg = Math.round(bg / 18 * 10) / 10;
}

var valueParts = [
valueString('BG: ', prop.lastSuggested.bg)
valueString('BG: ', bg)
, valueString(', ', prop.lastSuggested.reason)
, prop.lastSuggested.sensitivityRatio ? ', <b>Sensitivity Ratio:</b> ' + prop.lastSuggested.sensitivityRatio : ''
];
Expand Down