Skip to content

Commit

Permalink
Revert to c1b2988 (Merge branch 'hotfix/0.3.5')
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Calabrese committed Aug 25, 2014
1 parent 6df1e40 commit 1cc9c61
Show file tree
Hide file tree
Showing 35 changed files with 180 additions and 882 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ my.env
*.env
static/bower_components/
.*.sw?
.DS_Store

.vagrant
/iisnode
/web.config
.vagrant
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ cgm-remote-monitor (a.k.a. NightScout)
[![Dependency Status](https://david-dm.org/nightscout/cgm-remote-monitor.png)](https://david-dm.org/nightscout/cgm-remote-monitor)
[![Gitter chat](https://badges.gitter.im/nightscout.png)](https://gitter.im/nightscout/public)

[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

This acts as a web-based CGM (Continuous Glucose Montinor) to allow
multiple caregivers to remotely view a patients glucose data in
realtime. The server reads a MongoDB which is intended to be data
Expand Down
13 changes: 0 additions & 13 deletions app.json

This file was deleted.

11 changes: 0 additions & 11 deletions bin/post-treatment.sh

This file was deleted.

2 changes: 0 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"name": "nightscout",
"version": "0.3.5",
"dependencies": {
"angularjs": "1.3.0-beta.19",
"bootstrap": "~3.2.0",
"d3": "3.4.3",
"jquery": "2.1.0",
"jQuery-Storage-API": "~1.7.2",
Expand Down
5 changes: 2 additions & 3 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ function config ( ) {
env.name = software.name;
env.DISPLAY_UNITS = process.env.DISPLAY_UNITS || 'mg/dl';
env.PORT = process.env.PORT || 1337;
env.mongo = process.env.MONGO_CONNECTION || process.env.CUSTOMCONNSTR_mongo || process.env.MONGOLAB_URI;
env.mongo_collection = process.env.CUSTOMCONNSTR_mongo_collection || process.env.MONGO_COLLECTION || 'entries';
env.mongo = process.env.MONGO_CONNECTION || process.env.CUSTOMCONNSTR_mongo;
env.mongo_collection = process.env.CUSTOMCONNSTR_mongo_collection || 'entries';
env.settings_collection = process.env.CUSTOMCONNSTR_mongo_settings_collection || 'settings';
env.treatments_collection = process.env.CUSTOMCONNSTR_mongo_treatments_collection || 'treatments';
var shasum = crypto.createHash('sha1');
var useSecret = (process.env.API_SECRET && process.env.API_SECRET.length > 0);
env.api_secret = null;
Expand Down
3 changes: 1 addition & 2 deletions lib/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

function create (env, entries, settings, treatments) {
function create (env, entries, settings) {
var express = require('express'),
app = express( )
;
Expand Down Expand Up @@ -29,7 +29,6 @@ function create (env, entries, settings, treatments) {
// Entries and settings
app.use('/', require('./entries/')(app, wares, entries));
app.use('/', require('./settings/')(app, wares, settings));
app.use('/', require('./treatments/')(app, wares, treatments));

// Status
app.use('/', require('./status')(app, wares));
Expand Down
47 changes: 0 additions & 47 deletions lib/api/treatments/index.js

This file was deleted.

12 changes: 3 additions & 9 deletions lib/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,10 @@ function entries (name, storage) {
with_collection(function(err, collection) {
if (err) { fn(err); return; }
// potentially a batch insert
var firstErr = null,
totalCreated = 0;

docs.forEach(function(doc) {
collection.update(doc, doc, {upsert: true}, function (err, created) {
firstErr = firstErr || err;
totalCreated += created;
});
collection.insert(docs, function (err, created) {
// execute the callback
fn(err, created, docs);
});
fn(firstErr, totalCreated, docs);
});
}

Expand Down
24 changes: 0 additions & 24 deletions lib/treatments.js

This file was deleted.

50 changes: 12 additions & 38 deletions lib/websocket.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

function websocket (env, server, entries, treatments) {
function websocket (env, server, entries) {
"use strict";
// CONSTANTS
var ONE_HOUR = 3600000,
Expand All @@ -24,10 +24,8 @@ var dir2Char = {
var io;
var watchers = 0;
var now = new Date().getTime();

var cgmData = [],
treatmentData = [],
patientData = [];
var cgmData = [];
var patientData = [];

function start ( ) {
io = require('socket.io').listen(server);
Expand Down Expand Up @@ -103,7 +101,6 @@ function update() {
now = Date.now();

cgmData = [];
treatmentData = [];
var earliest_data = now - TWO_DAYS;
var q = { find: {"date": {"$gte": earliest_data}} };
entries.list(q, function (err, results) {
Expand All @@ -117,15 +114,8 @@ function update() {
cgmData.push(obj);
}
});
treatments.list(function (err, results) {
treatmentData = results.map(function(treatment) {
var timestamp = new Date(treatment.timestamp || treatment.created_at);
treatment.x = timestamp.getTime();
return treatment;
});
// all done, do loadData
loadData( );
});
// all done, do loadData
loadData( );
});

return update;
Expand All @@ -143,37 +133,23 @@ function emitAlarm(alarmType) {
function loadData() {

console.log('running loadData');
var treatment = [];
var mbg = [];

var actual = [],
actualCurrent,
treatment = [],
errorCode;

var actual = [];
if (cgmData) {
actual = cgmData.slice();
actual.sort(function(a, b) {
return a.x - b.x;
});

actualCurrent = actual.length > 0 ? actual[actual.length - 1].y : null;

// sgv less than or equal to 10 means error code
// or warm up period code, so ignore
actual = actual.filter(function (a) {
return a.y > 10;
})
}

if (treatmentData) {
treatment = treatmentData.slice();
treatment.sort(function(a, b) {
return a.x - b.x;
});
}

if (actualCurrent && actualCurrent < 39) errorCode = actualCurrent;

var actualLength = actual.length - 1;

if (actualLength > 1) {
Expand Down Expand Up @@ -205,8 +181,8 @@ function loadData() {
//TODO: need to consider when data being sent has less than the 2 day minimum

// consolidate and send the data to the client
var shouldEmit = is_different(actual, predicted, mbg, treatment, errorCode);
patientData = [actual, predicted, mbg, treatment, errorCode];
var shouldEmit = is_different(actual, predicted, mbg, treatment);
patientData = [actual, predicted, mbg, treatment];
console.log('patientData', patientData.length);
if (shouldEmit) {
emitData( );
Expand All @@ -219,16 +195,16 @@ function loadData() {
avgLoss += 1 / size * Math.pow(log10(predicted[j].y / 120), 2);
}

//console.log(alarms['urgent_alarm'].threshold);
//console.log(alarms['alarm'].threshold);
if (avgLoss > alarms['urgent_alarm'].threshold) {
emitAlarm('urgent_alarm');
} else if (avgLoss > alarms['alarm'].threshold) {
emitAlarm('alarm');
} else if (errorCode) {
emitAlarm('urgent_alarm');
}
}
}
function is_different (actual, predicted, mbg, treatment, errorCode) {
function is_different (actual, predicted, mbg, treatment) {
if (patientData && patientData.length < 3) {
return true;
}
Expand All @@ -237,14 +213,12 @@ function loadData() {
, predicted: patientData[1].slice(-1).pop( )
, mbg: patientData[2].slice(-1).pop( )
, treatment: patientData[3].slice(-1).pop( )
, errorCode: patientData.length >= 5 ? patientData[4] : 0
};
var last = {
actual: actual.slice(-1).pop( )
, predicted: predicted.slice(-1).pop( )
, mbg: mbg.slice(-1).pop( )
, treatment: treatment.slice(-1).pop( )
, errorCode: errorCode
};

// textual diff of objects
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"express": "^4.6.1",
"express-extension-to-accept": "0.0.2",
"mongodb": "^1.4.7",
"moment": "2.8.1",
"sgvdata": "0.0.2",
"socket.io": "^0.9.17"
},
Expand Down
9 changes: 4 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ var express = require('express');
///////////////////////////////////////////////////
var entries = require('./lib/entries')(env.mongo_collection, store);
var settings = require('./lib/settings')(env.settings_collection, store);
var treatments = require('./lib/treatments')(env.treatments_collection, store);
var api = require('./lib/api/')(env, entries, settings, treatments);
var api = require('./lib/api/')(env, entries, settings);
var pebble = require('./lib/pebble');
///////////////////////////////////////////////////

///////////////////////////////////////////////////
// setup http server
///////////////////////////////////////////////////
var PORT = env.PORT;
var THIRTY_DAYS = 2592000;

var app = express();
var appInfo = software.name + ' ' + software.version;
Expand All @@ -57,8 +57,7 @@ app.get('/pebble', pebble(entries));
//app.get('/package.json', software);

// define static server
//TODO: JC - changed cache to 1 hour from 30d ays to bypass cache hell until we have a real solution
var staticFiles = express.static(env.static_files, {maxAge: 60 * 60 * 1000});
var staticFiles = express.static(env.static_files, {maxAge: THIRTY_DAYS * 1000});

// serve the static content
app.use(staticFiles);
Expand All @@ -77,7 +76,7 @@ store(function ready ( ) {
// setup socket io for data and message transmission
///////////////////////////////////////////////////
var websocket = require('./lib/websocket');
var io = websocket(env, server, entries, treatments);
var io = websocket(env, server, entries);
});

///////////////////////////////////////////////////
Loading

0 comments on commit 1cc9c61

Please sign in to comment.