From f3fab567c5e2d25da3d5a2f452c28b99cb016b0f Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 12 Jun 2020 10:17:52 -0400 Subject: [PATCH] Fix Issue #5486 - Device Status Days Feature (#5651) * Device Status Days Feature * Edits per review from @sulkaharo --- README.md | 1 + env.js | 2 ++ lib/data/dataloader.js | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd55ebf8..e8aeecdb 100644 --- a/README.md +++ b/README.md @@ -557,6 +557,7 @@ For remote overrides, the following extended settings must be configured: Plugins only have access to their own extended settings, all the extended settings of client plugins will be sent to the browser. * `DEVICESTATUS_ADVANCED` (`true`) - Defaults to true. Users who only have a single device uploading data to Nightscout can set this to false to reduce the data use of the site. + * `DEVICESTATUS_DAYS` (`1`) - Defaults to 1, can optionally be set to 2. Users can use this to show 48 hours of device status data for in retro mode, rather than the default 24 hours. Setting this value to 2 will roughly double the bandwidth usage of nightscout, so users with a data cap may not want to update this setting. #### Pushover In addition to the normal web based alarms, there is also support for [Pushover](https://pushover.net/) based alarms and notifications. diff --git a/env.js b/env.js index 0d8d4140..9875435f 100644 --- a/env.js +++ b/env.js @@ -170,6 +170,8 @@ function findExtendedSettings (envs) { extended.devicestatus = {}; extended.devicestatus.advanced = true; + extended.devicestatus.days = 1; + if(process.env['DEVICESTATUS_DAYS'] && process.env['DEVICESTATUS_DAYS'] == '2') extended.devicestatus.days = 1; function normalizeEnv (key) { return key.toUpperCase().replace('CUSTOMCONNSTR_', ''); diff --git a/lib/data/dataloader.js b/lib/data/dataloader.js index b0eafdd4..3c2d8c65 100644 --- a/lib/data/dataloader.js +++ b/lib/data/dataloader.js @@ -361,8 +361,10 @@ function loadFood(ddata, ctx, callback) { } function loadDeviceStatus(ddata, env, ctx, callback) { + var retroDays = ONE_DAY; + if(env.extendedSettings.devicestatus && env.extendedSettings.devicestatus.days && env.extendedSettings.devicestatus.days == 2) retroDays = TWO_DAYS; var dateRange = { - $gte: new Date(ddata.lastUpdated - ONE_DAY).toISOString() + $gte: new Date( ddata.lastUpdated - (retroDays) ).toISOString() }; if (ddata.page && ddata.page.frame) { dateRange['$lte'] = new Date(ddata.lastUpdated).toISOString();