Skip to content

Commit

Permalink
Merge pull request #2 from nightscout/master
Browse files Browse the repository at this point in the history
Funnel Cake
  • Loading branch information
szpaku80 committed Oct 5, 2015
2 parents e53d8ce + 63283e8 commit f5498f9
Show file tree
Hide file tree
Showing 65 changed files with 4,162 additions and 338 deletions.
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Community maintained fork of the
- [Environment](#environment)
- [Required](#required)
- [Features/Labs](#featureslabs)
- [Alarms](#alarms)
- [Core](#core)
- [Predefined values for your browser settings (optional)](#predefined-values-for-your-browser-settings-optional)
- [Plugins](#plugins)
Expand Down Expand Up @@ -142,18 +143,35 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm

* `MONGO_CONNECTION` - Your mongo uri, for example: `mongodb://sally:[email protected]:99999/nightscout`
* `DISPLAY_UNITS` (`mg/dl`) - Choices: `mg/dl` and `mmol`. Setting to `mmol` puts the entire server into `mmol` mode by default, no further settings needed.
* `BASE_URL` - Used for building links to your sites api, ie pushover callbacks, usually the URL of your Nightscout site you may want https instead of http

### Features/Labs

* `ENABLE` - Used to enable optional features, expects a space delimited list, such as: `careportal rawbg iob`, see [plugins](#plugins) below
* `DISABLE` - Used to disable default features, expects a space delimited list, such as: `direction upbat`, see [plugins](#plugins) below
* `API_SECRET` - A secret passphrase that must be at least 12 characters long, required to enable `POST` and `PUT`; also required for the Care Portal
* `TREATMENTS_AUTH` (`off`) - possible values `on` or `off`. When on device must be authenticated by entering `API_SECRET` to create treatments


### Alarms

These alarm setting effect all delivery methods (browser, pushover, maker, etc), some settings can be overridden per client (web browser)

* `ALARM_TYPES` (`simple` if any `BG_`* ENV's are set, otherwise `predict`) - currently 2 alarm types are supported, and can be used independently or combined. The `simple` alarm type only compares the current BG to `BG_` thresholds above, the `predict` alarm type uses highly tuned formula that forecasts where the BG is going based on it's trend. `predict` **DOES NOT** currently use any of the `BG_`* ENV's
* `BG_HIGH` (`260`) - must be set using mg/dl units; the high BG outside the target range that is considered urgent
* `BG_TARGET_TOP` (`180`) - must be set using mg/dl units; the top of the target range, also used to draw the line on the chart
* `BG_TARGET_BOTTOM` (`80`) - must be set using mg/dl units; the bottom of the target range, also used to draw the line on the chart
* `BG_LOW` (`55`) - must be set using mg/dl units; the low BG outside the target range that is considered urgent
* `ALARM_TYPES` (`simple` if any `BG_`* ENV's are set, otherwise `predict`) - currently 2 alarm types are supported, and can be used independently or combined. The `simple` alarm type only compares the current BG to `BG_` thresholds above, the `predict` alarm type uses highly tuned formula that forecasts where the BG is going based on it's trend. `predict` **DOES NOT** currently use any of the `BG_`* ENV's
* `BASE_URL` - Used for building links to your sites api, ie pushover callbacks, usually the URL of your Nightscout site you may want https instead of http
* `ALARM_URGENT_HIGH` (`on`) - possible values `on` or `off`
* `ALARM_URGENT_HIGH_MINS` (`30 60 90 120`) - Number of minutes to snooze urgent high alarms, space separated for options in browser, first used for pushover
* `ALARM_HIGH` (`on`) - possible values `on` or `off`
* `ALARM_HIGH_MINS` (`30 60 90 120`) - Number of minutes to snooze high alarms, space separated for options in browser, first used for pushover
* `ALARM_LOW` (`on`) - possible values `on` or `off`
* `ALARM_LOW_MINS` (`15 30 45 60`) - Number of minutes to snooze low alarms, space separated for options in browser, first used for pushover
* `ALARM_URGENT_LOW` (`on`) - possible values `on` or `off`
* `ALARM_URGENT_LOW_MINS` (`15 30 45`) - Number of minutes to snooze urgent low alarms, space separated for options in browser, first used for pushover
* `ALARM_URGENT_MINS` (`30 60 90 120`) - Number of minutes to snooze urgent alarms (that aren't tagged as high or low), space separated for options in browser, first used for pushover
* `ALARM_WARN_MINS` (`30 60 90 120`) - Number of minutes to snooze warning alarms (that aren't tagged as high or low), space separated for options in browser, first used for pushover


### Core
Expand All @@ -165,6 +183,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `SSL_KEY` - Path to your ssl key file, so that ssl(https) can be enabled directly in node.js
* `SSL_CERT` - Path to your ssl cert file, so that ssl(https) can be enabled directly in node.js
* `SSL_CA` - Path to your ssl ca file, so that ssl(https) can be enabled directly in node.js
* `HEARTBEAT` (`60`) - Number of seconds to wait in between database checks


### Predefined values for your browser settings (optional)
Expand All @@ -173,10 +192,6 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `SHOW_RAWBG` (`never`) - possible values `always`, `never` or `noise`
* `CUSTOM_TITLE` (`Nightscout`) - Usually name of T1
* `THEME` (`default`) - possible values `default` or `colors`
* `ALARM_URGENT_HIGH` (`on`) - possible values `on` or `off`
* `ALARM_HIGH` (`on`) - possible values `on` or `off`
* `ALARM_LOW` (`on`) - possible values `on` or `off`
* `ALARM_URGENT_LOW` (`on`) - possible values `on` or `off`
* `ALARM_TIMEAGO_WARN` (`on`) - possible values `on` or `off`
* `ALARM_TIMEAGO_WARN_MINS` (`15`) - minutes since the last reading to trigger a warning
* `ALARM_TIMEAGO_URGENT` (`on`) - possible values `on` or `off`
Expand All @@ -198,6 +213,10 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `direction` (BG Direction) - Displays the trend direction.
* `upbat` (Uploader Battery) - Displays the most recent battery status from the uploader phone.
* `errorcodes` (CGM Error Codes) - Generates alarms for CGM codes `9` (hourglass) and `10` (???).
* Use [extended settings](#extended-settings) to adjust what errorcodes trigger notifications and alarms:
* `ERRORCODES_INFO` (`1 2 3 4 5 6 7 8`) - By default the needs calibration (blood drop) and other codes below 9 generate an info level notification, set to a space separate list of number or `off` to disable
* `ERRORCODES_WARN` (`off`) - By default there are no warning configured, set to a space separate list of numbers or `off` to disable
* `ERRORCODES_URGENT` (`9 10`) - By default the hourglass and ??? generate an urgent alarm, set to a space separate list of numbers or `off` to disable
* `ar2` ([Forcasting using AR2 algorithm](https://github.com/nightscout/nightscout.github.io/wiki/Forecasting)) - Generates alarms based on forecasted values.
* Enabled by default if no thresholds are set **OR** `ALARM_TYPES` includes `predict`.
* Use [extended settings](#extended-settings) to adjust AR2 behavior:
Expand Down Expand Up @@ -253,11 +272,18 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm

* `ENABLE` - `pushover` should be added to the list of plugin, for example: `ENABLE="pushover"`.
* `PUSHOVER_API_TOKEN` - Used to enable pushover notifications, this token is specific to the application you create from in [Pushover](https://pushover.net/), ***[additional pushover information](#pushover)*** below.
* `PUSHOVER_USER_KEY` - Your Pushover user key, can be found in the top left of the [Pushover](https://pushover.net/) site, this can also be a pushover delivery group key to send to a group rather than just a single user. This also support a space delimited list of keys.
* `PUSHOVER_ANNOUNCEMENT_KEY` - An optional Pushover user/group key, will be used for system wide user generated announcements. If not defined this will fallback to `PUSHOVER_USER_KEY`. A possible use for this is sending important messages and alarms to a CWD that you don't want to send all notification too. This also support a space delimited list of keys.
* `PUSHOVER_USER_KEY` - Your Pushover user key, can be found in the top left of the [Pushover](https://pushover.net/) site, this can also be a pushover delivery group key to send to a group rather than just a single user. This also supports a space delimited list of keys. To disable `INFO` level pushes set this to `off`.
* `PUSHOVER_ALARM_KEY` - An optional Pushover user/group key, will be used for system wide alarms (level > `WARN`). If not defined this will fallback to `PUSHOVER_USER_KEY`. A possible use for this is sending important messages and alarms to a CWD that you don't want to send all notification too. This also support a space delimited list of keys. To disable Alarm pushes set this to `off`.
* `PUSHOVER_ANNOUNCEMENT_KEY` - An optional Pushover user/group key, will be used for system wide user generated announcements. If not defined this will fallback to `PUSHOVER_USER_KEY` or `PUSHOVER_ALARM_KEY`. This also support a space delimited list of keys. To disable Announcement pushes set this to `off`.
* `BASE_URL` - Used for pushover callbacks, usually the URL of your Nightscout site, use https when possible.
* `API_SECRET` - Used for signing the pushover callback request for acknowledgments.


If you never want to get info level notifications (treatments) use `PUSHOVER_USER_KEY="off"`
If you never want to get an alarm via pushover use `PUSHOVER_ALARM_KEY="off"`
If you never want to get an announcement via pushover use `PUSHOVER_ANNOUNCEMENT_KEY="off"`

If only `PUSHOVER_USER_KEY` is set it will be used for all info notifications, alarms, and announcements

For testing/development try [localtunnel](http://localtunnel.me/).

#### IFTTT Maker
Expand Down
5 changes: 2 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "nightscout",
"version": "0.8.0",
"version": "0.8.1",
"dependencies": {
"angularjs": "1.3.0-beta.19",
"bootstrap": "~3.2.0",
"jquery": "2.1.0",
"jQuery-Storage-API": "~1.7.2",
"tipsy-jmalonzo": "~1.0.1",
"jquery-ui": "~1.11.3",
"jquery-flot": "0.8.3",
"swagger-ui": "~2.1.2"
},
"resolutions": {
Expand Down
2 changes: 2 additions & 0 deletions bundle/bundle.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

window.Nightscout = {
client: require('../lib/client')
, units: require('../lib/units')()
, plugins: require('../lib/plugins/')().registerClientDefaults()
, report_plugins: require('../lib/report_plugins/')()
};

console.info('Nightscout bundle ready');
Expand Down
4 changes: 3 additions & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function config ( ) {
*/
env.DISPLAY_UNITS = readENV('DISPLAY_UNITS', 'mg/dl');
env.PORT = readENV('PORT', 1337);
env.baseUrl = readENV('BASE_URL');
env.static_files = readENV('NIGHTSCOUT_STATIC_FILES', __dirname + '/static/');

setSSL();
Expand All @@ -26,6 +25,9 @@ function config ( ) {
setMongo();
updateSettings();

// require authorization for entering treatments
env.treatments_auth = readENV('TREATMENTS_AUTH',false);

return env;
}

Expand Down
12 changes: 10 additions & 2 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,15 @@ function configure (app, wares, ctx) {
api.get('/entries/:spec', function(req, res, next) {
if (isId(req.params.spec)) {
entries.getEntry(req.params.spec, function(err, entry) {
if (err) { return next(err); }
res.entries = [entry];
res.entries_err = err;
req.query.find = req.query.find || {};
req.query.find.type = entry.type;
if (entry) {
req.query.find.type = entry.type;
} else {
res.entries_err = "No such id: '" + req.params.spec + "'";
}
next();
});
} else {
Expand Down Expand Up @@ -581,12 +586,15 @@ curl -s -g 'http://localhost:1337/api/v1/times/20{14..15}/T{13..18}:{00..15}'.js
*/
api.delete('/entries/:spec', wares.verifyAuthorization, function (req, res, next) {
// if ID, prepare to query for one record
if (isId(req.params.id)) {
if (isId(req.params.spec)) {
prepReqModel(req, req.params.model);
req.query = {find: {_id: req.params.spec}};
} else {
req.params.model = req.params.spec;
prepReqModel(req, req.params.model);
if (req.query.find.type === '*') {
delete req.query.find.type;
}
}
next( );
}, delete_records);
Expand Down
2 changes: 2 additions & 0 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function create (env, ctx) {

app.set('title', [app.get('name'), 'API', app.get('version')].join(' '));

app.set('treatments_auth', env.treatments_auth);

// Start setting up routes
if (app.enabled('api')) {
// experiments
Expand Down
1 change: 1 addition & 0 deletions lib/api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function configure (app, wares, env) {
var info = { status: 'ok'
, name: app.get('name')
, version: app.get('version')
, serverTime: new Date().toISOString()
, apiEnabled: app.enabled('api')
, careportalEnabled: app.enabled('api') && env.settings.enable.indexOf('careportal') > -1
, head: wares.get_head( )
Expand Down
28 changes: 27 additions & 1 deletion lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,43 @@ function configure (app, wares, ctx) {

function config_authed (app, api, wares, ctx) {

api.post('/treatments/', /*TODO: auth disabled for now, need to get login figured out... wares.verifyAuthorization, */ function(req, res) {
function post_response(req, res) {
var treatment = req.body;
ctx.treatments.create(treatment, function (err, created) {
if (err) {
console.log('Error adding treatment');
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
} else {
console.log('Treatment created');
res.json(created);
}
});
}
if (app.settings.treatments_auth) {
api.post('/treatments/', wares.verifyAuthorization, post_response);
} else {
api.post('/treatments/', post_response);
}
api.delete('/treatments/:_id', wares.verifyAuthorization, function(req, res) {
ctx.treatments.remove(req.params._id, function ( ) {
res.json({ });
});
});

// update record
api.put('/treatments/', wares.verifyAuthorization, function(req, res) {
var data = req.body;
ctx.treatments.save(data, function (err, created) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
console.log('Error saving treatment');
console.log(err);
} else {
res.json(created);
console.log('Treatment saved', data);
}
});
});
}

if (app.enabled('api') && app.enabled('careportal')) {
Expand Down
4 changes: 3 additions & 1 deletion lib/bus.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

var Stream = require('stream');

function init (env) {
var beats = 0;
var started = new Date( );
var interval = env.HEARTBEAT || 60000;
var interval = env.settings.heartbeat * 1000;

var stream = new Stream;

Expand Down
23 changes: 12 additions & 11 deletions lib/client/browser-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function init ($) {
event.preventDefault();
});

$('.navigation a').click(function navigationClick ( ) {
closeDrawer('#drawer');
});

function reload() {
//strip '#' so form submission does not fail
var url = window.location.href;
Expand All @@ -62,14 +66,12 @@ function init ($) {

function closeDrawer(id, callback) {
lastOpenedDrawer = null;
$('html, body').animate({ scrollTop: 0 });
$(id).animate({right: '-300px'}, 300, function () {
$(id).css('display', 'none');
if (callback) { callback(); }
});
$('html, body').css({ scrollTop: 0 });
$(id).css({display: 'none', right: '-300px'});
if (callback) { callback(); }
}

function openDrawer(id, callback) {
function openDrawer(id, prepare) {
function closeOpenDraw(callback) {
if (lastOpenedDrawer) {
closeDrawer(lastOpenedDrawer, callback);
Expand All @@ -80,18 +82,17 @@ function init ($) {

closeOpenDraw(function () {
lastOpenedDrawer = id;
$(id).css('display', 'block').animate({right: '0'}, 300, function () {
if (callback) { callback(); }
});
if (prepare) { prepare(); }
$(id).css({display:'block', right: '0'});
});

}

function toggleDrawer(id, openCallback, closeCallback) {
function toggleDrawer(id, openPrepare, closeCallback) {
if (lastOpenedDrawer === id) {
closeDrawer(id, closeCallback);
} else {
openDrawer(id, openCallback);
openDrawer(id, openPrepare);
}
}

Expand Down
Loading

0 comments on commit f5498f9

Please sign in to comment.