mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
filter by hours in distribution
This commit is contained in:
@@ -21,12 +21,43 @@ glucosedistribution.html = function html(client) {
|
||||
+ ' <span id="glucosedistribution-days"></span>'
|
||||
+ ' )'
|
||||
+ ' </h2>'
|
||||
+ '<div id="glucosedistribution-overviewchart"></div>'
|
||||
+ '<div id="glucosedistribution-report"></div>'
|
||||
+ '<table><tr>'
|
||||
+ '<td><div id="glucosedistribution-overviewchart"></div></td>'
|
||||
+ '<td><div id="glucosedistribution-report"></div></td>'
|
||||
+ '</tr></table>'
|
||||
+ '<br/>'
|
||||
+ '<br/>'
|
||||
+ '* ' + translate('This is only a rough estimation that can be very inaccurate and does not replace actual blood testing. The formula used is taken from: Nathan, David M., et al. "Translating the A1C assay into estimated average glucose values." <i>Diabetes care</i> 31.8 (2008): 1473-1478.')
|
||||
;
|
||||
+ '<br/>'
|
||||
+ '<br/>'
|
||||
+ translate('Filter by hours') + ':'
|
||||
+ '<br/>'
|
||||
+ '0<input type="checkbox" id="glucosedistribution-0" checked>'
|
||||
+ '1<input type="checkbox" id="glucosedistribution-1" checked>'
|
||||
+ '2<input type="checkbox" id="glucosedistribution-2" checked>'
|
||||
+ '3<input type="checkbox" id="glucosedistribution-3" checked>'
|
||||
+ '4<input type="checkbox" id="glucosedistribution-4" checked>'
|
||||
+ '5<input type="checkbox" id="glucosedistribution-5" checked>'
|
||||
+ '6<input type="checkbox" id="glucosedistribution-6" checked>'
|
||||
+ '7<input type="checkbox" id="glucosedistribution-7" checked>'
|
||||
+ '8<input type="checkbox" id="glucosedistribution-8" checked>'
|
||||
+ '9<input type="checkbox" id="glucosedistribution-9" checked>'
|
||||
+ '10<input type="checkbox" id="glucosedistribution-10" checked>'
|
||||
+ '11<input type="checkbox" id="glucosedistribution-11" checked>'
|
||||
+ '12<input type="checkbox" id="glucosedistribution-12" checked>'
|
||||
+ '13<input type="checkbox" id="glucosedistribution-13" checked>'
|
||||
+ '14<input type="checkbox" id="glucosedistribution-14" checked>'
|
||||
+ '15<input type="checkbox" id="glucosedistribution-15" checked>'
|
||||
+ '16<input type="checkbox" id="glucosedistribution-16" checked>'
|
||||
+ '17<input type="checkbox" id="glucosedistribution-17" checked>'
|
||||
+ '18<input type="checkbox" id="glucosedistribution-18" checked>'
|
||||
+ '19<input type="checkbox" id="glucosedistribution-19" checked>'
|
||||
+ '20<input type="checkbox" id="glucosedistribution-20" checked>'
|
||||
+ '21<input type="checkbox" id="glucosedistribution-21" checked>'
|
||||
+ '22<input type="checkbox" id="glucosedistribution-22" checked>'
|
||||
+ '23<input type="checkbox" id="glucosedistribution-23" checked>'
|
||||
|
||||
;
|
||||
return ret;
|
||||
};
|
||||
|
||||
@@ -34,7 +65,6 @@ glucosedistribution.css =
|
||||
'#glucosedistribution-overviewchart {'
|
||||
+ ' width: 2.4in;'
|
||||
+ ' height: 2.4in;'
|
||||
+ ' float:left;'
|
||||
+ '}'
|
||||
+ '#glucosedistribution-placeholder .tdborder {'
|
||||
+ ' width:80px;'
|
||||
@@ -56,6 +86,8 @@ glucosedistribution.report = function report_glucosedistribution(datastorage,sor
|
||||
|
||||
var colors = ['#f88', '#8f8', '#ff8'];
|
||||
var tablecolors = { Low:'#f88', Normal: '#8f8', High: '#ff8' };
|
||||
|
||||
var enabledHours = [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true];
|
||||
|
||||
var report = $('#glucosedistribution-report');
|
||||
report.empty();
|
||||
@@ -75,13 +107,21 @@ glucosedistribution.report = function report_glucosedistribution(datastorage,sor
|
||||
var days = datastorage.alldays;
|
||||
|
||||
$('#glucosedistribution-days').text(days+' '+translate('days total'));
|
||||
|
||||
|
||||
for (var i = 0; i < 23; i++) {
|
||||
$('#glucosedistribution-' + i).unbind('click').click(onClick);
|
||||
enabledHours[i] = $('#glucosedistribution-' + i).is(':checked');
|
||||
}
|
||||
console.log(enabledHours);
|
||||
|
||||
var result = { };
|
||||
|
||||
var hourlyFilteredData = data.filter(function(r) { return enabledHours[new Date(r.displayTime).getHours()] });
|
||||
|
||||
['Low', 'Normal', 'High'].forEach(function(range) {
|
||||
result[range] = { };
|
||||
var r = result[range];
|
||||
r.rangeRecords = data.filter(function(r) {
|
||||
r.rangeRecords = hourlyFilteredData.filter(function(r) {
|
||||
if (range === 'Low') {
|
||||
return r.sgv > 0 && r.sgv < options.targetLow;
|
||||
} else if (range === 'Normal') {
|
||||
@@ -96,7 +136,7 @@ glucosedistribution.report = function report_glucosedistribution(datastorage,sor
|
||||
});
|
||||
r.localBgs = r.rangeRecords.map(function(r) { return r.sgv; }).filter(function(bg) { return !!bg; });
|
||||
r.midpoint = Math.floor(r.rangeRecords.length / 2);
|
||||
r.readingspct = Math.floor(100 * r.rangeRecords.length / data.length);
|
||||
r.readingspct = Math.floor(100 * r.rangeRecords.length / hourlyFilteredData.length);
|
||||
if (r.rangeRecords.length > 0) {
|
||||
r.mean = Math.floor(10*ss.mean(r.localBgs))/10;
|
||||
r.median = r.rangeRecords[r.midpoint].sgv;
|
||||
@@ -128,14 +168,14 @@ glucosedistribution.report = function report_glucosedistribution(datastorage,sor
|
||||
|
||||
table.append(tr);
|
||||
});
|
||||
|
||||
|
||||
var tr = $('<tr>');
|
||||
$('<td class="tdborder"><strong>'+translate('Overall')+': </strong></td>').appendTo(tr);
|
||||
$('<td> </td>').appendTo(tr);
|
||||
$('<td class="tdborder">' + data.length + '</td>').appendTo(tr);
|
||||
if (data.length > 0) {
|
||||
var localBgs = data.map(function(r) { return r.sgv; }).filter(function(bg) { return !!bg; });
|
||||
var mgDlBgs = data.map(function(r) { return r.bgValue; }).filter(function(bg) { return !!bg; });
|
||||
$('<td class="tdborder">' + hourlyFilteredData.length + '</td>').appendTo(tr);
|
||||
if (hourlyFilteredData.length > 0) {
|
||||
var localBgs = hourlyFilteredData.map(function(r) { return r.sgv; }).filter(function(bg) { return !!bg; });
|
||||
var mgDlBgs = hourlyFilteredData.map(function(r) { return r.bgValue; }).filter(function(bg) { return !!bg; });
|
||||
$('<td class="tdborder">' + (Math.round(10*ss.mean(localBgs))/10).toFixed(1) + '</td>').appendTo(tr);
|
||||
$('<td class="tdborder">' + (Math.round(10*ss.quantile(localBgs, 0.5))/10).toFixed(1) + '</td>').appendTo(tr);
|
||||
$('<td class="tdborder">' + (Math.round(ss.standard_deviation(localBgs)*10)/10).toFixed(1) + '</td>').appendTo(tr);
|
||||
@@ -163,4 +203,9 @@ glucosedistribution.report = function report_glucosedistribution(datastorage,sor
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
function onClick() {
|
||||
report_glucosedistribution(datastorage,sorteddaystoshow,options);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user