');
diff --git a/lib/report_plugins/loopalyzer.js b/lib/report_plugins/loopalyzer.js
index 8eb96e68..2d53fa25 100644
--- a/lib/report_plugins/loopalyzer.js
+++ b/lib/report_plugins/loopalyzer.js
@@ -11,7 +11,7 @@ var loopalyzer = {
, pluginType: 'report'
};
-function init() {
+function init () {
return loopalyzer;
}
@@ -23,80 +23,79 @@ var risingInterpolationGap = 6; // How large a gap in COB/IOB graph is allowed t
var fallingInterpolationGap = 24; // And if less than start
var interpolationRatio = 1.25; // But do allow rising interpolation if gap larger than interpolationGap and end value is less than 10% larger than start
-loopalyzer.html = function html(client) {
+loopalyzer.html = function html (client) {
var translate = client.translate;
var ret = '';
- ret += '
Loopalyzer
';
- ret += '' + translate('The primary purpose of Loopalyzer is to visualise how the Loop closed loop system performs. It may work with other setups as well, both closed and open loop, and non loop. However depending on which uploader you use, how frequent it is able to capture your data and upload, and how it is able to backfill missing data some graphs may have gaps or even be completely empty. Always ensure the graphs look reasonable. Best is to view one day at a time and scroll through a number of days first to see.');
- ret += '
' + translate('Loopalyzer includes a time shift feature. If you for example have breakfast at 07:00 one day and at 08:00 the day after your average blood glucose curve these two days will most likely look flattened and not show the actual response after a breakfast. Time shift will compute the average time these meals were eaten and then shift all data (carbs, insulin, basal etc.) during both days the corresponding time difference so that both meals align with the average meal start time. ');
- ret += ' ' + translate('In this example all data from first day is pushed 30 minutes forward in time and all data from second day 30 minutes backward in time so it appears as if you had had breakfast at 07:30 both days. This allows you to see your actual average blood glucose response from a meal.');
- ret += ' ' + translate('Time shift highlights the period after the average meal start time in gray, for the duration of the DIA (Duration of Insulin Action). As all data points the entire day are shifted the curves outside the gray area may not be accurate.');
- ret += ' ' + translate('Note that time shift is available only when viewing multiple days.');
- ret += '
';
- ret += translate('To see this report, press SHOW while in this view');
- ret += '';
- ret += '' + translate('Please select a maximum of' +
- ' two weeks duration and click Show again.') + '
';
- ret += '
';
- ret += ''+translate('Show profiles table')+' ';
- ret += ''+translate('Show predictions');
- ret += ' ';
- ret += ''; /* So we can show only if viewing multiple days style="display:none;" */
- ret += '';
- ret += translate('Timeshift on meals larger than') + ' ';
- ret += ''+' '+translate('g carbs');
- ret += ' '+translate('consumed between');
- ret += ' ';
- ret += ' '+translate('and');
- ret += ' ';
- ret += ''; /* timeShift */
- ret += '
';
- ret += '';
- ret += '';
- ret += '';
- ret += '';
- ret += '
';/* loopalyzer-button */
- ret += '
';
- ret += ' ';
- ret += ' ';
- ret += ' ';
- ret += ' ';
- ret += ' ';
- ret += '
';
- ret += '
';
- ret += '
';
- return ret;
+ ret += '
Loopalyzer
';
+ ret += '' + translate('The primary purpose of Loopalyzer is to visualise how the Loop closed loop system performs. It may work with other setups as well, both closed and open loop, and non loop. However depending on which uploader you use, how frequent it is able to capture your data and upload, and how it is able to backfill missing data some graphs may have gaps or even be completely empty. Always ensure the graphs look reasonable. Best is to view one day at a time and scroll through a number of days first to see.');
+ ret += '
' + translate('Loopalyzer includes a time shift feature. If you for example have breakfast at 07:00 one day and at 08:00 the day after your average blood glucose curve these two days will most likely look flattened and not show the actual response after a breakfast. Time shift will compute the average time these meals were eaten and then shift all data (carbs, insulin, basal etc.) during both days the corresponding time difference so that both meals align with the average meal start time. ');
+ ret += ' ' + translate('In this example all data from first day is pushed 30 minutes forward in time and all data from second day 30 minutes backward in time so it appears as if you had had breakfast at 07:30 both days. This allows you to see your actual average blood glucose response from a meal.');
+ ret += ' ' + translate('Time shift highlights the period after the average meal start time in gray, for the duration of the DIA (Duration of Insulin Action). As all data points the entire day are shifted the curves outside the gray area may not be accurate.');
+ ret += ' ' + translate('Note that time shift is available only when viewing multiple days.');
+ ret += '
';
+ ret += translate('To see this report, press SHOW while in this view');
+ ret += '';
+ ret += '' + translate('Please select a maximum of' +
+ ' two weeks duration and click Show again.') + '
';
+ ret += '
';
+ ret += '' + translate('Show profiles table') + ' ';
+ ret += '' + translate('Show predictions');
+ ret += ' ';
+ ret += ''; /* So we can show only if viewing multiple days style="display:none;" */
+ ret += '';
+ ret += translate('Timeshift on meals larger than') + ' ';
+ ret += '' + ' ' + translate('g carbs');
+ ret += ' ' + translate('consumed between');
+ ret += ' ';
+ ret += ' ' + translate('and');
+ ret += ' ';
+ ret += ''; /* timeShift */
+ ret += '
';
+ ret += '';
+ ret += '';
+ ret += '';
+ ret += '';
+ ret += '
'; /* loopalyzer-button */
+ ret += '
';
+ ret += ' ';
+ ret += ' ';
+ ret += ' ';
+ ret += ' ';
+ ret += ' ';
+ ret += '
'));
+loopalyzer.prepareHtml = function loopalyzerPrepareHtml () {
+ // $('#loopalyzer-charts').append($('
'));
};
// loopalyzer.ss = require('simple-statistics');
@@ -111,17 +110,17 @@ loopalyzer.getSGVs = function(datastorage, daysToShow) {
// Loop thru the days to show, for each day find the matching SGVs and insert into the bins entry array
daysToShow.forEach(function(day) {
var entries = []; // Array with all SGVs for this day, we'll fill this and then insert into the bins later
- for (var i=0; i<288; i++) entries.push(NaN); // Fill the array with NaNs so we have something in case we don't find an SGV
+ for (let i = 0; i < 288; i++) entries.push(NaN); // Fill the array with NaNs so we have something in case we don't find an SGV
var fromDate = moment(day);
var toDate = moment(day);
- fromDate.set({'hours':0, 'minutes':0, 'seconds':0, 'milliseconds':0});
- toDate.set({'hours':0, 'minutes':5, 'seconds':0, 'milliseconds':0}); // toDate is 5 mins ahead
- for (var i=0; i<288; i++) {
+ fromDate.set({ 'hours': 0, 'minutes': 0, 'seconds': 0, 'milliseconds': 0 });
+ toDate.set({ 'hours': 0, 'minutes': 5, 'seconds': 0, 'milliseconds': 0 }); // toDate is 5 mins ahead
+ for (let i = 0; i < 288; i++) {
var found = false;
data.some(function(record) {
var recDate = moment(record.displayTime);
if (!found && recDate.isAfter(fromDate) && recDate.isBefore(toDate)) {
- entries[i]=record.sgv;
+ entries[i] = record.sgv;
found = true;
}
return found; // Breaks .some loop if found is true
@@ -141,10 +140,10 @@ loopalyzer.getBasals = function(datastorage, daysToShow, profile) {
var dayStart = moment(day).startOf('day');
var dayEnd = moment(day).endOf('day');
var basals = [];
- for (var i=0; i<288; i++) basals.push(NaN); // Clear the basals by filling with NaNs
+ for (var i = 0; i < 288; i++) basals.push(NaN); // Clear the basals by filling with NaNs
var index = 0;
- for (var dt=dayStart; dt < dayEnd; dt.add(5, 'minutes')) {
+ for (var dt = dayStart; dt < dayEnd; dt.add(5, 'minutes')) {
var basal = profile.getTempBasal(dt.toDate());
if (basal)
basals[index++] = basal.basal;
@@ -162,10 +161,10 @@ loopalyzer.getTempBasalDeltas = function(datastorage, daysToShow, profile) {
var dayStart = moment(day).startOf('day');
var dayEnd = moment(day).endOf('day');
var temps = [];
- for (var i=0; i<288; i++) temps.push(NaN); // Clear the basals by filling with NaNs
+ for (var i = 0; i < 288; i++) temps.push(NaN); // Clear the basals by filling with NaNs
var index = 0;
- for (var dt=dayStart; dt < dayEnd; dt.add(5, 'minutes')) {
+ for (var dt = dayStart; dt < dayEnd; dt.add(5, 'minutes')) {
var basal = profile.getTempBasal(dt.toDate());
if (basal)
temps[index++] = basal.tempbasal - basal.basal;
@@ -188,37 +187,38 @@ loopalyzer.getIOBs = function(datastorage, daysToShow, profile, client, treatmen
var iobs = [];
if (iobStatusAvailable) {
// var dayStartMills = dayStart.milliseconds();
- for (var i=0; i<288; i++) iobs.push(NaN); // Clear the IOBs by filling with NaNs
+ for (var i = 0; i < 288; i++) iobs.push(NaN); // Clear the IOBs by filling with NaNs
var iobArray = client.plugins('iob').IOBDeviceStatusesInTimeRange(datastorage.devicestatus, dayStart.valueOf(), dayEnd.valueOf());
if (laDebug) console.log('getIOBs iobArray', iobArray);
- iobArray.forEach(function(entry){
- var index = Math.floor(moment(entry.mills).diff(dayStart,'minutes') / 5);
+ iobArray.forEach(function(entry) {
+ var index = Math.floor(moment(entry.mills).diff(dayStart, 'minutes') / 5);
iobs[index] = entry.iob;
});
- if (daysToShow.length===1) loopalyzer.fillNanWithTreatments(iobs, treatments);
+ if (daysToShow.length === 1) loopalyzer.fillNanWithTreatments(iobs, treatments);
// Loop thru these entries and where no IOB has been found, interpolate between nearby to get a continuous array
- var startIndex = 0, stopIndex = 0;
+ var startIndex = 0
+ , stopIndex = 0;
while (startIndex < iobs.length && isNaN(iobs[startIndex])) {
startIndex++; // Advance start to the first real number
}
if (startIndex < iobs.length) {
- stopIndex = startIndex+1;
- while (stopIndex=0 && isNaN(array[start])) {};
- while (stop++ = 0 && isNaN(array[start])) {}
+ // eslint-disable-next-line no-empty
+ while (stop++ < array.length && isNaN(array[stop])) {}
// var gap = stop - start;
// if (isNaN(array[start]) || isNaN(array[stop]) || gap > interpolationGap || (gap < interpolationGap && array[start]= interpolationGap || array[start]==0)) ) {
- var interpolate = (isNaN(array[start]) || isNaN(array[stop]) ? true : loopalyzer.canInterpolate(array,start,stop));
+ var interpolate = (isNaN(array[start]) || isNaN(array[stop]) ? true : loopalyzer.canInterpolate(array, start, stop));
if (!interpolate) {
array[index] = treatment.amount;
}
@@ -331,12 +336,12 @@ loopalyzer.fillNanWithTreatments = function(array, treatments) {
/* Returns true if we can interpolate between this start and end */
loopalyzer.canInterpolate = function(array, start, stop) {
var interpolate = false;
- if (array[stop] <= array[start]*interpolationRatio) {
+ if (array[stop] <= array[start] * interpolationRatio) {
// Falling
- if (stop-start0}).forEach(function(treatment){
+ datastorage.treatments.filter(function(treatment) { return treatment.carbs && treatment.carbs > 0 }).forEach(function(treatment) {
if (moment(treatment.created_at).isBetween(startDate, endDate)) {
- treatments.push({date:treatment.created_at, amount:treatment.carbs});
+ treatments.push({ date: treatment.created_at, amount: treatment.carbs });
}
})
if (laDebug) console.log('Carb treatments', treatments);
@@ -360,11 +365,11 @@ loopalyzer.getCarbTreatments = function(datastorage, daysToShow) {
loopalyzer.getInsulinTreatments = function(datastorage, daysToShow) {
var treatments = []; // Holds the treatments [date, amount]
var startDate = moment(daysToShow[0]);
- var endDate = moment(daysToShow[daysToShow.length-1]).add(1, 'days');
+ var endDate = moment(daysToShow[daysToShow.length - 1]).add(1, 'days');
- datastorage.treatments.filter(function(treatment){return treatment.insulin && treatment.insulin >0}).forEach(function(treatment){
+ datastorage.treatments.filter(function(treatment) { return treatment.insulin && treatment.insulin > 0 }).forEach(function(treatment) {
if (moment(treatment.created_at).isBetween(startDate, endDate)) {
- treatments.push({date:treatment.created_at, amount:treatment.insulin});
+ treatments.push({ date: treatment.created_at, amount: treatment.insulin });
}
})
if (laDebug) console.log('Insulin treatments', treatments);
@@ -376,12 +381,12 @@ loopalyzer.getInsulinTreatments = function(datastorage, daysToShow) {
loopalyzer.getAllTreatmentTimestampsForADay = function(datastorage, day) {
var timestamps = [];
var dayStart = moment(day).startOf('day');
- var carbTreatments = loopalyzer.getCarbTreatments(datastorage,[day]);
- var insulinTreatments = loopalyzer.getInsulinTreatments(datastorage,[day]);
- carbTreatments.forEach(function(entry) { timestamps.push(entry.date)});
- insulinTreatments.forEach(function(entry) { timestamps.push(entry.date)});
- timestamps.sort(function(a,b) { return (a= 0; i--) {
if (datastorage.devicestatus[i].loop && datastorage.devicestatus[i].loop.predicted) {
var predicted = datastorage.devicestatus[i].loop.predicted;
- if (moment(predicted.startDate).isSame(dayStart,'day'))
+ if (moment(predicted.startDate).isSame(dayStart, 'day'))
predictions.push(datastorage.devicestatus[i].loop.predicted);
} else if (datastorage.devicestatus[i].openaps && datastorage.devicestatus[i].openaps.suggested && datastorage.devicestatus[i].openaps.suggested.predBGs) {
var entry = {};
@@ -408,7 +413,7 @@ loopalyzer.getAllPredictionsForADay = function(datastorage, day) {
// Remove duplicates before we're done
var p = [];
predictions.forEach(function(prediction) {
- if (p.length === 0 || prediction.startDate !== p[p.length-1].startDate)
+ if (p.length === 0 || prediction.startDate !== p[p.length - 1].startDate)
p.push(prediction);
})
return p;
@@ -421,13 +426,13 @@ loopalyzer.findPredicted = function(predictions, timestamp, offset) {
var ts = moment(timestamp).add(offset, 'minutes');
var predicted = null;
if (offset && offset < 0) { // If offset is negative, start searching from first prediction going forward
- for (var i = 0; i < predictions.length; i++) {
+ for (let i = 0; i < predictions.length; i++) {
if (predictions[i] && predictions[i].startDate && moment(predictions[i].startDate) <= ts) {
predicted = i;
}
}
- } else { // If offset is positive or zero, start searching from last prediction going backward
- for (var i = predictions.length - 1; i > 0; i--) {
+ } else { // If offset is positive or zero, start searching from last prediction going backward
+ for (let i = predictions.length - 1; i > 0; i--) {
if (predictions[i] && predictions[i].startDate && moment(predictions[i].startDate) >= ts) {
predicted = i;
}
@@ -436,7 +441,6 @@ loopalyzer.findPredicted = function(predictions, timestamp, offset) {
return predicted;
}
-
loopalyzer.getPredictions = function(datastorage, daysToShow, client) {
if (!datastorage.devicestatus)
@@ -448,110 +452,112 @@ loopalyzer.getPredictions = function(datastorage, daysToShow, client) {
// Fill the bins array with the timestamp, one per 5 minutes
var bins = [];
var date = moment();
- date.set({'hours':0, 'minutes':0, 'seconds':0, 'milliseconds':0});
- for (var i=0; i<288; i++) {
- bins.push([date.toDate(),[]]);
+ date.set({ 'hours': 0, 'minutes': 0, 'seconds': 0, 'milliseconds': 0 });
+ for (var i = 0; i < 288; i++) {
+ bins.push([date.toDate(), []]);
date.add(5, 'minutes');
}
daysToShow.forEach(function(day) {
- var p = []; // Array with all prediction SGVs for this day, we'll fill this and then insert into the bins later
- for (var i=0; i<288; i++) p.push(NaN);
- var treatmentTimestamps = loopalyzer.getAllTreatmentTimestampsForADay(datastorage, day);
- var predictions = loopalyzer.getAllPredictionsForADay(datastorage, day);
+ var p = []; // Array with all prediction SGVs for this day, we'll fill this and then insert into the bins later
+ for (var i = 0; i < 288; i++) p.push(NaN);
+ var treatmentTimestamps = loopalyzer.getAllTreatmentTimestampsForADay(datastorage, day);
+ var predictions = loopalyzer.getAllPredictionsForADay(datastorage, day);
- if (predictions.length > 0 && treatmentTimestamps.length > 0) {
+ if (predictions.length > 0 && treatmentTimestamps.length > 0) {
- // Iterate over all treatments, find the predictions for each and add them to the entries array p, aligned on timestamp
- for (var treatmentsIndex = 0; treatmentsIndex < treatmentTimestamps.length; treatmentsIndex++) {
- var timestamp = treatmentTimestamps[treatmentsIndex];
- var predictedIndex = loopalyzer.findPredicted(predictions, timestamp, predictedOffset); // Find predictions offset before or after timestamp
+ // Iterate over all treatments, find the predictions for each and add them to the entries array p, aligned on timestamp
+ for (var treatmentsIndex = 0; treatmentsIndex < treatmentTimestamps.length; treatmentsIndex++) {
+ var timestamp = treatmentTimestamps[treatmentsIndex];
+ var predictedIndex = loopalyzer.findPredicted(predictions, timestamp, predictedOffset); // Find predictions offset before or after timestamp
- if (predictedIndex != null) {
- var entry = predictions[predictedIndex]; // Start entry
- var d = moment(entry.startDate);
- var end = moment(day).endOf('day'); // Default to stop and end of the day
- if (truncatePredictions) {
- if (predictedOffset >= 0) {
- // But if we are looking forward we want to stop at the next treatment
- if (treatmentsIndex < treatmentTimestamps.length - 1) {
- end = moment(treatmentTimestamps[treatmentsIndex + 1]);
- }
- } else {
- // And if we are looking backward then we want to stop at "this" treatment
- end = moment(treatmentTimestamps[treatmentsIndex]);
+ if (predictedIndex != null) {
+ var entry = predictions[predictedIndex]; // Start entry
+ var d = moment(entry.startDate);
+ var end = moment(day).endOf('day'); // Default to stop and end of the day
+ if (truncatePredictions) {
+ if (predictedOffset >= 0) {
+ // But if we are looking forward we want to stop at the next treatment
+ if (treatmentsIndex < treatmentTimestamps.length - 1) {
+ end = moment(treatmentTimestamps[treatmentsIndex + 1]);
}
+ } else {
+ // And if we are looking backward then we want to stop at "this" treatment
+ end = moment(treatmentTimestamps[treatmentsIndex]);
}
- for (var entryIndex in entry.values) {
- if (!d.isAfter(end)) {
- var dayStart = moment(d).startOf('day');
- var minutesAfterMidnight = moment(d).diff(dayStart, 'minutes');
- var index = Math.floor(minutesAfterMidnight/5);
- p[index] = client.utils.scaleMgdl(entry.values[entryIndex]);
- d.add(5, 'minutes');
- }
+ }
+ for (var entryIndex in entry.values) {
+ if (!d.isAfter(end)) {
+ var dayStart = moment(d).startOf('day');
+ var minutesAfterMidnight = moment(d).diff(dayStart, 'minutes');
+ var index = Math.floor(minutesAfterMidnight / 5);
+ p[index] = client.utils.scaleMgdl(entry.values[entryIndex]);
+ d.add(5, 'minutes');
}
}
}
}
- for (var i=0; i<288; i++) {
- bins[i][1].push(p[i]);
- }
- })
- return bins;
- }
- //
- // PREDICTIONS ENDS
-
+ }
+ for (let i = 0; i < 288; i++) {
+ bins[i][1].push(p[i]);
+ }
+ })
+ return bins;
+}
+//
+// PREDICTIONS ENDS
// VARIOUS UTILITY FUNCTIONS //
/* Create an empty bins array with date stamps for today */
loopalyzer.getEmptyBins = function() {
- var bins=[];
+ var bins = [];
var todayStart = moment().startOf('day');
var todayEnd = moment().endOf('day');
- for (var dt=todayStart; dt < todayEnd; dt.add(5, 'minutes')) {
+ for (var dt = todayStart; dt < todayEnd; dt.add(5, 'minutes')) {
bins.push([dt.toDate(), []]);
}
- return bins;
+ return bins;
}
/* Takes an array of 288 values and adds to the bins */
loopalyzer.addArrayToBins = function(bins, values) {
if (bins && bins.length === 288 && values && values.length === 288) {
- values.forEach(function(value,index) {
+ values.forEach(function(value, index) {
bins[index][1].push(value);
});
- } else
+ } else
console.log('addArrayToBins - array must have 288 items', values);
}
/* Fill all NaNs in an array by interpolating between adjacent values */
loopalyzer.interpolateArray = function(values, allowNegative) {
- var startIndex=0, stopIndex=0, k=0, m=0;
+ var startIndex = 0
+ , stopIndex = 0
+ , k = 0
+ , m = 0;
while (isNaN(values[startIndex])) {
startIndex++; // Advance start to the first real number
}
- stopIndex = startIndex+1;
- while (stopIndexmax) max = xBins[i][1];
+ if (!isNaN(xBins[i][1]) && xBins[i][1] > max) max = xBins[i][1];
}
return max;
}
/* Compute avg value in bins */
loopalyzer.avg = function(xBins) {
- var out=[];
- xBins.forEach(function(entry){
+ var out = [];
+ xBins.forEach(function(entry) {
var sum = 0;
var count = 0;
- entry[1].forEach(function(value){
- if (value && value != NaN) {
+ entry[1].forEach(function(value) {
+ if (value && !isNaN(value)) {
sum += value;
count++;
}
@@ -599,36 +605,36 @@ loopalyzer.avg = function(xBins) {
// Timeshifts a bins array with subarrays for multiple days
loopalyzer.timeShiftBins = function(bins, timeShift) {
- if (bins && bins.length>0) {
- timeShift.forEach(function(minutes, dayIndex){
- if (minutes !==0) {
+ if (bins && bins.length > 0) {
+ timeShift.forEach(function(minutes, dayIndex) {
+ if (minutes !== 0) {
var tempBin = [];
- bins.forEach(function(){
+ bins.forEach(function() {
tempBin.push(NaN); // Fill tempBin with NaNs
})
- var minutesBy5 = Math.floor(minutes/5);
- if (minutesBy5>0) {
- var count = 288-minutesBy5;
+ var minutesBy5 = Math.floor(minutes / 5);
+ if (minutesBy5 > 0) {
+ let count = 288 - minutesBy5;
// If minutes>0 it means we should shift forward in time
// Example: Shift by 15 mins = 3 buckets
// bin : 0 1 2 3 4 5 6 7 8 9 10
// tempBin: NaN NaN NaN 0 1 2 3 4 5 6 7
- for (var i=0; i0) {
- daysToShow.forEach(function(day, dayIndex){
+ if (bin && bin.length > 0) {
+ daysToShow.forEach(function(day, dayIndex) {
var minutesToAdd = timeShift[dayIndex];
var date = moment(day);
- bin.forEach(function(entry, entryIndex){
+ bin.forEach(function(entry, entryIndex) {
var entryDate = moment(entry.date);
if (entryDate.isSame(date, 'day')) {
entryDate.add(minutesToAdd, 'minutes');
- bin[entryIndex].date=entryDate.toDate();
+ bin[entryIndex].date = entryDate.toDate();
}
})
})
@@ -654,7 +660,7 @@ loopalyzer.timeShiftSingleBin = function(bin, daysToShow, timeShift) {
}
/* Returns true if the profile values in a is identical to values in b, false otherwise */
-loopalyzer.isSameProfileValues = function(a,b) {
+loopalyzer.isSameProfileValues = function(a, b) {
// Because the order of the keys are random when stringifying we do our own custom stringify ourselves
var aString = '';
var bString = '';
@@ -697,12 +703,12 @@ loopalyzer.isSameProfileValues = function(a,b) {
return (aString == bString);
}
-loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client) {
+loopalyzer.renderProfilesTable = function(datastoreProfiles, daysToShow, client) {
// Loop thru the daysToShow and get the timestamp of the first day displayed
var beginningOfFirstDay = null;
var endOfLastDay = null;
- daysToShow.forEach(function (day) {
+ daysToShow.forEach(function(day) {
var dayStart = moment(day).startOf('day');
var dayEnd = moment(day).endOf('day');
if (!beginningOfFirstDay || dayStart < beginningOfFirstDay)
@@ -719,16 +725,17 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
// these on ascending startDate (create a clone array so we don't modify the Store array). And only save the profiles
// that have basal, carbratio, or sens.
var profilesArray1 = [];
- datastoreProfiles.forEach(function (entry) {
+ datastoreProfiles.forEach(function(entry) {
var newEntry = {};
newEntry.startDate = entry.startDate;
- var store=entry.store;
+ var store = entry.store;
if (store) {
- for(var key in store){
+ for (var key in store) {
if (laDebug) console.log('profile ' + key);
- if (store.hasOwnProperty(key)){
- var defaultProfile=store[key];
- newEntry.profileName=key;
+ // eslint-disable-next-line no-prototype-builtins
+ if (store.hasOwnProperty(key)) {
+ var defaultProfile = store[key];
+ newEntry.profileName = key;
if (defaultProfile.basal) newEntry.basal = defaultProfile.basal;
if (defaultProfile.carbratio) newEntry.carbratio = defaultProfile.carbratio;
if (defaultProfile.sens) newEntry.sens = defaultProfile.sens;
@@ -738,9 +745,9 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
}
}
})
- profilesArray1.sort(function (a, b) { return (a.startDate > b.startDate ? 1 : -1) }); // Ascending
+ profilesArray1.sort(function(a, b) { return (a.startDate > b.startDate ? 1 : -1) }); // Ascending
if (laDebug) {
- profilesArray1.forEach(function (entry) {
+ profilesArray1.forEach(function(entry) {
console.log('profilesArray1 - ' + entry.startDate);
})
}
@@ -750,30 +757,30 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
var profilesArray2 = [];
var profileToCompareWith = profilesArray1[0];
profilesArray2.push(profileToCompareWith); // Push the first profile, which should always be included.
- profilesArray1.forEach(function (entry) {
+ profilesArray1.forEach(function(entry) {
if (laDebug) {
console.log('Comparing ' + JSON.stringify(profileToCompareWith.startDate) + ' to ' + JSON.stringify(entry.startDate));
console.log(profileToCompareWith, entry);
}
- if (!loopalyzer.isSameProfileValues(profileToCompareWith, entry)) {
+ if (!loopalyzer.isSameProfileValues(profileToCompareWith, entry)) {
profilesArray2.push(entry);
profileToCompareWith = entry;
- if (laDebug)
+ if (laDebug)
console.log('ADDING IT');
} else {
// Do NOT push the entry to profilesArray2, and keep comparing with the same (olders unique) profile
- if (laDebug)
+ if (laDebug)
console.log('SKIPPING IT');
}
})
if (laDebug) console.log('profilesArray2 has ' + profilesArray2.length + ' profiles');
// Sort the newest Profile first
- profilesArray2.sort(function (a, b) { return (a.startDate > b.startDate ? 1 : -1) }); // Ascending
+ profilesArray2.sort(function(a, b) { return (a.startDate > b.startDate ? 1 : -1) }); // Ascending
// Third, find the latest profile with a startDate before beginningOfFirstDay
var latestProfile = profilesArray2[0]; // This is the oldest one
- profilesArray2.forEach(function (entry) {
+ profilesArray2.forEach(function(entry) {
if (laDebug)
console.log(entry.startDate + ' isBefore ' + beginningOfFirstDay + ' = ' + moment(entry.startDate).isBefore(beginningOfFirstDay));
if (moment(entry.startDate).isBefore(beginningOfFirstDay))
@@ -785,7 +792,7 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
// the other profiles with a startDate between beginningOfFirstDay and endOfLastDay
var profiles = [];
profiles.push(latestProfile); // Add the latest one
- profilesArray2.forEach(function (entry) {
+ profilesArray2.forEach(function(entry) {
if (laDebug)
console.log(entry.startDate + ' isAfter ' + beginningOfFirstDay + ' = ' + moment(entry.startDate).isAfter(beginningOfFirstDay));
if (moment(entry.startDate).isAfter(beginningOfFirstDay))
@@ -794,7 +801,7 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
// Now we have an array of all the profiles that are relevant for the days we are displaying.
if (laDebug) {
- profiles.forEach(function (entry) {
+ profiles.forEach(function(entry) {
console.log('profiles - ' + entry.startDate);
})
}
@@ -803,7 +810,7 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
var translate = client.translate;
var tableHtml = '
';
@@ -814,7 +821,7 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
// Add Basal as a table in the first td
tableHtml += '
'
});
}
@@ -823,7 +830,7 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
// Add Carb Ratio as a table in the second td
tableHtml += '
'
});
}
@@ -832,7 +839,7 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
// Add Sensitivity as a table in the third td
tableHtml += '
'
});
}
@@ -841,8 +848,8 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
// Close theProfile table
tableHtml += '
';
- } else
- if (index == 3) {
+ } else
+ if (index == 3) {
// Add ellipsis if too many profiles to display, but only one ellipsis even if there are more profiles
tableHtml += '
.....
';
}
@@ -857,16 +864,16 @@ loopalyzer.renderProfilesTable = function (datastoreProfiles, daysToShow, client
};
// Main method
-loopalyzer.report = function(datastorage,sorteddaystoshow,options) {
+loopalyzer.report = function(datastorage, sorteddaystoshow, options) {
if (laDebug) console.log('Loopalyzer ' + laVersion);
// Copy the sorteddaystoshow into new array (clone) and re-sort ascending (so we don't mess with original array)
var daysToShow = [];
- sorteddaystoshow.forEach(function(day){daysToShow.push(day)});
- daysToShow.sort(function(a,b) { return (a1) dateInfo += ' - ' + moment(daysToShow[daysToShow.length-1]).format('ddd MMM D'); // .split(',')[0];
+ if (daysToShow.length > 1) dateInfo += ' - ' + moment(daysToShow[daysToShow.length - 1]).format('ddd MMM D'); // .split(',')[0];
$("#loopalyzer-dateinfo").html(dateInfo);
loopalyzer.prepareHtml();
$("#loopalyzer-buttons").show();
- if (daysToShow.length==1) {
+ if (daysToShow.length == 1) {
// Disable and gray out timeShift if only a single day
$("#rp_loopalyzertimeshift").prop('checked', false);
$("#rp_loopalyzertimeshift").attr("disabled", true);
@@ -925,23 +931,23 @@ loopalyzer.generateReport = function(datastorage,daysToShow,options) {
if ($("#rp_loopalyzerprofiles").is(":checked") && (datastorage.profiles && datastorage.profiles.length > 0)) {
$("#loopalyzer-profiles-table").show();
loopalyzer.renderProfilesTable(datastorage.profiles, daysToShow, client);
- } else
+ } else
$("#loopalyzer-profiles-table").hide();
// Pull all necessary treatment information
profile.updateTreatments(datastorage.profileSwitchTreatments, datastorage.tempbasalTreatments, datastorage.combobolusTreatments);
- var carbTreatments = loopalyzer.getCarbTreatments(datastorage,daysToShow);
- var insulinTreatments = loopalyzer.getInsulinTreatments(datastorage,daysToShow);
- var sgvBin = loopalyzer.getSGVs(datastorage,daysToShow);
- var basalsBin = loopalyzer.getBasals(datastorage,daysToShow,profile);
- var tempBasalsBin = loopalyzer.getTempBasalDeltas(datastorage,daysToShow,profile);
- var iobBin = loopalyzer.getIOBs(datastorage,daysToShow, profile, client, insulinTreatments);
- var cobBin = loopalyzer.getCOBs(datastorage,daysToShow, profile, client, carbTreatments);
+ var carbTreatments = loopalyzer.getCarbTreatments(datastorage, daysToShow);
+ var insulinTreatments = loopalyzer.getInsulinTreatments(datastorage, daysToShow);
+ var sgvBin = loopalyzer.getSGVs(datastorage, daysToShow);
+ var basalsBin = loopalyzer.getBasals(datastorage, daysToShow, profile);
+ var tempBasalsBin = loopalyzer.getTempBasalDeltas(datastorage, daysToShow, profile);
+ var iobBin = loopalyzer.getIOBs(datastorage, daysToShow, profile, client, insulinTreatments);
+ var cobBin = loopalyzer.getCOBs(datastorage, daysToShow, profile, client, carbTreatments);
var predictionsBin = [];
if ($("#rp_loopalyzerpredictions").is(":checked")) {
- predictionsBin = loopalyzer.getPredictions(datastorage,daysToShow,client);
+ predictionsBin = loopalyzer.getPredictions(datastorage, daysToShow, client);
}
// Prepare an array with the minutes to timeShift each day (0 as default since timeShift is off by default)
@@ -950,76 +956,80 @@ loopalyzer.generateReport = function(datastorage,daysToShow,options) {
var timeShiftStartTime = null; // If timeShifting this is the average time the meals were eaten
var timeShiftStopTime = null; // and this is the start + DIA according to profile
var doTimeShift = false;
- daysToShow.forEach(function(){ timeShifts.push(0); firstCarbs.push(NaN) });
+ daysToShow.forEach(function() { timeShifts.push(0);
+ firstCarbs.push(NaN) });
// Check to see if we are doing timeShift or not
- if ($("#rp_loopalyzertimeshift").is(":checked") && daysToShow.length>1) {
+ if ($("#rp_loopalyzertimeshift").is(":checked") && daysToShow.length > 1) {
var mealMinCarbs = $("#rp_loopalyzermincarbs").val();
var t1 = $("#rp_loopalyzert1").val();
var t2 = $("#rp_loopalyzert2").val();
- if (t2>t1) {
+ if (t2 > t1) {
var h1 = t1.split(':')[0];
var m1 = t1.split(':')[1];
var h2 = t2.split(':')[0];
var m2 = t2.split(':')[1];
-
+
var timeShiftBegin = moment();
- timeShiftBegin.set({'hours':h1, 'minutes':m1, 'seconds':0});
-
+ timeShiftBegin.set({ 'hours': h1, 'minutes': m1, 'seconds': 0 });
+
var timeShiftEnd = moment();
- timeShiftEnd.set({'hours':h2, 'minutes':m2, 'seconds':0});
-
+ timeShiftEnd.set({ 'hours': h2, 'minutes': m2, 'seconds': 0 });
+
//Loop through the carb treatments and find the first meal each day
- daysToShow.forEach(function(day, dayIndex){
+ daysToShow.forEach(function(day, dayIndex) {
var timeShiftBegin = moment(day);
var timeShiftEnd = moment(day);
- timeShiftBegin.set({'hours':h1, 'minutes':m1, 'seconds':0});
- timeShiftEnd.set({'hours':h2, 'minutes':m2, 'seconds':0});
-
+ timeShiftBegin.set({ 'hours': h1, 'minutes': m1, 'seconds': 0 });
+ timeShiftEnd.set({ 'hours': h2, 'minutes': m2, 'seconds': 0 });
+
var found = false;
- carbTreatments.forEach(function(entry){
+ carbTreatments.forEach(function(entry) {
if (!found && entry.amount >= mealMinCarbs) {
var date = moment(entry.date);
- if ( (date.isSame(timeShiftBegin,'minute') || date.isAfter(timeShiftBegin,'minute')) &&
- (date.isSame(timeShiftEnd,'minute') || date.isBefore(timeShiftEnd,'minute')) ) {
- var startOfDay = moment(entry.date);
- startOfDay.set({'hours':0, 'minutes':0, 'seconds':0});
- var minutesAfterMidnight = date.diff(startOfDay, 'minutes');
- firstCarbs[dayIndex]=minutesAfterMidnight;
- found = true;
- doTimeShift = true;
+ if ((date.isSame(timeShiftBegin, 'minute') || date.isAfter(timeShiftBegin, 'minute')) &&
+ (date.isSame(timeShiftEnd, 'minute') || date.isBefore(timeShiftEnd, 'minute'))) {
+ var startOfDay = moment(entry.date);
+ startOfDay.set({ 'hours': 0, 'minutes': 0, 'seconds': 0 });
+ var minutesAfterMidnight = date.diff(startOfDay, 'minutes');
+ firstCarbs[dayIndex] = minutesAfterMidnight;
+ found = true;
+ doTimeShift = true;
}
}
})
})
-
+
// Calculate the average starting time, in minutes after midnight
- var averageMinutesAfterMidnight = 0, sum = 0, count = 0;
- firstCarbs.forEach(function(minutesAfterMidnight){
+ var sum = 0
+ , count = 0;
+
+ firstCarbs.forEach(function(minutesAfterMidnight) {
if (minutesAfterMidnight) { // Avoid NaN
sum += minutesAfterMidnight;
count++;
}
});
+
var averageMinutesAfterMidnight = Math.round(sum / count);
-
+
var dia = profile.getDIA();
if (!dia || dia <= 0)
- dia=6; // Default to 6h if DIA not set in profile
+ dia = 6; // Default to 6h if DIA not set in profile
timeShiftStartTime = moment(todayJSON);
timeShiftStartTime.minutes(averageMinutesAfterMidnight);
timeShiftStopTime = moment(todayJSON);
- if (averageMinutesAfterMidnight + dia*60 < 24*60)
- timeShiftStopTime.minutes(averageMinutesAfterMidnight + dia*60); // If not beyond midnight, stop at end of DIA
+ if (averageMinutesAfterMidnight + dia * 60 < 24 * 60)
+ timeShiftStopTime.minutes(averageMinutesAfterMidnight + dia * 60); // If not beyond midnight, stop at end of DIA
else
- timeShiftStopTime.minutes(24*60-1); // If beyond midnight, stop at midnight
-
+ timeShiftStopTime.minutes(24 * 60 - 1); // If beyond midnight, stop at midnight
+
// Compute the timeShift (+ / -) that we should add to each entry (sgv, iob, carbs, etc) for each day
- firstCarbs.forEach(function(minutesAfterMidnight,index){
+ firstCarbs.forEach(function(minutesAfterMidnight, index) {
if (minutesAfterMidnight) { // Avoid NaN
var delta = Math.round(averageMinutesAfterMidnight - minutesAfterMidnight);
- timeShifts[index]=delta;
+ timeShifts[index] = delta;
}
});
@@ -1050,7 +1060,7 @@ loopalyzer.generateReport = function(datastorage,daysToShow,options) {
var low = options.targetLow;
// Set up the charts basics
- function tickFormatter(val,axis) {
+ function tickFormatter (val, axis) {
if (val <= axis.min) { return ''; }
if (val >= axis.max) { return ''; }
return val + '';
@@ -1068,200 +1078,195 @@ loopalyzer.generateReport = function(datastorage,daysToShow,options) {
var borderWidth = 1;
var labelWidth = 25;
var xaxisCfg = {
- mode: 'time',
- timezone: 'browser',
- timeformat: '%H:%M',
- tickColor: tickColor,
- tickSize: [1, "hour"],
- font: { size: 0 }
+ mode: 'time'
+ , timezone: 'browser'
+ , timeformat: '%H:%M'
+ , tickColor: tickColor
+ , tickSize: [1, "hour"]
+ , font: { size: 0 }
};
var hiddenAxis = {
- position: "right",
- show: true,
- labelWidth: 10,
- tickColor: "#FFFFFF",
- font: { size: 0}
+ position: "right"
+ , show: true
+ , labelWidth: 10
+ , tickColor: "#FFFFFF"
+ , font: { size: 0 }
}
// For drawing the carbs and insulin treatments
var markings = [];
var markingColor = "#000000";
-
// Chart 1: Basal
markings = [];
if (doTimeShift)
- markings.push( { xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate()}, color: timeShiftBackgroundColor } );
+ markings.push({ xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate() }, color: timeShiftBackgroundColor });
var chartBasalData = [{
- data: basalsAvg,
- label: translate('Basal profile'),
- id: 'basals',
- color: basalColor,
- points: { show: false },
- bars: { show: true, fill: true, barWidth: barWidth },
- yaxis: 1
+ data: basalsAvg
+ , label: translate('Basal profile')
+ , id: 'basals'
+ , color: basalColor
+ , points: { show: false }
+ , bars: { show: true, fill: true, barWidth: barWidth }
+ , yaxis: 1
}];
var chartBasalOptions = {
- xaxis: xaxisCfg,
- yaxes: [{
- tickColor: tickColor,
- labelWidth: labelWidth,
- tickFormatter: function(val,axis) { return tickFormatter(val,axis); }
- },
- hiddenAxis],
- grid: {
- borderWidth: borderWidth,
- markings: markings
+ xaxis: xaxisCfg
+ , yaxes: [{
+ tickColor: tickColor
+ , labelWidth: labelWidth
+ , tickFormatter: function(val, axis) { return tickFormatter(val, axis); }
+ }
+ , hiddenAxis]
+ , grid: {
+ borderWidth: borderWidth
+ , markings: markings
}
};
- $.plot( '#loopalyzer-basal', chartBasalData, chartBasalOptions );
-
+ $.plot('#loopalyzer-basal', chartBasalData, chartBasalOptions);
// Chart 2: Blood glucose
markings = [];
if (doTimeShift)
- markings.push( { xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate()}, color: timeShiftBackgroundColor } );
+ markings.push({ xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate() }, color: timeShiftBackgroundColor });
markings.push({ yaxis: { from: low, to: high }, color: glucoseRangeColor });
var chartBGData = [{
- label: translate('Blood glucose'),
- data: sgvAvg,
- id: 'glucose',
- color: glucoseColor,
- points: { show: false },
- lines: { show: true }
+ label: translate('Blood glucose')
+ , data: sgvAvg
+ , id: 'glucose'
+ , color: glucoseColor
+ , points: { show: false }
+ , lines: { show: true }
}];
- if (predictionsAvg && predictionsAvg.length>0) {
+ if (predictionsAvg && predictionsAvg.length > 0) {
chartBGData.push({
- label: translate('Predictions'),
- data: predictionsAvg,
- id: 'predictions',
- color: predictionsColor,
- points: { show: true, fill: true, radius: 0.75, fillColor: predictionsColor },
- lines: { show: false }
+ label: translate('Predictions')
+ , data: predictionsAvg
+ , id: 'predictions'
+ , color: predictionsColor
+ , points: { show: true, fill: true, radius: 0.75, fillColor: predictionsColor }
+ , lines: { show: false }
});
}
var chartBGOptions = {
- xaxis: xaxisCfg,
- yaxes: [{
- min: 0,
- max: options.units === 'mmol' ? 20 : 400,
- tickColor: tickColor,
- labelWidth: labelWidth,
- tickFormatter: function(val,axis) { return tickFormatter(val,axis); }
- },
- hiddenAxis],
- grid: {
- borderWidth: borderWidth,
- markings: markings
+ xaxis: xaxisCfg
+ , yaxes: [{
+ min: 0
+ , max: options.units === 'mmol' ? 20 : 400
+ , tickColor: tickColor
+ , labelWidth: labelWidth
+ , tickFormatter: function(val, axis) { return tickFormatter(val, axis); }
+ }
+ , hiddenAxis]
+ , grid: {
+ borderWidth: borderWidth
+ , markings: markings
}
};
- $.plot( '#loopalyzer-bg', chartBGData, chartBGOptions );
-
+ $.plot('#loopalyzer-bg', chartBGData, chartBGOptions);
// Chart 3: Delta temp basals
markings = [];
if (doTimeShift)
- markings.push( { xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate()}, color: timeShiftBackgroundColor } );
- markings.push( { yaxis: { from: 0, to: 0 }, color: insulinColor, lineWidth: 2 });
+ markings.push({ xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate() }, color: timeShiftBackgroundColor });
+ markings.push({ yaxis: { from: 0, to: 0 }, color: insulinColor, lineWidth: 2 });
var chartTempBasalData = [{
- data: tempBasalsAvg,
- label: translate('Temp basal delta'),
- id: 'tempBasals',
- color: insulinColor,
- points: { show: false },
- bars: { show: true, barWidth: barWidth }
+ data: tempBasalsAvg
+ , label: translate('Temp basal delta')
+ , id: 'tempBasals'
+ , color: insulinColor
+ , points: { show: false }
+ , bars: { show: true, barWidth: barWidth }
}];
var chartTempBasalOptions = {
- xaxis: xaxisCfg,
- yaxes: [{
- tickColor: tickColor,
- labelWidth: labelWidth,
- tickFormatter: function(val,axis) { return tickFormatter(val,axis); }
- },
- hiddenAxis],
- grid: {
- borderWidth: borderWidth,
- markings: markings
+ xaxis: xaxisCfg
+ , yaxes: [{
+ tickColor: tickColor
+ , labelWidth: labelWidth
+ , tickFormatter: function(val, axis) { return tickFormatter(val, axis); }
+ }
+ , hiddenAxis]
+ , grid: {
+ borderWidth: borderWidth
+ , markings: markings
}
};
- $.plot( '#loopalyzer-tempbasal', chartTempBasalData, chartTempBasalOptions );
-
+ $.plot('#loopalyzer-tempbasal', chartTempBasalData, chartTempBasalOptions);
// Chart 4: IOB
markings = [];
if (doTimeShift)
- markings.push( { xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate()}, color: timeShiftBackgroundColor } );
- insulinTreatments.forEach(function(treatment){
+ markings.push({ xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate() }, color: timeShiftBackgroundColor });
+ insulinTreatments.forEach(function(treatment) {
var startDate = moment(treatment.date);
var endDate = moment(treatment.date);
startDate.set(todayJSON);
endDate.set(todayJSON);
endDate.add(5, 'minutes');
- markings.push( { xaxis: { from: startDate.toDate(), to: endDate.toDate()}, yaxis: { from: 0, to: treatment.amount }, color: markingColor } );
+ markings.push({ xaxis: { from: startDate.toDate(), to: endDate.toDate() }, yaxis: { from: 0, to: treatment.amount }, color: markingColor });
})
var chartIOBData = [{
- data: iobAvg,
- label: translate('IOB'),
- id: 'iobs',
- color: insulinColor,
- points: { show: false },
- bars: { show: true, fill: true, barWidth: barWidth }
+ data: iobAvg
+ , label: translate('IOB')
+ , id: 'iobs'
+ , color: insulinColor
+ , points: { show: false }
+ , bars: { show: true, fill: true, barWidth: barWidth }
}];
var chartIOBOptions = {
- xaxis: xaxisCfg,
- yaxes: [{
- tickColor: tickColor,
- labelWidth: labelWidth,
- tickFormatter: function(val,axis) { return tickFormatter(val,axis); }
- },
- hiddenAxis],
- grid: {
- borderWidth: borderWidth,
- markings: markings
+ xaxis: xaxisCfg
+ , yaxes: [{
+ tickColor: tickColor
+ , labelWidth: labelWidth
+ , tickFormatter: function(val, axis) { return tickFormatter(val, axis); }
+ }
+ , hiddenAxis]
+ , grid: {
+ borderWidth: borderWidth
+ , markings: markings
}
};
- $.plot( '#loopalyzer-iob', chartIOBData, chartIOBOptions );
-
+ $.plot('#loopalyzer-iob', chartIOBData, chartIOBOptions);
// Chart 5: COB
markings = [];
if (doTimeShift)
- markings.push( { xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate()}, color: timeShiftBackgroundColor } );
- carbTreatments.forEach(function(treatment){
+ markings.push({ xaxis: { from: timeShiftStartTime.toDate(), to: timeShiftStopTime.toDate() }, color: timeShiftBackgroundColor });
+ carbTreatments.forEach(function(treatment) {
var startDate = moment(treatment.date);
var endDate = moment(treatment.date);
startDate.set(todayJSON);
endDate.set(todayJSON);
endDate.add(5, 'minutes');
- markings.push( { xaxis: { from: startDate.toDate(), to: endDate.toDate()}, yaxis: { from: 0, to: treatment.amount }, color: markingColor } );
+ markings.push({ xaxis: { from: startDate.toDate(), to: endDate.toDate() }, yaxis: { from: 0, to: treatment.amount }, color: markingColor });
})
delete xaxisCfg.font; // Remove the font config so HH:MM is shown on the last chart
var chartCOBData = [{
- data: cobAvg,
- label: translate('COB'),
- id: 'cobs',
- color: carbColor,
- points: { show: false },
- bars: { show: true, fil: true, barWidth: barWidth }
+ data: cobAvg
+ , label: translate('COB')
+ , id: 'cobs'
+ , color: carbColor
+ , points: { show: false }
+ , bars: { show: true, fil: true, barWidth: barWidth }
}];
var chartCOBOptions = {
- xaxis: xaxisCfg,
- yaxes: [{
- tickColor: tickColor,
- labelWidth: labelWidth,
- tickFormatter: function(val,axis) { return tickFormatter(val,axis); }
- },
- hiddenAxis],
- grid: {
- borderWidth: borderWidth,
- markings: markings
+ xaxis: xaxisCfg
+ , yaxes: [{
+ tickColor: tickColor
+ , labelWidth: labelWidth
+ , tickFormatter: function(val, axis) { return tickFormatter(val, axis); }
+ }
+ , hiddenAxis]
+ , grid: {
+ borderWidth: borderWidth
+ , markings: markings
}
};
- $.plot( '#loopalyzer-cob', chartCOBData, chartCOBOptions );
+ $.plot('#loopalyzer-cob', chartCOBData, chartCOBOptions);
};
diff --git a/lib/report_plugins/profiles.js b/lib/report_plugins/profiles.js
index c31b8b2f..58036789 100644
--- a/lib/report_plugins/profiles.js
+++ b/lib/report_plugins/profiles.js
@@ -6,33 +6,32 @@ var profiles = {
, pluginType: 'report'
};
-function init() {
+function init () {
return profiles;
}
module.exports = init;
-profiles.html = function html(client) {
+profiles.html = function html (client) {
var translate = client.translate;
var ret =
- '