From 28515b70f30e77b314ef1bafe108f0f300a2bd46 Mon Sep 17 00:00:00 2001 From: Brian Hanifin Date: Tue, 22 Jul 2014 17:19:54 -0700 Subject: [PATCH] /pebble?units=mmol Is this converting everything correctly? --- lib/pebble.js | 67 ++++++++++++--------- static/polymer.html | 138 -------------------------------------------- 2 files changed, 40 insertions(+), 165 deletions(-) delete mode 100644 static/polymer.html diff --git a/lib/pebble.js b/lib/pebble.js index a763b23760c..94ea26ab19d 100644 --- a/lib/pebble.js +++ b/lib/pebble.js @@ -20,36 +20,50 @@ function directionToTrend (direction) { } function pebble (req, res) { - var FORTY_MINUTES = 2400000; + var FORTY_MINUTES = 2400000, + cgmData = [ ], + units = req.query.units, + useMetricBg = false + ; + + if (units == "mmol") { + useMetricBg = true; + } + + function scaleBg(bg) { + if (useMetricBg) { + return (Math.round((bg / 18) * 10) / 10).toFixed(1); + } else + return bg; + } - var cgmData = [ ]; function get_latest (err, results) { var now = Date.now(); - results.forEach(function(element, index, array) { - var next = null; - if (index + 1 < results.length) { - next = results[index + 1]; - } - if (element) { - var obj = {}; - obj.sgv = element.sgv; - obj.bgdelta = (next ? (element.sgv - next.sgv ) : 0); - if ('direction' in element) { - obj.trend = directionToTrend(element.direction); - obj.direction = element.direction; - } - // obj.y = element.sgv; - // obj.x = element.date; - obj.datetime = element.date; - // obj.date = element.date.toString( ); - cgmData.push(obj); + results.forEach(function(element, index, array) { + var next = null; + if (index + 1 < results.length) { + next = results[index + 1]; + } + if (element) { + var obj = {}; + obj.sgv = scaleBg(element.sgv); + obj.bgdelta = (next ? (scaleBg(element.sgv) - scaleBg(next.sgv) ) : 0); + if ('direction' in element) { + obj.trend = directionToTrend(element.direction); + obj.direction = element.direction; } - }); - var result = { status: [ {now:now}], bgs: cgmData.slice(0, 1) }; - res.setHeader('content-type', 'application/json'); - res.write(JSON.stringify(result)); - res.end( ); - // collection.db.close(); + // obj.y = element.sgv; + // obj.x = element.date; + obj.datetime = element.date; + // obj.date = element.date.toString( ); + cgmData.push(obj); + } + }); + var result = { status: [ {now:now}], bgs: cgmData.slice(0, 1) }; + res.setHeader('content-type', 'application/json'); + res.write(JSON.stringify(result)); + res.end( ); + // collection.db.close(); } req.entries.list({count: 2}, get_latest); } @@ -63,4 +77,3 @@ function configure (entries) { configure.pebble = pebble; module.exports = configure; - diff --git a/static/polymer.html b/static/polymer.html deleted file mode 100644 index 9c44b16fe0d..00000000000 --- a/static/polymer.html +++ /dev/null @@ -1,138 +0,0 @@ - - - - - NightScout - - - - - - - - - - - - - - - - - - - - -
-
-
-
---
-
- --- -
-
- -
-
-
-
-
-
- - -
- - - - - - -