From 0541e2a801aac9fb685b84a465daacbd87c63ff4 Mon Sep 17 00:00:00 2001 From: Ben West Date: Sat, 14 Jan 2023 17:49:52 -0800 Subject: [PATCH 01/11] daytoday reports are always in the profile's time zone Midnight for the profile should always be at the start of the day (midnight) for the chart. --- lib/report_plugins/daytoday.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index 49aad99ed16..c4518b21fc7 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -432,8 +432,8 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio contextCircles.exit() .remove(); - var to = moment(day).add(1, 'days'); - var from = moment(day); + var from = moment.tz(day, profile.getTimezone( )); + var to = moment(from).add(1, 'days'); var iobpolyline = '' , cobpolyline = ''; From a47b3675a460580ef9bef8c541da44aea09107ba Mon Sep 17 00:00:00 2001 From: Ben West Date: Sun, 15 Jan 2023 09:59:44 -0800 Subject: [PATCH 02/11] pin start of day in profile's timezone This more closely mirrors logic in loopalyzer, as well as the intent from the surrounding code in reportclient.js. --- lib/report_plugins/daytoday.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index c4518b21fc7..1bcaeea46a0 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -432,8 +432,8 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio contextCircles.exit() .remove(); - var from = moment.tz(day, profile.getTimezone( )); - var to = moment(from).add(1, 'days'); + var from = moment.tz(day, profile.getTimezone( )).startOf('day'); + var to = moment(from.clone( )).add(1, 'days'); var iobpolyline = '' , cobpolyline = ''; From 0330e13e3354f448c6456f22f0693179000ee1d4 Mon Sep 17 00:00:00 2001 From: Ben West Date: Mon, 23 Jan 2023 08:23:04 -0800 Subject: [PATCH 03/11] ensure timezones assigned once in daily reports This fixes the label on the days in the daytoday charts. Passing a moment object that is already zoned prevents toLocaleDateString from reinterpreting the zone information when the date is already relative to the profile. This also ensures that the datefilter is adjusted to the profile's zone rather than truncating the time to the end or beginning of the day. This should prevent incorrectly wrapping arounnd the dateline. --- lib/report/reportclient.js | 4 ++++ lib/report_plugins/daytoday.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index cb294640fe9..151e9eb2f28 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -261,6 +261,10 @@ var init = function init () { var from = moment.tz($('#rp_from').val().replace(/\//g, '-') + 'T00:00:00', zone); var to = moment.tz($('#rp_to').val().replace(/\//g, '-') + 'T23:59:59', zone); timerange = '&find[created_at][$gte]=' + from.toISOString() + '&find[created_at][$lt]=' + to.toISOString(); + + console.log('DATEFILTER', zone, timerange); + console.log("DATEFILTER", "FROM", from.format( ), moment.tz(moment($('#rp_from').val()).startOf('day'), zone).format( ) ); + console.log("DATEFILTER", "TO", to.format( ), moment.tz(moment($('#rp_to').val()).startOf('day'), zone).format( ) ); //console.log($('#rp_from').val(),$('#rp_to').val(),zone,timerange); while (from <= to) { if (daystoshow[from.format('YYYY-MM-DD')]) { diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index 1bcaeea46a0..f1bee57ca09 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -168,7 +168,7 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio // create svg and g to contain the chart contents charts = d3.select('#daytodaychart-' + day).html( '' + - report_plugins.utils.localeDate(day) + + report_plugins.utils.localeDate(moment(day)) + '
' ).append('svg'); From 8983713b741d0b65e16426256246c2884fe6e330 Mon Sep 17 00:00:00 2001 From: Ben West Date: Mon, 23 Jan 2023 08:30:50 -0800 Subject: [PATCH 04/11] ensure daily reports dates translate to profile timezone To illustrate the difference, I used chrome "sensors" feature to change my timezone to one that spans the dateline. > moment.tz('2023-01-19', 'America/Los_Angeles').endOf('day').format( ) '2023-01-19T23:59:59-08:00' > moment.tz(moment('2023-01-19'), 'America/Los_Angeles').endOf('day').format( ) '2023-01-18T23:59:59-08:00' The old code uses a string replacement, which is equivalent to the first test. This causes the dates on the reports to be off by one, as well as risks the data wrapping around the dateline so it can't be seen. For example, replacing "23:59:59" with "00:00:00" in the first example doesn't correctly wrap around the dateline. The patch introduces a way to parse the dates requested in the browser's time zone, and then translates them to the profile's timezone. The difference is shown in the second example above. With this change, the correct date label should be rendered, and the data should start at midnight without wrapping around the dateline. --- lib/report/reportclient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index 151e9eb2f28..669080de526 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -264,7 +264,7 @@ var init = function init () { console.log('DATEFILTER', zone, timerange); console.log("DATEFILTER", "FROM", from.format( ), moment.tz(moment($('#rp_from').val()).startOf('day'), zone).format( ) ); - console.log("DATEFILTER", "TO", to.format( ), moment.tz(moment($('#rp_to').val()).startOf('day'), zone).format( ) ); + console.log("DATEFILTER", "TO", to.format( ), moment.tz(moment($('#rp_to').val()).startOf('day'), zone).endOf('day').format( ) ); //console.log($('#rp_from').val(),$('#rp_to').val(),zone,timerange); while (from <= to) { if (daystoshow[from.format('YYYY-MM-DD')]) { From f51fac96230a885b543a75a123502c4ce2bf83c9 Mon Sep 17 00:00:00 2001 From: Ben West Date: Mon, 23 Jan 2023 08:45:10 -0800 Subject: [PATCH 05/11] clock at the end of the day is 23:59:59.999 Ensure that the test fixtures will return; the previous changes correctly forward the time to end of day across zones and datelines. One side effect is that the date formatted for the end of the day uses all the microseconds for the day as well. This changes the query from the form of 23:59:59.000Z to 23:59:59.999Z. This also ensures that anything that happens during that one second will be included rather than excluded. --- lib/report/reportclient.js | 4 ++-- tests/reports.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index 669080de526..1ed76a6b524 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -258,8 +258,8 @@ var init = function init () { function datefilter () { if ($('#rp_enabledate').is(':checked')) { matchesneeded++; - var from = moment.tz($('#rp_from').val().replace(/\//g, '-') + 'T00:00:00', zone); - var to = moment.tz($('#rp_to').val().replace(/\//g, '-') + 'T23:59:59', zone); + var from = moment.tz(moment($('#rp_from').val()).startOf('day'), zone).startOf('day'); + var to = moment.tz(moment($('#rp_to').val()).startOf('day'), zone).endOf('day'); timerange = '&find[created_at][$gte]=' + from.toISOString() + '&find[created_at][$lt]=' + to.toISOString(); console.log('DATEFILTER', zone, timerange); diff --git a/tests/reports.test.js b/tests/reports.test.js index 947eb5e5b03..3ff2f882334 100644 --- a/tests/reports.test.js +++ b/tests/reports.test.js @@ -30,7 +30,7 @@ var someData = { '/api/v1/treatments.json?find[created_at][$gte]=2015-08-14T00:00:00.000Z&find[created_at][$lt]=2015-08-15T00:00:00.000Z&count=1000': [{'enteredBy':'Dad','eventType':'Site Change','glucose':268,'glucoseType':'Finger','insulin':1.75,'units':'mg/dl','created_at':'2015-08-14T00:00:00.000Z','_id':'55ce78fe925aa80e7071e5d6'},{'enteredBy':'Mom ','eventType':'Meal Bolus','glucose':89,'glucoseType':'Finger','carbs':54,'insulin':3.15,'units':'mg/dl','created_at':'2015-08-14T21:00:00.000Z','_id':'55ce59bb925aa80e7071e5ba'}], '/api/v1/entries.json?find[date][$gte]=1439596800000&find[date][$lt]=1439683200000&count=10000': [{'_id':'55cfd25f38a8d88ad1b49931','unfiltered':283136,'filtered':304768,'direction':'SingleDown','device':'dexcom','rssi':185,'sgv':306,'dateString':'Sat Aug 15 16:58:16 PDT 2015','type':'sgv','date':1439683096000,'noise':1},{'_id':'55cfd13338a8d88ad1b4992e','unfiltered':302528,'filtered':312576,'direction':'FortyFiveDown','device':'dexcom','rssi':179,'sgv':329,'dateString':'Sat Aug 15 16:53:16 PDT 2015','type':'sgv','date':1439682796000,'noise':1}], '/api/v1/food/regular.json': [{'_id':'552ece84a6947ea011db35bb','type':'food','category':'Zakladni','subcategory':'Sladkosti','name':'Bebe male','portion':18,'carbs':12,'gi':1,'unit':'pcs','created_at':'2015-04-15T20:48:04.966Z'}], - '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z': [ + '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -63,7 +63,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z': [ + '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -96,7 +96,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z?find[openaps][$exists]=true&count=1000': [ + '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z?find[openaps][$exists]=true&count=1000': [ { 'openaps': { 'suggested': { From 0ee0712ca777ce06528562e0f3a231dfc46823f0 Mon Sep 17 00:00:00 2001 From: Ben West Date: Tue, 24 Jan 2023 10:59:40 -0800 Subject: [PATCH 06/11] redact console log lines --- lib/report/reportclient.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index 1ed76a6b524..0ecdf2dc2da 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -262,9 +262,6 @@ var init = function init () { var to = moment.tz(moment($('#rp_to').val()).startOf('day'), zone).endOf('day'); timerange = '&find[created_at][$gte]=' + from.toISOString() + '&find[created_at][$lt]=' + to.toISOString(); - console.log('DATEFILTER', zone, timerange); - console.log("DATEFILTER", "FROM", from.format( ), moment.tz(moment($('#rp_from').val()).startOf('day'), zone).format( ) ); - console.log("DATEFILTER", "TO", to.format( ), moment.tz(moment($('#rp_to').val()).startOf('day'), zone).endOf('day').format( ) ); //console.log($('#rp_from').val(),$('#rp_to').val(),zone,timerange); while (from <= to) { if (daystoshow[from.format('YYYY-MM-DD')]) { From a4f92713c4f9301392f51c675aa4a4433de48a35 Mon Sep 17 00:00:00 2001 From: Ben West Date: Thu, 26 Jan 2023 11:42:36 -0800 Subject: [PATCH 07/11] Revert "clock at the end of the day is 23:59:59.999" This reverts commit f51fac96230a885b543a75a123502c4ce2bf83c9. --- lib/report/reportclient.js | 4 ++-- tests/reports.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index 0ecdf2dc2da..f7da4d1f5f0 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -258,8 +258,8 @@ var init = function init () { function datefilter () { if ($('#rp_enabledate').is(':checked')) { matchesneeded++; - var from = moment.tz(moment($('#rp_from').val()).startOf('day'), zone).startOf('day'); - var to = moment.tz(moment($('#rp_to').val()).startOf('day'), zone).endOf('day'); + var from = moment.tz($('#rp_from').val().replace(/\//g, '-') + 'T00:00:00', zone); + var to = moment.tz($('#rp_to').val().replace(/\//g, '-') + 'T23:59:59', zone); timerange = '&find[created_at][$gte]=' + from.toISOString() + '&find[created_at][$lt]=' + to.toISOString(); //console.log($('#rp_from').val(),$('#rp_to').val(),zone,timerange); diff --git a/tests/reports.test.js b/tests/reports.test.js index 3ff2f882334..947eb5e5b03 100644 --- a/tests/reports.test.js +++ b/tests/reports.test.js @@ -30,7 +30,7 @@ var someData = { '/api/v1/treatments.json?find[created_at][$gte]=2015-08-14T00:00:00.000Z&find[created_at][$lt]=2015-08-15T00:00:00.000Z&count=1000': [{'enteredBy':'Dad','eventType':'Site Change','glucose':268,'glucoseType':'Finger','insulin':1.75,'units':'mg/dl','created_at':'2015-08-14T00:00:00.000Z','_id':'55ce78fe925aa80e7071e5d6'},{'enteredBy':'Mom ','eventType':'Meal Bolus','glucose':89,'glucoseType':'Finger','carbs':54,'insulin':3.15,'units':'mg/dl','created_at':'2015-08-14T21:00:00.000Z','_id':'55ce59bb925aa80e7071e5ba'}], '/api/v1/entries.json?find[date][$gte]=1439596800000&find[date][$lt]=1439683200000&count=10000': [{'_id':'55cfd25f38a8d88ad1b49931','unfiltered':283136,'filtered':304768,'direction':'SingleDown','device':'dexcom','rssi':185,'sgv':306,'dateString':'Sat Aug 15 16:58:16 PDT 2015','type':'sgv','date':1439683096000,'noise':1},{'_id':'55cfd13338a8d88ad1b4992e','unfiltered':302528,'filtered':312576,'direction':'FortyFiveDown','device':'dexcom','rssi':179,'sgv':329,'dateString':'Sat Aug 15 16:53:16 PDT 2015','type':'sgv','date':1439682796000,'noise':1}], '/api/v1/food/regular.json': [{'_id':'552ece84a6947ea011db35bb','type':'food','category':'Zakladni','subcategory':'Sladkosti','name':'Bebe male','portion':18,'carbs':12,'gi':1,'unit':'pcs','created_at':'2015-04-15T20:48:04.966Z'}], - '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ + '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -63,7 +63,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ + '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -96,7 +96,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z?find[openaps][$exists]=true&count=1000': [ + '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z?find[openaps][$exists]=true&count=1000': [ { 'openaps': { 'suggested': { From f6b2d4f717d434655fd7051cc4d9416f983be0a9 Mon Sep 17 00:00:00 2001 From: Ben West Date: Thu, 26 Jan 2023 11:43:43 -0800 Subject: [PATCH 08/11] Revert "Revert "clock at the end of the day is 23:59:59.999"" This reverts commit a4f92713c4f9301392f51c675aa4a4433de48a35. --- lib/report/reportclient.js | 4 ++-- tests/reports.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index f7da4d1f5f0..0ecdf2dc2da 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -258,8 +258,8 @@ var init = function init () { function datefilter () { if ($('#rp_enabledate').is(':checked')) { matchesneeded++; - var from = moment.tz($('#rp_from').val().replace(/\//g, '-') + 'T00:00:00', zone); - var to = moment.tz($('#rp_to').val().replace(/\//g, '-') + 'T23:59:59', zone); + var from = moment.tz(moment($('#rp_from').val()).startOf('day'), zone).startOf('day'); + var to = moment.tz(moment($('#rp_to').val()).startOf('day'), zone).endOf('day'); timerange = '&find[created_at][$gte]=' + from.toISOString() + '&find[created_at][$lt]=' + to.toISOString(); //console.log($('#rp_from').val(),$('#rp_to').val(),zone,timerange); diff --git a/tests/reports.test.js b/tests/reports.test.js index 947eb5e5b03..3ff2f882334 100644 --- a/tests/reports.test.js +++ b/tests/reports.test.js @@ -30,7 +30,7 @@ var someData = { '/api/v1/treatments.json?find[created_at][$gte]=2015-08-14T00:00:00.000Z&find[created_at][$lt]=2015-08-15T00:00:00.000Z&count=1000': [{'enteredBy':'Dad','eventType':'Site Change','glucose':268,'glucoseType':'Finger','insulin':1.75,'units':'mg/dl','created_at':'2015-08-14T00:00:00.000Z','_id':'55ce78fe925aa80e7071e5d6'},{'enteredBy':'Mom ','eventType':'Meal Bolus','glucose':89,'glucoseType':'Finger','carbs':54,'insulin':3.15,'units':'mg/dl','created_at':'2015-08-14T21:00:00.000Z','_id':'55ce59bb925aa80e7071e5ba'}], '/api/v1/entries.json?find[date][$gte]=1439596800000&find[date][$lt]=1439683200000&count=10000': [{'_id':'55cfd25f38a8d88ad1b49931','unfiltered':283136,'filtered':304768,'direction':'SingleDown','device':'dexcom','rssi':185,'sgv':306,'dateString':'Sat Aug 15 16:58:16 PDT 2015','type':'sgv','date':1439683096000,'noise':1},{'_id':'55cfd13338a8d88ad1b4992e','unfiltered':302528,'filtered':312576,'direction':'FortyFiveDown','device':'dexcom','rssi':179,'sgv':329,'dateString':'Sat Aug 15 16:53:16 PDT 2015','type':'sgv','date':1439682796000,'noise':1}], '/api/v1/food/regular.json': [{'_id':'552ece84a6947ea011db35bb','type':'food','category':'Zakladni','subcategory':'Sladkosti','name':'Bebe male','portion':18,'carbs':12,'gi':1,'unit':'pcs','created_at':'2015-04-15T20:48:04.966Z'}], - '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z': [ + '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -63,7 +63,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z': [ + '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -96,7 +96,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.000Z?find[openaps][$exists]=true&count=1000': [ + '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z?find[openaps][$exists]=true&count=1000': [ { 'openaps': { 'suggested': { From 10dd236cda32102534605183705f3bdc6e1b5cbf Mon Sep 17 00:00:00 2001 From: Ben West Date: Thu, 26 Jan 2023 12:52:32 -0800 Subject: [PATCH 09/11] daytoday: Align start of day with data across zones This change correctly aligns the name of the day in the current zone with the start of the data for the equivalent day in the profile's zone. This makes it so that viewing a day to day report in any timezone works going both east and west directions. --- lib/report/reportclient.js | 3 ++- lib/report_plugins/daytoday.js | 2 +- tests/reports.test.js | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index 0ecdf2dc2da..9b918d6fb84 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -259,9 +259,10 @@ var init = function init () { if ($('#rp_enabledate').is(':checked')) { matchesneeded++; var from = moment.tz(moment($('#rp_from').val()).startOf('day'), zone).startOf('day'); - var to = moment.tz(moment($('#rp_to').val()).startOf('day'), zone).endOf('day'); + var to = moment.tz(moment($('#rp_to').val()).endOf('day'), zone).endOf('day'); timerange = '&find[created_at][$gte]=' + from.toISOString() + '&find[created_at][$lt]=' + to.toISOString(); + //console.log("FROM", from.format( ), "TO", to.format( ), 'timerange', timerange); //console.log($('#rp_from').val(),$('#rp_to').val(),zone,timerange); while (from <= to) { if (daystoshow[from.format('YYYY-MM-DD')]) { diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index f1bee57ca09..18076b7c9ae 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -432,7 +432,7 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio contextCircles.exit() .remove(); - var from = moment.tz(day, profile.getTimezone( )).startOf('day'); + var from = moment.tz(moment(day), profile.getTimezone( )).startOf('day'); var to = moment(from.clone( )).add(1, 'days'); var iobpolyline = '' , cobpolyline = ''; diff --git a/tests/reports.test.js b/tests/reports.test.js index 3ff2f882334..a639f3d4fb8 100644 --- a/tests/reports.test.js +++ b/tests/reports.test.js @@ -30,7 +30,7 @@ var someData = { '/api/v1/treatments.json?find[created_at][$gte]=2015-08-14T00:00:00.000Z&find[created_at][$lt]=2015-08-15T00:00:00.000Z&count=1000': [{'enteredBy':'Dad','eventType':'Site Change','glucose':268,'glucoseType':'Finger','insulin':1.75,'units':'mg/dl','created_at':'2015-08-14T00:00:00.000Z','_id':'55ce78fe925aa80e7071e5d6'},{'enteredBy':'Mom ','eventType':'Meal Bolus','glucose':89,'glucoseType':'Finger','carbs':54,'insulin':3.15,'units':'mg/dl','created_at':'2015-08-14T21:00:00.000Z','_id':'55ce59bb925aa80e7071e5ba'}], '/api/v1/entries.json?find[date][$gte]=1439596800000&find[date][$lt]=1439683200000&count=10000': [{'_id':'55cfd25f38a8d88ad1b49931','unfiltered':283136,'filtered':304768,'direction':'SingleDown','device':'dexcom','rssi':185,'sgv':306,'dateString':'Sat Aug 15 16:58:16 PDT 2015','type':'sgv','date':1439683096000,'noise':1},{'_id':'55cfd13338a8d88ad1b4992e','unfiltered':302528,'filtered':312576,'direction':'FortyFiveDown','device':'dexcom','rssi':179,'sgv':329,'dateString':'Sat Aug 15 16:53:16 PDT 2015','type':'sgv','date':1439682796000,'noise':1}], '/api/v1/food/regular.json': [{'_id':'552ece84a6947ea011db35bb','type':'food','category':'Zakladni','subcategory':'Sladkosti','name':'Bebe male','portion':18,'carbs':12,'gi':1,'unit':'pcs','created_at':'2015-04-15T20:48:04.966Z'}], - '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ + '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-08T23:59:59.999Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -63,7 +63,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ + '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-08T23:59:59.999Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, {'created_at':'2015-08-10T00:00:00.000Z'}, @@ -96,7 +96,7 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], - '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z?find[openaps][$exists]=true&count=1000': [ + '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-08T23:59:59.999Z?find[openaps][$exists]=true&count=1000': [ { 'openaps': { 'suggested': { From 48d1ae399b9636d61c5d2d27b4cd5ca6d2e10106 Mon Sep 17 00:00:00 2001 From: Ben West Date: Fri, 27 Jan 2023 08:07:29 -0800 Subject: [PATCH 10/11] tweak tests/logging --- lib/report/reportclient.js | 2 +- lib/report_plugins/daytoday.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index 9b918d6fb84..bf806591436 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -262,7 +262,7 @@ var init = function init () { var to = moment.tz(moment($('#rp_to').val()).endOf('day'), zone).endOf('day'); timerange = '&find[created_at][$gte]=' + from.toISOString() + '&find[created_at][$lt]=' + to.toISOString(); - //console.log("FROM", from.format( ), "TO", to.format( ), 'timerange', timerange); + console.log("FROM", from.format( ), "TO", to.format( ), 'timerange', timerange); //console.log($('#rp_from').val(),$('#rp_to').val(),zone,timerange); while (from <= to) { if (daystoshow[from.format('YYYY-MM-DD')]) { diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index 18076b7c9ae..c44cdf0386f 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -96,7 +96,9 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio var fatSum = 0; daytoday.prepareHtml(sorteddaystoshow); + console.log('DAY2DAY', 'sorteddaystoshow', sorteddaystoshow); sorteddaystoshow.forEach(function eachDay (day) { + drawChart(day, datastorage[day], options); }); From a8059393711fd5db63561afe21a51c729ac57442 Mon Sep 17 00:00:00 2001 From: Ben West Date: Fri, 27 Jan 2023 10:16:56 -0800 Subject: [PATCH 11/11] fix test with fixtures both ways --- tests/reports.test.js | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/reports.test.js b/tests/reports.test.js index a639f3d4fb8..bcaadbaf7cc 100644 --- a/tests/reports.test.js +++ b/tests/reports.test.js @@ -63,6 +63,39 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], + '/api/v1/treatments.json?find[eventType]=/BG Check/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ + {'created_at':'2015-08-08T00:00:00.000Z'}, + {'created_at':'2015-08-09T00:00:00.000Z'}, + {'created_at':'2015-08-10T00:00:00.000Z'}, + {'created_at':'2015-08-11T00:00:00.000Z'}, + {'created_at':'2015-08-12T00:00:00.000Z'}, + {'created_at':'2015-08-13T00:00:00.000Z'}, + {'created_at':'2015-08-14T00:00:00.000Z'}, + {'created_at':'2015-08-15T00:00:00.000Z'}, + {'created_at':'2015-08-16T00:00:00.000Z'}, + {'created_at':'2015-08-17T00:00:00.000Z'}, + {'created_at':'2015-08-18T00:00:00.000Z'}, + {'created_at':'2015-08-19T00:00:00.000Z'}, + {'created_at':'2015-08-20T00:00:00.000Z'}, + {'created_at':'2015-08-21T00:00:00.000Z'}, + {'created_at':'2015-08-22T00:00:00.000Z'}, + {'created_at':'2015-08-23T00:00:00.000Z'}, + {'created_at':'2015-08-24T00:00:00.000Z'}, + {'created_at':'2015-08-25T00:00:00.000Z'}, + {'created_at':'2015-08-26T00:00:00.000Z'}, + {'created_at':'2015-08-27T00:00:00.000Z'}, + {'created_at':'2015-08-28T00:00:00.000Z'}, + {'created_at':'2015-08-29T00:00:00.000Z'}, + {'created_at':'2015-08-30T00:00:00.000Z'}, + {'created_at':'2015-08-31T00:00:00.000Z'}, + {'created_at':'2015-09-01T00:00:00.000Z'}, + {'created_at':'2015-09-02T00:00:00.000Z'}, + {'created_at':'2015-09-03T00:00:00.000Z'}, + {'created_at':'2015-09-04T00:00:00.000Z'}, + {'created_at':'2015-09-05T00:00:00.000Z'}, + {'created_at':'2015-09-06T00:00:00.000Z'}, + {'created_at':'2015-09-07T00:00:00.000Z'} + ], '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-08T23:59:59.999Z': [ {'created_at':'2015-08-08T00:00:00.000Z'}, {'created_at':'2015-08-09T00:00:00.000Z'}, @@ -96,6 +129,39 @@ var someData = { {'created_at':'2015-09-06T00:00:00.000Z'}, {'created_at':'2015-09-07T00:00:00.000Z'} ], + '/api/v1/treatments.json?find[notes]=/something/i&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z': [ + {'created_at':'2015-08-08T00:00:00.000Z'}, + {'created_at':'2015-08-09T00:00:00.000Z'}, + {'created_at':'2015-08-10T00:00:00.000Z'}, + {'created_at':'2015-08-11T00:00:00.000Z'}, + {'created_at':'2015-08-12T00:00:00.000Z'}, + {'created_at':'2015-08-13T00:00:00.000Z'}, + {'created_at':'2015-08-14T00:00:00.000Z'}, + {'created_at':'2015-08-15T00:00:00.000Z'}, + {'created_at':'2015-08-16T00:00:00.000Z'}, + {'created_at':'2015-08-17T00:00:00.000Z'}, + {'created_at':'2015-08-18T00:00:00.000Z'}, + {'created_at':'2015-08-19T00:00:00.000Z'}, + {'created_at':'2015-08-20T00:00:00.000Z'}, + {'created_at':'2015-08-21T00:00:00.000Z'}, + {'created_at':'2015-08-22T00:00:00.000Z'}, + {'created_at':'2015-08-23T00:00:00.000Z'}, + {'created_at':'2015-08-24T00:00:00.000Z'}, + {'created_at':'2015-08-25T00:00:00.000Z'}, + {'created_at':'2015-08-26T00:00:00.000Z'}, + {'created_at':'2015-08-27T00:00:00.000Z'}, + {'created_at':'2015-08-28T00:00:00.000Z'}, + {'created_at':'2015-08-29T00:00:00.000Z'}, + {'created_at':'2015-08-30T00:00:00.000Z'}, + {'created_at':'2015-08-31T00:00:00.000Z'}, + {'created_at':'2015-09-01T00:00:00.000Z'}, + {'created_at':'2015-09-02T00:00:00.000Z'}, + {'created_at':'2015-09-03T00:00:00.000Z'}, + {'created_at':'2015-09-04T00:00:00.000Z'}, + {'created_at':'2015-09-05T00:00:00.000Z'}, + {'created_at':'2015-09-06T00:00:00.000Z'}, + {'created_at':'2015-09-07T00:00:00.000Z'} + ], '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-08T23:59:59.999Z?find[openaps][$exists]=true&count=1000': [ { 'openaps': { @@ -111,6 +177,22 @@ var someData = { }, 'created_at': '2015-08-31T00:00:00.000Z' } + ], + '/api/v1/devicestatus.json&find[created_at][$gte]=2015-08-08T00:00:00.000Z&find[created_at][$lt]=2015-09-07T23:59:59.999Z?find[openaps][$exists]=true&count=1000': [ + { + 'openaps': { + 'suggested': { + 'temp': 'absolute', + 'bg': 67, + 'tick': '+6', + 'eventualBG': 145, + 'snoozeBG': 145, + 'reason': 'BG 67<74.5, delta 6>0; no high-temp to cancel', + 'timestamp': '2015-08-31T00:00:00.000Z' + } + }, + 'created_at': '2015-08-31T00:00:00.000Z' + } ] };