Skip to content

Commit

Permalink
Merge pull request #1 from nightscout/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
janrpn authored Jan 12, 2019
2 parents 06a7133 + 3ec9664 commit ce4f380
Show file tree
Hide file tree
Showing 37 changed files with 3,841 additions and 1,497 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.12.x
8.x
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ Languages with less than 90% coverage will be removed in a future Nightscout ver
| עברית (`he`)|Please volunteer|OK|
| Hrvatski (`hr`)|Please volunteer|Needs attention: 47.8%|
| Italiano (`it`)|Please volunteer|OK|
| 日本語 (`ja`)|[@LuminaryXion]|Working on this|
| 한국어 (`ko`)|Please volunteer|Needs attention: 80.6%|
| Norsk (Bokmål) (`nb`)|Please volunteer|OK|
| Nederlands (`nl`)|[@PieterGit]|OK|
Expand All @@ -231,12 +232,13 @@ Languages with less than 90% coverage will be removed in a future Nightscout ver
| Svenska (`sv`)|Please volunteer|OK|
| 中文(简体) (`zh_cn`) | [@jizhongwen]|OK|
| 中文(繁體) (`zh_tw`) | [@jizhongwen]|Needs attention: 25.0%]
| 日本語 (`ja_jp`) | [@LuminaryXion]|]


### List of all contributors
| Contribution area | List of contributors |
| ------------------------------------- | -------------------- |
| All active developers: | [@jasoncalabrese] [@jpcunningh] [@jweismann] [@komarserjio] [@mdomox] [@MilosKozak] [@PieterGit] [@rickfriele] [@sulkaharo]
| All active testers/documentors: | [@danamlewis] [@jamieowendexcom] [@mcdafydd] [@oteroos] [@rarneson] [@tynbendad] [@unsoluble]
| All active translators: | [@apanasef] [@jizhongwen] [@viderehh] @herzogmedia
| All active translators: | [@apanasef] [@jizhongwen] [@viderehh] @herzogmedia [@LuminaryXion]

23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ If you plan to use Nightscout, we recommend using [Heroku](http://openaps.readth

Minimum browser requirements for viewing the site:

- iOS 9
- Android 4
- Chrome 42
- Safari 9 (El Capitan)
- Firefox 34
- Chrome 68
- Edge 15
- Firefox 61
- Internet Explorer: not supported
- Opera: not supported
- iOS 9
- Safari 11
- Opera: 54

Windows installation software requirements:

- [Node.js](http://nodejs.org/) Latest Node 8 LTS (Node 8.12.0 or later). Use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or use `setup.sh`)
- [Node.js](http://nodejs.org/) Latest Node 8 LTS (Node 8.15.0 or later) or Node 10 LTS (Node 10.15.0 or later; Node 10.14.1 works for Azure). Use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or use `setup.sh`)
- [MongoDB](https://www.mongodb.com/download-center?jmp=nav#community) 3.x or later. MongoDB 2.4 is only supported for Raspberry Pi.

As a non-root user clone this repo then install dependencies into the root of the project:
Expand All @@ -140,16 +140,15 @@ As a non-root user clone this repo then install dependencies into the root of th
$ npm install
```

Installation notes for Microsoft Azure, Windows and Node 10:
Installation notes for Microsoft Azure, Windows:

- If deploying the software to Microsoft Azure, you must set ** in the app settings for *WEBSITE_NODE_DEFAULT_VERSION* and *SCM_COMMAND_IDLE_TIMEOUT* **before** you deploy the latest Nightscout or the site deployment will likely fail. Other hosting environments do not require this setting. Please use:
```
WEBSITE_NODE_DEFAULT_VERSION=8.11.1
WEBSITE_NODE_DEFAULT_VERSION=10.14.1
SCM_COMMAND_IDLE_TIMEOUT=300
```
- See [install MongoDB, Node.js, and Nightscouton a single Windows system](https://github.com/jaylagorio/Nightscout-on-Windows-Server). if you want to host your Nightscout outside of the cloud. Although the instructions are intended for Windows Server the procedure is compatible with client versions of Windows such as Windows 7 and Windows 10.
- If you deploy to Windows and want to develop or test you need to install [Cygwin](https://www.cygwin.com/) (use [setup-x86_64.exe](https://www.cygwin.com/setup-x86_64.exe) and make sure to install `build-essential` package. Test your configuration by executing `make` and check if all tests are ok.
- There may be some issues with Node 10.6.0 or later with Nightscout. Node 10 support will be in the 0.11 release. Please don't use Nightscout with (Node 9 or) Node 10 at this moment.

# Usage

Expand Down Expand Up @@ -360,7 +359,11 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
An option plugin to enable adding foods from database in Bolus Wizard and enable .

##### `rawbg` (Raw BG)
Calculates BG using sensor and calibration records from and displays an alternate BG values and noise levels.
Calculates BG using sensor and calibration records from and displays an alternate BG values and noise levels. Defaults that can be adjusted with [extended setting](#extended-settings)
* `DISPLAY` (`unsmoothed`) - Allows the user to control which algorithm is used to calculate the displayed raw BG values using the most recent calibration record.
* `unfiltered` - Raw BG is calculated by applying the calibration to the glucose record's unfiltered value.
* `filtered` - Raw BG is calculated by applying the calibration to the glucose record's filtered value. The glucose record's filtered values are generally produced by the CGM by a running average of the unfiltered values to produce a smoothed value when the sensor noise is high.
* `unsmoothed` - Raw BG is calculated by first finding the ratio of the calculated filtered value (the same value calculated by the `filtered` setting) to the reported glucose value. The displayed raw BG value is calculated by dividing the calculated unfiltered value (the same value calculated by the `unfiltered` setting) by the ratio. The effect is to exagerate changes in trend direction so the trend changes are more noticeable to the user. This is the legacy raw BG calculation algorithm.

##### `iob` (Insulin-on-Board)
Adds the IOB pill visualization in the client and calculates values that used by other plugins. Uses treatments with insulin doses and the `dia` and `sens` fields from the [treatment profile](#treatment-profile).
Expand Down
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ function create(env, ctx) {
// serve the static content
app.use(staticFiles);

var swaggerFiles = express.static(env.swagger_files, {
const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath();
var swaggerFiles = express.static(swaggerUiAssetPath, {
maxAge: maxAge
});

Expand Down
17 changes: 0 additions & 17 deletions bundle/index.js

This file was deleted.

1 change: 0 additions & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function config ( ) {
env.HOSTNAME = readENV('HOSTNAME', null);
env.IMPORT_CONFIG = readENV('IMPORT_CONFIG', null);
env.static_files = readENV('NIGHTSCOUT_STATIC_FILES', __dirname + '/static/');
env.swagger_files = readENV('NIGHTSCOUT_SWAGGER_FILES', __dirname + '/node_modules/swagger-ui-dist/');
env.debug = {
minify: readENVTruthy('DEBUG_MINIFY', true)
};
Expand Down
80 changes: 80 additions & 0 deletions lib/admin_plugins/cleanentriesdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

var moment = require('moment');

var cleanentriesdb = {
name: 'cleanentriesdb'
, label: 'Clean Mongo entries (glucose entries) database'
, pluginType: 'admin'
};

function init() {
return cleanentriesdb;
}

module.exports = init;

cleanentriesdb.actions = [
{
name: 'Delete all documents from entries collection older than 180 days'
, description: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.'
, buttonLabel: 'Delete old documents'
, confirmText: 'Delete old documents from entries collection?'
, preventClose: true
}
];

cleanentriesdb.actions[0].init = function init(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleanentriesdb.name + '_0_status');

$status.hide();

var numDays = '<br/>'
+ '<label for="admin_entries_days">'
+ translate('Number of Days to Keep:')
+ ' <input id="admin_entries_days" value="180" size="3" min="1"/>'
+ '</label>';

$('#admin_' + cleanentriesdb.name + '_0_html').html(numDays);

if (callback) { callback(); }
};

cleanentriesdb.actions[0].code = function deleteOldRecords(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleanentriesdb.name + '_0_status');
var numDays = Number($('#admin_entries_days').val());

if (isNaN(numDays) || (numDays < 3)) {
alert(translate('%1 is not a valid number - must be more than 2', { params: [$('#admin_entries_days').val()] }));
if (callback) { callback(); }
return;
}
var endDate = moment().subtract(numDays, 'days');

if (!client.hashauth.isAuthenticated()) {
alert(translate('Your device is not authenticated yet'));
if (callback) {
callback();
}
return;
}

$status.hide().text(translate('Deleting records ...')).fadeIn('slow');
$.ajax('/api/v1/entries/?find[date][$lte]=' + endDate.valueOf(), {
method: 'DELETE'
, headers: client.headers()
, success: function (retVal) {
$status.hide().text(translate('%1 records deleted',{ params: [retVal.n] })).fadeIn('slow');
}
, error: function () {
$status.hide().text(translate('Error')).fadeIn('slow');
}
}).done(function success () {
if (callback) { callback(); }
}).fail(function fail() {
if (callback) { callback(); }
});

};
10 changes: 5 additions & 5 deletions lib/admin_plugins/cleanstatusdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ cleanstatusdb.actions[1].code = function deleteOldRecords(client, callback) {
}

$status.hide().text(translate('Deleting records ...')).fadeIn('slow');
$.ajax({
$.ajax('/api/v1/devicestatus/?find[created_at][$lte]=' + dateStr, {
method: 'DELETE'
, url: '/api/v1/devicestatus/?find[created_at][$lte]=' + dateStr
, headers: client.headers()
, success: function (retVal) {
$status.hide().text(translate('%1 records deleted',{ params: [retVal.n] })).fadeIn('slow');
$status.text(translate('%1 records deleted',{ params: [retVal.n] }));
}
, error: function () {
$status.hide().text(translate('Error')).fadeIn('slow');
}
}).done(function success () {
if (callback) { callback(); }
}).fail(function fail() {
$status.hide().text(translate('Error')).fadeIn('slow');
if (callback) { callback(); }
});

};
81 changes: 81 additions & 0 deletions lib/admin_plugins/cleantreatmentsdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

var moment = require('moment');

var cleantreatmentsdb = {
name: 'cleantreatmentsdb'
, label: 'Clean Mongo treatments database'
, pluginType: 'admin'
};

function init() {
return cleantreatmentsdb;
}

module.exports = init;

cleantreatmentsdb.actions = [
{
name: 'Delete all documents from treatments collection older than 180 days'
, description: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.'
, buttonLabel: 'Delete old documents'
, confirmText: 'Delete old documents from treatments collection?'
, preventClose: true
}
];

cleantreatmentsdb.actions[0].init = function init(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleantreatmentsdb.name + '_0_status');

$status.hide();

var numDays = '<br/>'
+ '<label for="admin_treatments_days">'
+ translate('Number of Days to Keep:')
+ ' <input id="admin_treatments_days" value="180" size="3" min="1"/>'
+ '</label>';

$('#admin_' + cleantreatmentsdb.name + '_0_html').html(numDays);

if (callback) { callback(); }
};

cleantreatmentsdb.actions[0].code = function deleteOldRecords(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleantreatmentsdb.name + '_0_status');
var numDays = Number($('#admin_treatments_days').val());

if (isNaN(numDays) || (numDays < 3)) {
alert(translate('%1 is not a valid number - must be more than 2', { params: [$('#admin_treatments_days').val()] }));
if (callback) { callback(); }
return;
}
var endDate = moment().subtract(numDays, 'days');
var dateStr = endDate.format('YYYY-MM-DD');

if (!client.hashauth.isAuthenticated()) {
alert(translate('Your device is not authenticated yet'));
if (callback) {
callback();
}
return;
}

$status.hide().text(translate('Deleting records ...')).fadeIn('slow');
$.ajax('/api/v1/treatments/?find[created_at][$lte]=' + dateStr, {
method: 'DELETE'
, headers: client.headers()
, success: function (retVal) {
$status.hide().text(translate('%1 records deleted',{ params: [retVal.n] })).fadeIn('slow');
}
, error: function () {
$status.hide().text(translate('Error')).fadeIn('slow');
}
}).done(function success () {
if (callback) { callback(); }
}).fail(function fail() {
if (callback) { callback(); }
});

};
4 changes: 3 additions & 1 deletion lib/admin_plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function init() {
require('./subjects')()
, require('./roles')()
, require('./cleanstatusdb')()
, require('./cleantreatmentsdb')()
, require('./cleanentriesdb')()
, require('./futureitems')()
];

Expand Down Expand Up @@ -84,4 +86,4 @@ function init() {

}

module.exports = init;
module.exports = init;
57 changes: 36 additions & 21 deletions lib/api/devicestatus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,52 @@ function configure (app, wares, ctx) {

api.post('/devicestatus/', ctx.authorization.isPermitted('api:devicestatus:create'), doPost);

api.delete('/devicestatus/:_id', ctx.authorization.isPermitted('api:devicestatus:delete'), function(req, res) {
console.log('Deleting id: ' + req.params._id);

ctx.devicestatus.remove_id(req.params._id, function (err, removed) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
} else {
res.json(removed);
}
});
});

// delete record that match query
api.delete('/devicestatus/', ctx.authorization.isPermitted('api:devicestatus:delete'), function(req, res) {
/**
* @function delete_records
* Delete devicestatus. The query logic works the same way as find/list. This
* endpoint uses same search logic to remove records from the database.
*/
function delete_records(req, res, next) {
var query = req.query;
if (!query.count) {
query.count = 10
}

console.log('Delete records with query: ', query);

// remove using the query
ctx.devicestatus.remove(query, function(err, stat) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
console.log('Error saving treatment');
console.log(err);
} else {
res.json(stat);
console.log('devicestatus records deleted');
console.log('devicestatus delete error: ', err);
return next(err);
}
// yield some information about success of operation
res.json(stat);

console.log('devicestatus records deleted');

return next();
});
});
}

api.delete('/devicestatus/:id', ctx.authorization.isPermitted('api:devicestatus:delete'), function(req, res, next) {
if (!req.query.find) {
req.query.find = {
_id: req.params.id
};
} else {
req.query.find._id = req.params.id;
}

if (req.query.find._id === '*') {
// match any record id
delete req.query.find._id;
}
next();
}, delete_records);

// delete record that match query
api.delete('/devicestatus/', ctx.authorization.isPermitted('api:devicestatus:delete'), delete_records);
}

if (app.enabled('api') || true /*TODO: auth disabled for quick UI testing...*/) {
Expand Down
Loading

0 comments on commit ce4f380

Please sign in to comment.