Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…itor into vagrant

* 'master' of https://github.com/nightscout/cgm-remote-monitor: (52 commits)
  travis.yml: removed unused gitter.im hook
  Removing audio.load() per bewest's request
  get sign in bg delta correct
  actually show bgdelta
  Removing unnecessary packages
  Removing unused library
  README: Build & Dependancies
  manually bust cache
  client.js change test successful
  test 2
  alert test1
  fix now-line placement
  HTML App Cache: removed .css and .js files.
  removed test alert
  alert test2
  test alert1
  tweak whitespace
  Added alarm silence for 120 minutes
  Ensure that audio loops once it starts
  re-work audio handling
  ...

Conflicts:
	.gitignore
  • Loading branch information
Ollie Glass committed Jul 5, 2014
2 parents 5df1544 + 00cb61a commit c484650
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "./static/bower_components"
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ node_modules/
*.iml
my.env

*.env
static/bower_components/
.*.sw?

.vagrant
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
language: node_js
node_js:
- 0.10
- 0.11
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/60110e7743c1616b18fc
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: always # default: false
- 0.11
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cgm-remote-monitor (a.k.a. NightScout)
======================================

[![Build Status](https://travis-ci.org/brianhanifin/cgm-remote-monitor.png)](https://travis-ci.org/brianhanifin/cgm-remote-monitor)
[![Gitter chat](https://badges.gitter.im/brianhanifin/cgm-remote-monitor.png)](https://gitter.im/brianhanifin/cgm-remote-monitor)
[![Dependency Status](https://david-dm.org/brianhanifin/cgm-remote-monitor.png)](https://david-dm.org/brianhanifin/cgm-remote-monitor)
[![Build Status](https://travis-ci.org/nightscout/cgm-remote-monitor.png)](https://travis-ci.org/nightscout/cgm-remote-monitor)
[![Dependency Status](https://david-dm.org/nightscout/cgm-remote-monitor.png)](https://david-dm.org/nightscout/cgm-remote-monitor)

This acts as a web-based CGM (Continuous Glucose Montinor) to allow
multiple caregivers to remotely view a patients glucose data in
Expand Down Expand Up @@ -59,13 +58,13 @@ Easy to emulate on the commandline:
```bash
echo 'CUSTOMCONNSTR_mongo="mongodb://sally:[email protected]/db"' >> my.env
echo 'CUSTOMCONNSTR_mongo_collection="sallyCGMCollection"' >> my.env
source my.env
export CUSTOMCONNSTR_mongo
export CUSTOMCONNSTR_mongo_collection
```

From now on you can run using
```bash
source my.env
export CUSTOMCONNSTR_mongo
export CUSTOMCONNSTR_mongo_collection
node server.js
```

Expand Down
Binary file removed audio/alarm.mp3.gz
Binary file not shown.
Binary file removed audio/alarm2.mp3.gz
Binary file not shown.
8 changes: 5 additions & 3 deletions lib/pebble.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ function pebble (req, res) {
console.log('queried', new Date(earliest_data).toISOString( ),
new Date(now).toISOString( ), 'got raw results', results.length);
results.forEach(function(element, index, array) {
var last = cgmData[cgmData.length - 1];
var next = null;
if (index + 1 < results.length) {
next = results[index + 1];
}
if (element) {
console.log(element, index);
var obj = {};
obj.sgv = element.sgv;
obj.bgdelta = (last ? (last.sgv - element.sgv) : 0);
obj.bgdelta = (next ? (element.sgv - next.sgv ) : 0);
if ('direction' in element) {
obj.trend = directionToTrend(element.direction);
obj.direction = element.direction;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"postinstall": "node node_modules/bower/bin/bower install"
},
"dependencies": {
"appcache-node": "^0.2.0",
"bower": "~1.3.2",
"express": "^4.4.4",
"mongodb": "1.3.20",
"node-static": "0.7.1",
"socket.io": "~0.9.16"
}
}
97 changes: 43 additions & 54 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var patientData = [];
var now = new Date().getTime();
var fs = require('fs');
var c = require("appcache-node");
var express = require('express');
var mongoClient = require('mongodb').MongoClient;
var pebble = require('./lib/pebble');
var cgmData = [];
Expand All @@ -30,61 +30,50 @@ var cgmData = [];
// setup http server
////////////////////////////////////////////////////////////////////////////////////////////////////
var PORT = process.env.PORT || 1337;
var server = require('http').createServer(function serverCreator(request, response) {
var nodeStatic = require('node-static');
//enable gzip compression and cache for 30 days
var staticServer = new nodeStatic.Server(".", { cache:2592000, gzip:true });
var sys = require("sys");

// Grab the URL requested by the client and parse any query options
var url = require('url').parse(request.url, true);
if (url.path.indexOf('/pebble') === 0) {
request.with_collection = with_collection;
pebble.pebble(request, response);
return;
}

// Define the files you want the browser to cache
var hostname = request.headers.host;
var cf = c.newCache([
'http://'+hostname+'/audio/alarm.mp3',
'http://'+hostname+'/audio/alarm2.mp3',
'http://'+hostname+'/audio/alarm.mp3.gz',
'http://'+hostname+'/audio/alarm2.mp3.gz',
'http://'+hostname+'/css/dropdown.css',
'http://'+hostname+'/css/main.css',
'http://'+hostname+'/js/client.js',
'http://'+hostname+'/js/dropdown.js',
'http://'+hostname+'/favicon.ico',
'http://'+hostname+'/socket.io/socket.io.js',
'http://'+hostname+'/bower_components/d3/d3.min.js',
'http://'+hostname+'/bower_components/jquery/dist/jquery.min.js',
'http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,300,400,600,700,800',
'http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic',
'',
'NETWORK:',
'*'
]);

// Send the HTML5 nightscout.appcache file
if(request.url.match(/nightscout\.appcache$/)){
console.log( 'http://'+hostname+'/nightscout\.appcache')
response.writeHead(200, {'Content-Type': 'text/cache-manifest'});
return response.end(cf);
}
var THIRTY_DAYS = 2592000;
var now = new Date();
var STATIC_DIR = __dirname + '/static/';

// Serve file using node-static
staticServer.serve(request, response, function clientHandler(err) {
if (err) {
// Log the error
sys.error("Error serving " + request.url + " - " + err.message);
var app = express();
app.set('title', 'Nightscout');

// Respond to the client
response.writeHead(err.status, err.headers);
response.end('Error 404 - file not found');
}
});
}).listen(PORT);
// serve special URLs
// Pebble API
app.get("/pebble", servePebble);

// define static server
var server = express.static(STATIC_DIR, {maxAge: THIRTY_DAYS * 1000});

// serve the static content
app.use(server);

// handle errors
app.use(errorHandler);

var server = app.listen(PORT);
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
// server helper functions
////////////////////////////////////////////////////////////////////////////////////////////////////
function errorHandler(err, req, res, next) {
if (err) {
// Log the error
var msg = "Error serving " + request.url + " - " + err.message;
require("sys").error(msg);
console.log(msg);

// Respond to the client
res.status(err.status);
res.render('error', { error: err });
}
}

function servePebble(req, res) {
req.with_collection = with_collection;
pebble.pebble(req, res);
return;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
14 changes: 9 additions & 5 deletions index.html → static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>NightScout</title>
<link rel='stylesheet' type='text/css' href='css/main.css'>
<link rel='stylesheet' type='text/css' href='css/dropdown.css'>
<link rel='stylesheet' type='text/css' href='/css/main.css'>
<link rel='stylesheet' type='text/css' href='/css/dropdown.css'>
</head>
<body>
<div class='container'>
Expand All @@ -28,18 +28,22 @@
<li><a href="#" data-snooze-time="1800000">Silence for 30 minutes</a></li>
<li><a href="#" data-snooze-time="3600000">Silence for 60 minutes</a></li>
<li><a href="#" data-snooze-time="5400000">Silence for 90 minutes</a></li>
<li><a href="#" data-snooze-time="7200000">Silence for 120 minutes</a></li>
</ul>
</div>
</div>
<div class='row-fluid section1'>
<div id='chartContainer'></div>
</div>
</div>
<audio id='audio' loop src='audio/alarm.mp3' type='audio/mp3'></audio>
<div class="audio alarms">
<audio src='/audio/alarm.mp3' preload="auto" loop="true" class="alarm mp3" type='audio/mp3'></audio>
<audio src='/audio/alarm2.mp3' preload="auto" loop="true" class="urgent alarm2 mp3" type='audio/mp3'></audio>
</div>
<script src='/socket.io/socket.io.js'></script>
<script src='/bower_components/d3/d3.min.js'></script>
<script src='/bower_components/jquery/dist/jquery.min.js'></script>
<script src='js/dropdown.js'></script>
<script src='/js/client.js'></script>
<script src='/js/dropdown.js'></script>
<script src='/js/client.js?a'></script>
</body>
</html>
42 changes: 24 additions & 18 deletions js/client.js → static/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
var focusData = data.slice();

var element = document.getElementById('bgButton').hidden == '';
var nowDate = new Date(brushExtent[1] - THIRTY_MINS_IN_MS);

// predict for retrospective data
if (retrospectivePredictor && brushExtent[1].getTime() - THIRTY_MINS_IN_MS < now && element != true) {
Expand All @@ -200,11 +201,12 @@
.css('text-decoration','none');
}
$('#currentTime')
.text(d3.time.format('%I:%M%p')(brushExtent[1]))
.text(d3.time.format('%I:%M%p')(new Date(brushExtent[1] - THIRTY_MINS_IN_MS)))
.css('text-decoration','line-through');
} else if (retrospectivePredictor) {
// if the brush comes back into the current time range then it should reset to the current time and sg
var dateTime = new Date(now);
nowDate = dateTime;
$('#currentTime')
.text(d3.time.format('%I:%M%p')(dateTime))
.css('text-decoration','none');
Expand Down Expand Up @@ -272,9 +274,9 @@
focus.select('.now-line')
.transition()
.duration(UPDATE_TRANS_MS)
.attr('x1', xScale(new Date(brushExtent[1].getTime() - THIRTY_MINS_IN_MS)))
.attr('x1', xScale(nowDate))
.attr('y1', yScale(36))
.attr('x2', xScale(new Date(brushExtent[1].getTime() - THIRTY_MINS_IN_MS)))
.attr('x2', xScale(nowDate))
.attr('y2', yScale(420));

// update x axis
Expand Down Expand Up @@ -697,27 +699,27 @@
stopAlarm();
}
});
// TODO: this is dead code, maybe delete and remove from server
socket.on('clients', function(watchers) {
console.log('number of clients has changed to ' + watchers);
$('#watchers').text(watchers);
});


$('#testAlarms').click(function(event) {
d3.select('.audio.alarms audio').each(function (data, i) {
var audio = this;
audio.play();
setTimeout(function() {
audio.pause();
}, 4000);
});
event.preventDefault();
audio.src = 'audio/alarm.mp3';
audio.load();
audio.play();
setTimeout(function() {
audio.pause();
}, 4000);
});

function generateAlarm(file) {
alarmInProgress = true;
audio.src = 'audio/' + file;
audio.load();
audio.play();
var selector = '.audio.alarms audio.' + file;
d3.select(selector).each(function (d, i) {
var audio = this;
audio.play();
$(this).addClass('playing');
});
var element = document.getElementById('bgButton');
element.hidden = '';
var element1 = document.getElementById('noButton');
Expand All @@ -731,7 +733,11 @@
element.hidden = 'true';
element = document.getElementById('noButton');
element.hidden = '';
audio.pause();
d3.select('audio.playing').each(function (d, i) {
var audio = this;
audio.pause();
$(this).removeClass('playing');
});

// only emit ack if client invoke by button press
if (isClient) {
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions static/nightscout.appcache
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CACHE MANIFEST # June 30, 2014

CACHE:
audio/alarm.mp3
audio/alarm2.mp3
//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,300,400,600,700,800
//fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic

NETWORK:
*

0 comments on commit c484650

Please sign in to comment.