diff --git a/lib/pebble.js b/lib/pebble.js index 37118e383ee..67f4236bc48 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 ? (element.sgv - next.sgv ) : 0); if ('direction' in element) { obj.trend = directionToTrend(element.direction); obj.direction = element.direction;