Skip to content

Commit

Permalink
Merge pull request #7 from nightscout/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
winni67 authored Oct 26, 2017
2 parents 1589397 + dd5c125 commit 56accc3
Show file tree
Hide file tree
Showing 36 changed files with 662 additions and 390 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules/

bundle/bundle.out.js

.vscode/
.idea/
*.iml
my.env
Expand All @@ -22,4 +23,4 @@ coverage/
npm-debug.log
*.heapsnapshot

/tmp
/tmp
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.1.4
8.8.1
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: node_js
sudo: required
dist: trusty
node_js:
- "8.5.0"
- "8.8.1"
matrix:
fast_finish: true
services:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:8.5.0
FROM node:8.8.1

MAINTAINER Nightscout Contributors

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ all: test

coverage:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} -- --timeout 30000 -R tap ${TESTS}
${ISTANBUL} cover ${MOCHA} -- --timeout 15000 -R tap ${TESTS}

report:
test -f ${ANALYZED} && \
Expand All @@ -45,7 +45,7 @@ test:

travis:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 50000 -R tap ${TESTS}
${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 5000 -R tap ${TESTS}

docker_release:
# Get the version from the package.json file
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ Community maintained fork of the

Requirements:

- [Node.js](http://nodejs.org/)
- [Node.js](http://nodejs.org/) 8.8.1 (use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or `setup.sh`)

Clone this repo then install dependencies into the root of the project:

```bash
$ npm install
```

If deploying the software to Microsoft Azure, you must set *WEBSITE_NODE_DEFAULT_VERSION* in the app settings to *8.5.0* or the site deployment will fail. Other hosting environments do not require this setting.
If deploying the software to Microsoft Azure, you must set *WEBSITE_NODE_DEFAULT_VERSION* in the app settings to *8.8.1* **before** you deploy the latest Nightscout or the site deployment will likely fail. Other hosting environments do not require this setting.

# Usage

Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function create(env, ctx) {
json_match: /json/,
uglifyJS: myUglifyJS,
cssmin: myCssmin,
cache: __dirname + '/cache',
cache: __dirname + '/tmp',
onerror: undefined,
}));

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout",
"version": "0.10.0-dev-20170716",
"version": "0.10.2-release-20171026",
"dependencies": {
"colorbrewer": "~1.0.0",
"jQuery-Storage-API": "~1.7.2",
Expand Down
2 changes: 1 addition & 1 deletion lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function configure (app, wares, ctx) {
var ifModifiedSince = req.get('If-Modified-Since');
if (!ifModifiedSince) { return next(); }

if (lastEntryDate <= new Date(ifModifiedSince)) {
if (lastEntryDate.getTime() <= new Date(ifModifiedSince).getTime()) {
res.status(304).send({status:304, message: 'Not modified', type:'internal'});
return;
}
Expand Down
17 changes: 14 additions & 3 deletions lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var _ = require('lodash');
var consts = require('../../constants');
var moment = require('moment');

function configure(app, wares, ctx) {
var express = require('express')
Expand Down Expand Up @@ -39,16 +40,26 @@ function configure(app, wares, ctx) {
t.carbs = Number(t.carbs);
t.insulin = Number(t.insulin);

var d2 = new Date(t.timestamp);
var d2 = null;

if (d1 == null || d2 > d1) {
if (t.hasOwnProperty('created_at')) {
d2 = new Date(t.created_at);
} else {
if (t.hasOwnProperty('timestamp')) {
d2 = new Date(t.timestamp);
}
}

if (d2 == null) { return; }

if (d1 == null || d2.getTime() > d1.getTime()) {
d1 = d2;
}
});

if (!_.isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());

if (ifModifiedSince && d1 <= new Date(ifModifiedSince)) {
if (ifModifiedSince && d1.getTime() <= moment(ifModifiedSince).valueOf()) {
res.status(304).send({
status: 304
, message: 'Not modified'
Expand Down
54 changes: 27 additions & 27 deletions lib/client/boluscalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,41 +621,41 @@ function init(client, $) {
boluscalc.loadFoodDatabase = function loadFoodDatabase(event, callback) {
categories = [];
foodlist = [];
$.ajax('/api/v1/food/regular.json', {
headers: client.headers()
, success: function (records) {
records.forEach(function (r) {
foodlist.push(r);
if (r.category && !categories[r.category]) {
categories[r.category] = {};
}
if (r.category && r.subcategory) {
categories[r.category][r.subcategory] = true;
}
});
databaseloaded = true;
console.log('Food database loaded');
fillForm();
var records = client.sbx.data.food || [];
records.forEach(function (r) {
if (r.type == 'food') {
foodlist.push(r);
if (r.category && !categories[r.category]) {
categories[r.category] = {};
}
if (r.category && r.subcategory) {
categories[r.category][r.subcategory] = true;
}
}
}).done(function() { if (callback) { callback(); } });
});
databaseloaded = true;
console.log('Food database loaded');
fillForm();
maybePrevent(event);
if (callback) { callback(); }
};

boluscalc.loadFoodQuickpicks = function loadFoodQuickpicks( ) {
// Load quickpicks
$.ajax('/api/v1/food/quickpicks.json', {
headers: client.headers()
, success: function (records) {
quickpicks = records;
$('#bc_quickpick').empty().append('<option value="-1">' + translate('(none)') + '</option>');
for (var i=0; i<records.length; i++) {
var r = records[i];
$('#bc_quickpick').append('<option value="' + i +'">' + r.name + ' (' + r.carbs + ' g)</option>');
};
$('#bc_quickpick').val(-1);
$('#bc_quickpick').change(quickpickChange);
quickpicks = [];
var records = client.sbx.data.food || [];
records.forEach(function (r) {
if (r.type == 'quickpick') {
quickpicks.push(r);
}
});
$('#bc_quickpick').empty().append('<option value="-1">' + translate('(none)') + '</option>');
for (var i=0; i<records.length; i++) {
var r = records[i];
$('#bc_quickpick').append('<option value="' + i +'">' + r.name + ' (' + r.carbs + ' g)</option>');
};
$('#bc_quickpick').val(-1);
$('#bc_quickpick').change(quickpickChange);
};

function fillForm(event) {
Expand Down
2 changes: 1 addition & 1 deletion lib/client/receiveddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function receiveDData (received, ddata, settings) {
ddata.mbgs = mergeDataUpdate(received.delta, ddata.mbgs, received.mbgs);
ddata.treatments = mergeTreatmentUpdate(received.delta, ddata.treatments, received.treatments);

ddata.processTreatments(true);
ddata.processTreatments(false);

// Do some reporting on the console
// console.log('Total SGV data size', ddata.sgvs.length);
Expand Down
4 changes: 2 additions & 2 deletions lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,9 @@ function init (client, d3) {
var sign = t.first ? '▲▲▲' : '▬▬▬';
var ret;
if (t.cutting) {
ret = sign + ' ' + t.cutting + ' ' + '►►►' + ' ' + t.profile + ' ' + sign;
ret = sign + ' ' + client.profilefunctions.profileSwitchName(t.cutting) + ' ' + '►►►' + ' ' + client.profilefunctions.profileSwitchName(t.profile) + ' ' + sign;
} else {
ret = sign + ' ' + t.profile + ' ' + sign;
ret = sign + ' ' + client.profilefunctions.profileSwitchName(t.profile) + ' ' + sign;
}
return ret;
};
Expand Down
14 changes: 12 additions & 2 deletions lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function init(env, ctx) {
if (err) {
console.error(err);
}
ddata.processTreatments(false);
ddata.processTreatments(true);

var counts = [];
_.forIn(ddata, function each (value, key) {
Expand All @@ -66,6 +66,7 @@ function init(env, ctx) {
, loadProfileSwitchTreatments.bind(null, ddata, ctx)
, loadSensorAndInsulinTreatments.bind(null, ddata, ctx)
, loadProfile.bind(null, ddata, ctx)
, loadFood.bind(null, ddata, ctx)
, loadDeviceStatus.bind(null, ddata, env, ctx)
], loadComplete);

Expand Down Expand Up @@ -249,7 +250,16 @@ function loadProfile (ddata, ctx, callback) {
});
}

function loadDeviceStatus (ddata, env, ctx, callback) {
function loadFood (ddata, ctx, callback) {
ctx.food.list(function (err, results) {
if (!err && results) {
ddata.food = results;
}
callback();
});
}

function loadDeviceStatus (ddata, env, ctx, callback) {
var dateRange = {
$gte: new Date(ddata.lastUpdated - ONE_DAY).toISOString()
};
Expand Down
31 changes: 23 additions & 8 deletions lib/data/ddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function init( ) {
, cals: []
, profiles: []
, devicestatus: []
, food: []
, lastUpdated: 0
};

Expand Down Expand Up @@ -63,9 +64,20 @@ function init( ) {

result.first.sgvs = ddata.sgvs.filter(filterMax);
result.first.cals = ddata.cals;
result.first.profiles = ddata.profiles;

var profiles = _.cloneDeep(ddata.profiles);
if (profiles && profiles[0])
for (var k in profiles[0].store) {
if (profiles[0].store.hasOwnProperty(k)) {
if (k.indexOf('@@@@@') > 0) {
delete profiles[0].store[k];
}
}
}
result.first.profiles = profiles;

result.rest.mbgs = ddata.mbgs.filter(filterMax);
result.rest.food = ddata.food;

console.log('results.first size', JSON.stringify(result.first).length,'bytes');
console.log('results.rest size', JSON.stringify(result.rest).length,'bytes');
Expand Down Expand Up @@ -163,7 +175,7 @@ function init( ) {
}
};

ddata.processTreatments = function processTreatments (callProcessDurations ) {
ddata.processTreatments = function processTreatments (preserveOrignalTreatments ) {

// filter & prepare 'Site Change' events
ddata.sitechangeTreatments = ddata.treatments.filter( function filterSensor (t) {
Expand All @@ -184,8 +196,9 @@ function init( ) {
var profileTreatments = ddata.treatments.filter( function filterProfiles (t) {
return t.eventType === 'Profile Switch';
}).sort(function (a,b) { return a.mills > b.mills; });
if (callProcessDurations)
ddata.profileTreatments = ddata.processDurations(profileTreatments, true);
if (preserveOrignalTreatments)
profileTreatments = _.cloneDeep(profileTreatments);
ddata.profileTreatments = ddata.processDurations(profileTreatments, true);

// filter & prepare 'Combo Bolus' events
ddata.combobolusTreatments = ddata.treatments.filter( function filterComboBoluses (t) {
Expand All @@ -196,15 +209,17 @@ function init( ) {
var tempbasalTreatments = ddata.treatments.filter( function filterBasals (t) {
return t.eventType && t.eventType.indexOf('Temp Basal') > -1;
});
if (callProcessDurations)
ddata.tempbasalTreatments = ddata.processDurations(tempbasalTreatments, false);
if (preserveOrignalTreatments)
tempbasalTreatments = _.cloneDeep(tempbasalTreatments);
ddata.tempbasalTreatments = ddata.processDurations(tempbasalTreatments, false);

// filter temp target
var tempTargetTreatments = ddata.treatments.filter( function filterTargets (t) {
return t.eventType && t.eventType.indexOf('Temporary Target') > -1;
});
if (callProcessDurations)
ddata.tempTargetTreatments = ddata.processDurations(tempTargetTreatments, false);
if (preserveOrignalTreatments)
tempTargetTreatments = _.cloneDeep(tempTargetTreatments);
ddata.tempTargetTreatments = ddata.processDurations(tempTargetTreatments, false);

};

Expand Down
Loading

0 comments on commit 56accc3

Please sign in to comment.