diff --git a/js/client.js b/js/client.js index 64b0b7b3c41..8f54a5feaa0 100644 --- a/js/client.js +++ b/js/client.js @@ -26,6 +26,7 @@ alarmSound = 'alarm.mp3', urgentAlarmSound = 'alarm2.mp3'; + var useMetricBg = true; // true means use mmol/L, false means mg/dL // create svg and g to contain the chart contents var charts = d3.select('#chartContainer').append('svg') @@ -43,6 +44,14 @@ focus.append('g') .attr('class', 'y axis'); +// lixgbg: Convert mg/dL BG value to metric mmol + function scaleBg(bg) { + if (useMetricBg) { + return (Math.round((by / 18) * 10) / 10).toFixed(1); + } else + return bg; + } + var context = charts.append('g'); // create the x axis container @@ -61,13 +70,14 @@ .domain(d3.extent(data, function (d) { return d.date; })); yScale = d3.scale.log() - .domain([30, 420]); + /*.domain([30, 420]);*/ + .domain([scaleBg(30), scaleBg(420)]); xScale2 = d3.time.scale() .domain(d3.extent(data, function (d) { return d.date; })); yScale2 = d3.scale.log() - .domain([36, 420]); + .domain([scaleBg(36), scaleBg(420)]); xAxis = d3.svg.axis() .scale(xScale) @@ -77,9 +87,11 @@ yAxis = d3.svg.axis() .scale(yScale) .tickFormat(d3.format('d')) - .tickValues([40, 60, 80, 120, 180, 300, 400]) + /*.tickValues([scaleBg(40), scaleBg(60), scaleBg(80), scaleBg(120), scaleBg(180), scaleBg(300), scaleBg(400)])*/ + .tickValues([2.0, 3.0, 4.0, 6.0, 10.0, 15.0, 22.0]) .orient('left'); + xAxis2 = d3.svg.axis() .scale(xScale2) .ticks(4) @@ -88,7 +100,8 @@ yAxis2 = d3.svg.axis() .scale(yScale2) .tickFormat(d3.format('d')) - .tickValues([40, 60, 80, 120, 180, 300, 400]) + /*.tickValues([scaleBg(40), scaleBg(60), scaleBg(80), scaleBg(120), scaleBg(180), scaleBg(300), scaleBg(400)])*/ + .tickValues([2.0, 3.0, 4.0, 6.0, 10.0, 15.0, 22.0]) .orient('right'); // setup a brush @@ -201,9 +214,9 @@ // transition open-top line to correct location focus.select('.open-top') .attr('x1', xScale2(brush.extent()[0])) - .attr('y1', yScale(30)) + .attr('y1', yScale(scaleBg(30))) .attr('x2', xScale2(brush.extent()[1])) - .attr('y2', yScale(30)); + .attr('y2', yScale(scaleBg(30))); // transition open-left line to correct location focus.select('.open-left') @@ -223,9 +236,9 @@ .transition() .duration(UPDATE_TRANS_MS) .attr('x1', xScale(new Date(now))) - .attr('y1', yScale(36)) + .attr('y1', yScale(scaleBg(36))) .attr('x2', xScale(new Date(now))) - .attr('y2', yScale(420)); + .attr('y2', yScale(scaleBg(420))); // update x axis focus.select('.x.axis') @@ -311,9 +324,9 @@ focus.append('line') .attr('class', 'now-line') .attr('x1', xScale(new Date(now))) - .attr('y1', yScale(36)) + .attr('y1', yScale(scaleBg(36))) .attr('x2', xScale(new Date(now))) - .attr('y2', yScale(420)) + .attr('y2', yScale(scaleBg(420))) .style('stroke-dasharray', ('3, 3')) .attr('stroke', 'grey'); @@ -321,9 +334,9 @@ focus.append('line') .attr('class', 'high-line') .attr('x1', xScale(dataRange[0])) - .attr('y1', yScale(180)) + .attr('y1', yScale(scaleBg(180))) .attr('x2', xScale(dataRange[1])) - .attr('y2', yScale(180)) + .attr('y2', yScale(scaleBg(180))) .style('stroke-dasharray', ('3, 3')) .attr('stroke', 'grey'); @@ -331,9 +344,9 @@ focus.append('line') .attr('class', 'low-line') .attr('x1', xScale(dataRange[0])) - .attr('y1', yScale(80)) + .attr('y1', yScale(scaleBg(80))) .attr('x2', xScale(dataRange[1])) - .attr('y2', yScale(80)) + .attr('y2', yScale(scaleBg(80))) .style('stroke-dasharray', ('3, 3')) .attr('stroke', 'grey'); @@ -357,9 +370,9 @@ context.append('line') .attr('class', 'now-line') .attr('x1', xScale(new Date(now))) - .attr('y1', yScale2(36)) + .attr('y1', yScale2(scaleBg(36))) .attr('x2', xScale(new Date(now))) - .attr('y2', yScale2(420)) + .attr('y2', yScale2(scaleBg(420))) .style('stroke-dasharray', ('3, 3')) .attr('stroke', 'grey'); @@ -367,9 +380,9 @@ context.append('line') .attr('class', 'high-line') .attr('x1', xScale(dataRange[0])) - .attr('y1', yScale2(180)) + .attr('y1', yScale2(scaleBg(180))) .attr('x2', xScale(dataRange[1])) - .attr('y2', yScale2(180)) + .attr('y2', yScale2(scaleBg(180))) .style('stroke-dasharray', ('3, 3')) .attr('stroke', 'grey'); @@ -377,9 +390,9 @@ context.append('line') .attr('class', 'low-line') .attr('x1', xScale(dataRange[0])) - .attr('y1', yScale2(80)) + .attr('y1', yScale2(scaleBg(80))) .attr('x2', xScale(dataRange[1])) - .attr('y2', yScale2(80)) + .attr('y2', yScale2(scaleBg(80))) .style('stroke-dasharray', ('3, 3')) .attr('stroke', 'grey'); @@ -424,27 +437,27 @@ .transition() .duration(UPDATE_TRANS_MS) .attr('x1', xScale(currentBrushExtent[0])) - .attr('y1', yScale(180)) + .attr('y1', yScale(scaleBg(180))) .attr('x2', xScale(currentBrushExtent[1])) - .attr('y2', yScale(180)); + .attr('y2', yScale(scaleBg(180))); // transition low line to correct location focus.select('.low-line') .transition() .duration(UPDATE_TRANS_MS) .attr('x1', xScale(currentBrushExtent[0])) - .attr('y1', yScale(80)) + .attr('y1', yScale(scaleBg(80))) .attr('x2', xScale(currentBrushExtent[1])) - .attr('y2', yScale(80)); + .attr('y2', yScale(scaleBg(80))); // transition open-top line to correct location focus.select('.open-top') .transition() .duration(UPDATE_TRANS_MS) .attr('x1', xScale2(currentBrushExtent[0])) - .attr('y1', yScale(30)) + .attr('y1', yScale(scaleBg(30))) .attr('x2', xScale2(currentBrushExtent[1])) - .attr('y2', yScale(30)); + .attr('y2', yScale(scaleBg(30))); // transition open-left line to correct location focus.select('.open-left') @@ -469,18 +482,18 @@ .transition() .duration(UPDATE_TRANS_MS) .attr('x1', xScale2(dataRange[0])) - .attr('y1', yScale2(180)) + .attr('y1', yScale2(scaleBg(180))) .attr('x2', xScale2(dataRange[1])) - .attr('y2', yScale2(180)); + .attr('y2', yScale2(scaleBg(180))); // transition low line to correct location context.select('.low-line') .transition() .duration(UPDATE_TRANS_MS) .attr('x1', xScale2(dataRange[0])) - .attr('y1', yScale2(80)) + .attr('y1', yScale2(scaleBg(180))) .attr('x2', xScale2(dataRange[1])) - .attr('y2', yScale2(80)); + .attr('y2', yScale2(scaleBg(180))); } } @@ -491,9 +504,9 @@ .transition() .duration(UPDATE_TRANS_MS) .attr('x1', xScale2(new Date(now))) - .attr('y1', yScale2(36)) + .attr('y1', yScale2(scaleBg(36))) .attr('x2', xScale2(new Date(now))) - .attr('y2', yScale2(420)); + .attr('y2', yScale2(scaleBg(420))); // only if a user brush is not active, update brush and focus chart with recent data // else, just transition brush @@ -580,7 +593,9 @@ if (d.length > 1) { // change the next line so that it uses the prediction if the signal gets lost (max 1/2 hr) if (d[0].length) { - var current = d[0][d[0].length - 1]; + var bg = scaleBg(d[0][d[0].length - 1].y); + $('#currentBG').text(bg); + $('#bgValue').text(bg); var secsSinceLast = (Date.now() - new Date(current.x).getTime()) / 1000; var currentBG = current.y; diff --git a/server.js b/server.js index e293b6aeea0..b8287e7c824 100644 --- a/server.js +++ b/server.js @@ -23,6 +23,10 @@ var fs = require('fs'); var mongoClient = require('mongodb').MongoClient; var pebble = require('./lib/pebble'); var cgmData = []; +//kate + + // var useMetricBg = true; // true means use mmol/L, false means mg/dL + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -154,6 +158,7 @@ function update() { if (element) { var obj = {}; obj.y = element.sgv; + obj.x = element.date; obj.d = element.dateString; obj.direction = directionToChar(element.direction);