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

Basal and bolus average besides TDD and carbs in day to day report #4216

Merged
merged 5 commits into from
Dec 6, 2019
Merged
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
36 changes: 24 additions & 12 deletions lib/report_plugins/daytoday.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio
var padding = { top: 15, right: 22, bottom: 30, left: 35 };

var tddSum = 0;
var basalSum = 0;
var baseBasalSum = 0;
var bolusSum = 0;
var carbsSum = 0;
var proteinSum = 0;
var fatSum = 0;
Expand All @@ -95,22 +98,28 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio
});

var tddAverage = tddSum / datastorage.alldays;
var basalAveragePercent = Math.round( (basalSum / datastorage.alldays) / tddAverage * 100);
var baseBasalAveragePercent = Math.round( (baseBasalSum / datastorage.alldays) / tddAverage * 100);
var bolusAveragePercent = Math.round( (bolusSum / datastorage.alldays) / tddAverage * 100);
var carbsAverage = carbsSum / datastorage.alldays;
var proteinAverage = proteinSum / datastorage.alldays;
var fatAverage = fatSum / datastorage.alldays;

if (options.insulindistribution)
$('#daytodaycharts').append('<br><br>' +
'<b>' + translate('TDD average') + ':</b> ' + tddAverage.toFixed(1) + 'U ' +
'<b>' + translate('Carbs average') + ':</b> ' + carbsAverage.toFixed(0) + 'g ' +
'<b>' + translate('Protein average') + ':</b> ' + proteinAverage.toFixed(0) + 'g ' +
'<b>' + translate('Fat average') + ':</b> ' + fatAverage.toFixed(0) + 'g'
);

function timeTicks (n, i) {
var t12 = [
'12am', '', '2am', '', '4am', '', '6am', '', '8am', '', '10am', ''
, '12pm', '', '2pm', '', '4pm', '', '6pm', '', '8pm', '', '10pm', '', '12am'
if (options.insulindistribution) {
var html = '<br><br><b>' + translate('TDD average') + ':</b> ' + tddAverage.toFixed(1) + 'U&nbsp; ';
html += '<b>' + translate('Bolus average') + ':</b> ' + bolusAveragePercent + '%&nbsp; ';
html += '<b>' + translate('Basal average') + ':</b> ' + basalAveragePercent + '%&nbsp; ';
html += '<b>(' + translate('Base basal average:') + '</b> ' + baseBasalAveragePercent + '%<b>)</b>&nbsp; ';
html += '<b>' + translate('Carbs average') + ':</b> ' + carbsAverage.toFixed(0) + 'g';
html += '<b>' + translate('Protein average') + ':</b> ' + proteinAverage.toFixed(0) + 'g';
html += '<b>' + translate('Fat average') + ':</b> ' + fatAverage.toFixed(0) + 'g';
$('#daytodaycharts').append(html);
}

function timeTicks(n,i) {
var t12 = [
'12am', '', '2am', '', '4am', '', '6am', '', '8am', '', '10am', '',
'12pm', '', '2pm', '', '4pm', '', '6pm', '', '8pm', '', '10pm', '', '12am'
];
if (Nightscout.client.settings.timeFormat === 24) {
return ('00' + i).slice(-2);
Expand Down Expand Up @@ -1024,6 +1033,9 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio
}

tddSum += totalDailyInsulin;
basalSum += totalBasalInsulin;
baseBasalSum += baseBasalInsulin;
bolusSum += bolusInsulin;
carbsSum += data.dailyCarbs;
proteinSum += data.dailyProtein;
fatSum += data.dailyFat;
Expand Down