From ae83e210d394f44b726d67eb979fae1641696259 Mon Sep 17 00:00:00 2001 From: Ben West Date: Mon, 30 Jun 2014 18:19:25 -0700 Subject: [PATCH 1/2] actually show bgdelta The first bgdelta was always 0, which is incorrect. This allows the first item to have a delta. --- lib/pebble.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pebble.js b/lib/pebble.js index 37118e383ee..ce6881f68d6 100644 --- a/lib/pebble.js +++ b/lib/pebble.js @@ -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 ? (next.sgv - element.sgv) : 0); if ('direction' in element) { obj.trend = directionToTrend(element.direction); obj.direction = element.direction; From be57b350945303589788c8c20292bb5f98e20da4 Mon Sep 17 00:00:00 2001 From: Ben West Date: Mon, 30 Jun 2014 18:25:09 -0700 Subject: [PATCH 2/2] get sign in bg delta correct --- lib/pebble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pebble.js b/lib/pebble.js index ce6881f68d6..67f4236bc48 100644 --- a/lib/pebble.js +++ b/lib/pebble.js @@ -37,7 +37,7 @@ function pebble (req, res) { if (element) { var obj = {}; obj.sgv = element.sgv; - obj.bgdelta = (next ? (next.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;