Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
885f0cb
Reworked to support Express.
brianhanifin Jun 25, 2014
27be039
Full Caching with Express,
brianhanifin Jun 25, 2014
3555f73
Upgraded from node-static to Express,
brianhanifin Jun 25, 2014
59b7bca
put everything in a static directory
bewest Jun 25, 2014
4c10967
Merge pull request #3 from nightscout/express-cache
brianhanifin Jun 25, 2014
34bd567
Disable caching for /pebble
brianhanifin Jun 25, 2014
77b34aa
fixed typo in direction mapping; won't matter when cgm-pebble:feature…
Jun 25, 2014
2ae52a6
Merge pull request #24 from nightscout/feature/dir-typo
jasoncalabrese Jun 25, 2014
a0a9a02
Pebble class experiment.
brianhanifin Jun 26, 2014
53d9b7e
Fixed "expires:" header format error.
brianhanifin Jun 26, 2014
4f5c4e6
Fixed "expires:" header format error.
brianhanifin Jun 26, 2014
01349a8
Fixed "expires:" header format error.
brianhanifin Jun 26, 2014
6f298c3
Fixed "expires:" header format error.
brianhanifin Jun 26, 2014
a15f334
Unnecessary "cache-control: public" removed.
brianhanifin Jun 26, 2014
0f8e409
Attempting to resolve a few reddot.org issues.
brianhanifin Jun 27, 2014
d17670c
More redbot.org testing
brianhanifin Jun 27, 2014
3e9092e
I think it is ready!
brianhanifin Jun 27, 2014
1821568
Removing unused experiment.
brianhanifin Jun 27, 2014
ef6e17f
Changing HTML5 app cache
brianhanifin Jun 28, 2014
0ff2aaf
Changing HTML5 app cache
brianhanifin Jun 28, 2014
b3370f1
Removed http: protocol from HTML5 app cache file
brianhanifin Jun 29, 2014
7a024b7
change to test heroku + codeship.io integration
brianhanifin Jun 29, 2014
5d1ba85
Error handler fix.
brianhanifin Jun 29, 2014
49f3161
change to test heroku + codeship.io integration
brianhanifin Jun 29, 2014
290da9b
Cache test: testing change to client.js
brianhanifin Jun 29, 2014
82e2ad9
Cache test: testing change to client.js
brianhanifin Jun 29, 2014
1088fcc
Removing cache test code
brianhanifin Jun 29, 2014
d6eb615
remove expires, rework comment a bit
bewest Jun 30, 2014
a400b56
use default caching from express
bewest Jun 30, 2014
e02dd91
show correct time when brushing
bewest Jun 30, 2014
55fb873
remove dead code
bewest Jun 30, 2014
ddd66eb
re-work audio handling
bewest Jun 30, 2014
4136acb
Ensure that audio loops once it starts
bewest Jun 30, 2014
ac17273
Merge pull request #4 from nightscout/express-cache
brianhanifin Jun 30, 2014
382ec34
Added alarm silence for 120 minutes
gregwaehner Jun 24, 2014
9727c20
tweak whitespace
bewest Jun 30, 2014
f067953
test alert1
brianhanifin Jun 30, 2014
768283d
alert test2
brianhanifin Jun 30, 2014
ac5263e
removed test alert
brianhanifin Jun 30, 2014
004653c
HTML App Cache: removed .css and .js files.
brianhanifin Jun 30, 2014
0394b54
fix now-line placement
bewest Jun 30, 2014
f47a76f
alert test1
brianhanifin Jun 30, 2014
c215969
test 2
brianhanifin Jun 30, 2014
9c1a879
client.js change test successful
brianhanifin Jun 30, 2014
514718f
manually bust cache
bewest Jun 30, 2014
97ca423
Merge pull request #5 from nightscout/express-cache
brianhanifin Jun 30, 2014
1b77f74
README: Build & Dependancies
brianhanifin Jun 30, 2014
3f5fbec
Removing unused library
brianhanifin Jul 1, 2014
8c4016f
Removing unnecessary packages
brianhanifin Jul 1, 2014
ae83e21
actually show bgdelta
bewest Jul 1, 2014
be57b35
get sign in bg delta correct
bewest Jul 1, 2014
5cee972
Merge pull request #6 from nightscout/express-cache
brianhanifin Jul 1, 2014
431e95c
Removing audio.load() per bewest's request
brianhanifin Jul 1, 2014
233f1be
Merge pull request #26 from brianhanifin/express-cache
bewest Jul 1, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ node_modules/

.idea/
*.iml
my.env
my.env
*.env
static/bower_components/
.*.sw?
5 changes: 2 additions & 3 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
Binary file removed audio/alarm.mp3.gz
Binary file not shown.
Binary file removed audio/alarm2.mp3.gz
Binary file not shown.
10 changes: 6 additions & 4 deletions lib/pebble.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DIRECTIONS = {
NONE: 0
, DoupleUp: 1
, DoubleUp: 1
, SingleUp: 2
, FortyFiveUp: 3
, Flat: 4
Expand Down 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"
}
}
108 changes: 43 additions & 65 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 @@ -29,73 +29,51 @@ var cgmData = [];
////////////////////////////////////////////////////////////////////////////////////////////////////
// setup http server
////////////////////////////////////////////////////////////////////////////////////////////////////
var THIRTY_DAYS = 2592000;
var PORT = process.env.PORT || 1337;
var server = require('http').createServer(function serverCreator(request, response) {
var sys = require("sys");

var nodeStatic = require('node-static');
//enable gzip compression and cache for 30 days
//var staticServer = new nodeStatic.Server(".", { cache:THIRTY_DAYS, gzip:true });
var now = new Date();
var expires = new Date(now.getTime() + (1000 * THIRTY_DAYS));
var staticServer = new nodeStatic.Server(".", {
gzip: true,
headers: {
"cache-control": "public, max-age=" + THIRTY_DAYS,
"expires" : expires,
"Arr-Disable-Session-Affinity": "True"
}
});

// Grab the URL requested by the client and parse any query options
var url = require('url').parse(request.url, true);

// Return pebble API
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+'/css/dropdown.css',
'http://'+hostname+'/css/main.css',
'http://'+hostname+'/js/client.js',
'http://'+hostname+'/js/dropdown.js',
'http://'+hostname+'/favicon.ico',
'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:
*