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

Fixes issue https://github.com/nightscout/cgm-remote-monitor/issues/3660 #3661

Merged
merged 1 commit into from
Jul 3, 2018
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
32 changes: 24 additions & 8 deletions lib/report_plugins/glucosedistribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ glucosedistribution.report = function report_glucosedistribution(datastorage, so
var Nightscout = window.Nightscout;
var client = Nightscout.client;
var translate = client.translate;
var displayUnits = Nightscout.client.settings.units;

var ss = require('simple-statistics');

Expand Down Expand Up @@ -187,6 +188,8 @@ glucosedistribution.report = function report_glucosedistribution(datastorage, so

var prevEntry = glucose_data[0];

const maxGap = (5 * 60 * 1000) + 10000;

for (var i = 1; i < glucose_data.length-2; i++) {

// var prevEntry = glucose_data[i-1];
Expand All @@ -196,8 +199,6 @@ glucosedistribution.report = function report_glucosedistribution(datastorage, so
var timeDelta = nextEntry.displayTime.getTime() - entry.displayTime.getTime();
var timeDelta2 = entry.displayTime.getTime() - prevEntry.displayTime.getTime();

var maxGap = (5 * 60 * 1000) + 10000;

if (timeDelta > maxGap || timeDelta2 > maxGap ) {
glucose_data2.push(entry);
prevEntry = entry;
Expand Down Expand Up @@ -233,6 +234,23 @@ glucosedistribution.report = function report_glucosedistribution(datastorage, so
glucose_data = data = glucose_data2.filter(function(r) {
return enabledHours[new Date(r.displayTime).getHours()]
});

glucose_data.sort(function(a,b){
return a.displayTime.getTime()-b.displayTime.getTime();
});

var timeTotal = 0;

for (var i = 1; i < glucose_data.length-2; i++) {
var entry = glucose_data[i];
var nextEntry = glucose_data[i+1];
var timeDelta = nextEntry.displayTime.getTime() - entry.displayTime.getTime();
if (timeDelta < maxGap) {
timeTotal += timeDelta;
}
}

var daysTotal = timeTotal / (1000*60*60*24);

['Low', 'Normal', 'High'].forEach(function(range) {
result[range] = {};
Expand Down Expand Up @@ -403,9 +421,8 @@ glucosedistribution.report = function report_glucosedistribution(datastorage, so

console.log('glucoseMean', glucoseMean,'tirMultiplier',tirMultiplier, 'PGS',PGS);

var days = (glucose_data[glucose_data.length-1].displayTime.getTime() - glucose_data[0].displayTime.getTime()) / (24*60*60*1000.0);

var TDC = deltaTotal / days;
var TDC = deltaTotal / daysTotal;

var TDCHourly = TDC / 24.0;

var RMS = Math.sqrt(RMSTotal / events);
Expand All @@ -417,13 +434,12 @@ glucosedistribution.report = function report_glucosedistribution(datastorage, so

var unitString = ' mg/dl';

if (client.settings.units == 'mmol') {
if (displayUnits == 'mmol') {
TDC = TDC / 18.0;
TDCHourly = TDCHourly / 18.0;
unitString = ' mmol/L';

RMS = Math.sqrt(RMSTotal / events) / 18;

}

TDC = Math.round(TDC * 100) / 100;
Expand All @@ -434,7 +450,7 @@ glucosedistribution.report = function report_glucosedistribution(datastorage, so
var t1exp = '>5 mg/dl/5m';
var t2exp = '>10 mg/dl/5m';

if (client.settings.units == 'mmol') {
if (displayUnits == 'mmol') {
t1exp = '>0.27 mmol/l/5m';
t2exp = '>0.55 mmol/l/5m';
}
Expand Down