Skip to content

Commit

Permalink
Merge pull request #3 from nightscout/dev
Browse files Browse the repository at this point in the history
Update dev
  • Loading branch information
ireneusz-ptak authored Jun 13, 2020
2 parents 0cecb60 + 802d986 commit 9ee13b1
Show file tree
Hide file tree
Showing 23 changed files with 618 additions and 129 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,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.
Expand Down
2 changes: 2 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_', '');
Expand Down
25 changes: 25 additions & 0 deletions lib/api/profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ function configure (app, wares, ctx) {
api.use(wares.bodyParser.urlencoded({ extended: true }));

api.use(ctx.authorization.isPermitted('api:profile:read'));


/**
* @function query_models
* Perform the standard query logic, translating API parameters into mongo
* db queries in a fairly regimented manner.
* This middleware executes the query, returning the results as JSON
*/
function query_models (req, res, next) {
var query = req.query;

// If "?count=" is present, use that number to decide how many to return.
if (!query.count) {
query.count = consts.ENTRIES_DEFAULT_COUNT;
}

// perform the query
ctx.profile.list_query(query, function payload(err, profiles) {
return res.json(profiles);
});
}

// List profiles available
api.get('/profiles/', query_models);

// List profiles available
api.get('/profile/', function(req, res) {
ctx.profile.list(function (err, attribute) {
Expand Down
1 change: 1 addition & 0 deletions lib/client/browser-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function init (client, serverSettings, $) {
settings.thresholds = serverSettings.settings.thresholds;
}


if (serverSettings.settings.enable) {
settings.enable = serverSettings.settings.enable;
}
Expand Down
45 changes: 42 additions & 3 deletions lib/client/careportal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function init (client, $) {
submitHooks = {};

_.forEach(careportal.allEventTypes, function each (event) {
inputMatrix[event.val] = _.pick(event, ['bg', 'insulin', 'carbs', 'protein', 'fat', 'prebolus', 'duration', 'percent', 'absolute', 'profile', 'split', 'reasons', 'targets']);
inputMatrix[event.val] = _.pick(event, ['otp','remoteCarbs', 'remoteAbsorption', 'remoteBolus', 'bg', 'insulin', 'carbs', 'protein', 'fat', 'prebolus', 'duration', 'percent', 'absolute', 'profile', 'split', 'reasons', 'targets']);
submitHooks[event.val] = event.submitHook;
});
}
Expand Down Expand Up @@ -80,11 +80,18 @@ function init (client, $) {
$('#reasonLabel').css('display', displayType(reasons && reasons.length > 0));
$('#targets').css('display', displayType(inputMatrix[eventType]['targets']));

$('#otpLabel').css('display', displayType(inputMatrix[eventType]['otp']));
$('#remoteCarbsLabel').css('display', displayType(inputMatrix[eventType]['remoteCarbs']));
$('#remoteAbsorptionLabel').css('display', displayType(inputMatrix[eventType]['remoteAbsorption']));
$('#remoteBolusLabel').css('display', displayType(inputMatrix[eventType]['remoteBolus']));

$('#bg').css('display', displayType(inputMatrix[eventType]['bg']));
$('#insulinGivenLabel').css('display', displayType(inputMatrix[eventType]['insulin']));

$('#carbsGivenLabel').css('display', displayType(inputMatrix[eventType]['carbs']));
$('#proteinGivenLabel').css('display', displayType(inputMatrix[eventType]['protein']));
$('#fatGivenLabel').css('display', displayType(inputMatrix[eventType]['fat']));

$('#durationLabel').css('display', displayType(inputMatrix[eventType]['duration']));
$('#percentLabel').css('display', displayType(inputMatrix[eventType]['percent'] && $('#absolute').val() === ''));
$('#absoluteLabel').css('display', displayType(inputMatrix[eventType]['absolute'] && $('#percent').val() === ''));
Expand All @@ -99,6 +106,11 @@ function init (client, $) {

careportal.reasonable();

resetIfHidden(inputMatrix[eventType]['otp'], '#otp');
resetIfHidden(inputMatrix[eventType]['remoteCarbs'], '#remoteCarbs');
resetIfHidden(inputMatrix[eventType]['remoteAbsorption'], '#remoteAbsorption');
resetIfHidden(inputMatrix[eventType]['remoteBolus'], '#remoteBolus');

resetIfHidden(inputMatrix[eventType]['insulin'], '#insulinGiven');
resetIfHidden(inputMatrix[eventType]['carbs'], '#carbsGiven');
resetIfHidden(inputMatrix[eventType]['protein'], '#proteinGiven');
Expand Down Expand Up @@ -192,6 +204,12 @@ function init (client, $) {
$('#eventType').val('<none>');
$('#glucoseValue').val('').attr('placeholder', translate('Value in') + ' ' + client.settings.units);
$('#meter').prop('checked', true);

$('#otp').val('');
$('#remoteCarbs').val('');
$('#remoteAbsorption').val('');
$('#remoteBolus').val('');

$('#carbsGiven').val('');
$('#proteinGiven').val('');
$('#fatGiven').val('');
Expand All @@ -214,6 +232,10 @@ function init (client, $) {
var data = {
enteredBy: $('#enteredBy').val()
, eventType: eventType
, otp: $('#otp').val()
, remoteCarbs: $('#remoteCarbs').val()
, remoteAbsorption: $('#remoteAbsorption').val()
, remoteBolus: $('#remoteBolus').val()
, glucose: $('#glucoseValue').val().replace(',', '.')
, reason: selectedReason
, targetTop: $('#targetTop').val().replace(',', '.')
Expand All @@ -226,11 +248,17 @@ function init (client, $) {
, duration: times.msecs(parse_duration($('#duration').val())).mins < 1 ? $('#duration').val() : times.msecs(parse_duration($('#duration').val())).mins
, percent: $('#percent').val()
, profile: $('#profile').val()
, preBolus: parseInt($('#preBolus').val())
, preBolus: $('#preBolus').val()
, notes: $('#notes').val()
, units: client.settings.units
};

data.preBolus = parseInt(data.preBolus);

if (isNaN(data.preBolus)) {
delete data.preBolus;
}

var reasons = inputMatrix[eventType]['reasons'];
var reason = _.find(reasons, function matches (r) {
return r.name === selectedReason;
Expand Down Expand Up @@ -273,7 +301,11 @@ function init (client, $) {
data.splitExt = parseInt($('#insulinSplitExt').val()) || 0;
}

return data;
let d = {};
Object.keys(data).forEach(function(key) {
if (data[key] != "" && data[key] != null) d[key] = data[key];
});
return d;
}

careportal.save = function save (event) {
Expand Down Expand Up @@ -327,6 +359,8 @@ function init (client, $) {
}
}

// TODO: add check for remote (Bolus, Carbs, Absorption)

return {
allOk
, messages
Expand All @@ -350,6 +384,11 @@ function init (client, $) {
text[text.length - 1] += ' ' + translate('Cancel');
}

pushIf(data.remoteCarbs, translate('Remote Carbs') + ': ' + data.remoteCarbs);
pushIf(data.remoteAbsorption, translate('Remote Absorption') + ': ' + data.remoteAbsorption);
pushIf(data.remoteBolus, translate('Remote Bolus') + ': ' + data.remoteBolus);
pushIf(data.otp, translate('One Time Pascode') + ': ' + data.otp);

pushIf(data.glucose, translate('Blood Glucose') + ': ' + data.glucose);
pushIf(data.glucose, translate('Measurement Method') + ': ' + translate(data.glucoseType));

Expand Down
19 changes: 13 additions & 6 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ function init (client, d3, $) {

function brushEnded () {
// update the opacity of the context data points to brush extent
var selectedRange = chart.createAdjustedRange();
var from = selectedRange[0].getTime();
var to = selectedRange[1].getTime();

chart.context.selectAll('circle')
.data(client.entries)
.style('opacity', function(d) { return renderer.highlightBrushPoints(d) });
.style('opacity', function(d) { return renderer.highlightBrushPoints(d, from, to) });
}

var extent = client.dataExtent();
Expand Down Expand Up @@ -251,6 +255,7 @@ function init (client, d3, $) {

chart.createBrushedRange = function() {
var brushedRange = chart.theBrush && d3.brushSelection(chart.theBrush.node()) || null;

var range = brushedRange && brushedRange.map(chart.xScale2.invert);
var dataExtent = client.dataExtent();

Expand All @@ -267,6 +272,8 @@ function init (client, d3, $) {
range[1] = new Date(end);
range[0] = new Date(end - client.focusRangeMS);

// console.log('createBrushedRange: ', brushedRange, range);

return range;
}

Expand Down Expand Up @@ -375,7 +382,8 @@ function init (client, d3, $) {

chart.theBrush.selectAll('rect')
.attr('y', 0)
.attr('height', contextHeight);
.attr('height', contextHeight)
.attr('width', '100%');

// disable resizing of brush
chart.context.select('.x.brush').select('.overlay').style('cursor', 'move');
Expand Down Expand Up @@ -507,7 +515,7 @@ function init (client, d3, $) {
.attr('y', 0)
.attr('height', contextHeight);

// console.log('Redrawing old brush with new dimensions: ', currentBrushExtent);
// console.log('chart.update(): Redrawing old brush with new dimensions: ', currentBrushExtent);

// redraw old brush with new dimensions
chart.theBrush.call(chart.brush.move, currentBrushExtent.map(chart.xScale2));
Expand Down Expand Up @@ -578,7 +586,7 @@ function init (client, d3, $) {

chart.xScaleBasals.domain(dataRange);

// console.log('Redrawing brush due to update: ', currentBrushExtent);
// console.log('chart.update(): Redrawing brush due to update: ', currentBrushExtent);

chart.theBrush.call(chart.brush.move, currentBrushExtent.map(chart.xScale2));
};
Expand Down Expand Up @@ -663,8 +671,7 @@ function init (client, d3, $) {
renderer.addTreatmentProfiles(client);
renderer.drawTreatments(client);


// console.log('Redrawing brush due to update: ', currentBrushExtent);
// console.log('scrollUpdate(): Redrawing brush due to update: ', currentBrushExtent);

chart.theBrush.call(chart.brush.move, currentBrushExtent.map(chart.xScale2));

Expand Down
14 changes: 9 additions & 5 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,12 @@ client.load = function load (serverSettings, callback) {

brushExtent[0] = new Date(brushExtent[1].getTime() - client.focusRangeMS);

// console.log('Resetting brush in updateBrushToNow: ', brushExtent);
// console.log('updateBrushToNow(): Resetting brush: ', brushExtent);

chart.theBrush && chart.theBrush.call(chart.brush.move, brushExtent.map(chart.xScale2));
if (chart.theBrush) {
chart.theBrush.call(chart.brush)
chart.theBrush.call(chart.brush.move, brushExtent.map(chart.xScale2));
}

if (!skipBrushing) {
brushed();
Expand All @@ -415,7 +418,6 @@ client.load = function load (serverSettings, callback) {

function brushed () {
// Brush not initialized
console.log("brushed");
if (!chart.theBrush) {
return;
}
Expand All @@ -426,11 +428,13 @@ client.load = function load (serverSettings, callback) {

var brushedRange = d3.brushSelection(chart.theBrush.node());

// console.log("brushed(): coordinates: ", brushedRange);

if (brushedRange) {
brushExtent = brushedRange.map(chart.xScale2.invert);
}

// console.log('Brushed to: ', brushExtent);
console.log('brushed(): Brushed to: ', brushExtent);

if (!brushedRange || (brushExtent[1].getTime() - brushExtent[0].getTime() !== client.focusRangeMS)) {
// ensure that brush updating is with the time range
Expand All @@ -440,7 +444,7 @@ client.load = function load (serverSettings, callback) {
brushExtent[1] = new Date(brushExtent[0].getTime() + client.focusRangeMS);
}

// console.log('Updating brushed to: ', brushExtent);
// console.log('brushed(): updating to: ', brushExtent);

chart.theBrush.call(chart.brush.move, brushExtent.map(chart.xScale2));
}
Expand Down
9 changes: 4 additions & 5 deletions lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ function init (client, d3) {
}

// get the desired opacity for context chart based on the brush extent
renderer.highlightBrushPoints = function highlightBrushPoints (data) {
var selectedRange = chart().createAdjustedRange();
var from = selectedRange[0].getTime();
var to = selectedRange[1].getTime();

renderer.highlightBrushPoints = function highlightBrushPoints (data, from, to) {
if (client.latestSGV && data.mills >= from && data.mills <= to) {
return chart().futureOpacity(data.mills - client.latestSGV.mills);
} else {
Expand Down Expand Up @@ -1038,6 +1034,9 @@ function init (client, d3) {

renderer.addBasals = function addBasals (client) {

if (!client.settings.isEnabled('basal')) {
return;
}
var mode = client.settings.extendedSettings.basal.render;
var profile = client.sbx.data.profile;
var linedata = [];
Expand Down
4 changes: 3 additions & 1 deletion lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/data/ddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function init () {
results.cals = ddata.cals;

var profiles = _.cloneDeep(ddata.profiles);
if (profiles && profiles[0]) {
if (profiles && profiles[0] && profiles[0].store) {
Object.keys(profiles[0].store).forEach(k => {
if (k.indexOf('@@@@@') > 0) {
delete profiles[0].store[k];
Expand Down
21 changes: 21 additions & 0 deletions lib/plugins/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ function init (ctx) {
});
}

// TODO: add OTP entry

return [
{
val: 'Temporary Override'
Expand All @@ -229,6 +231,7 @@ function init (ctx) {
, split: false
, targets: false
, reasons: reasonconf
, otp: true
, submitHook: postLoopNotification
},
{
Expand All @@ -245,10 +248,28 @@ function init (ctx) {
, split: false
, targets: false
, submitHook: postLoopNotification
},
{
val: 'Remote Carbs Entry'
, name: 'Remote Carbs Entry'
, remoteCarbs: true
, remoteAbsorption: true
, otp: true
, submitHook: postLoopNotification
},
{
val: 'Remote Bolus Entry'
, name: 'Remote Bolus Entry'
, remoteBolus: true
, otp: true
, submitHook: postLoopNotification
}
];
};

// TODO: Add event listener to customize labels


loop.updateVisualisation = function updateVisualisation (sbx) {
var prop = sbx.properties.loop;

Expand Down
Loading

0 comments on commit 9ee13b1

Please sign in to comment.