|
232 | 232 | var nowData = data.filter(function(d) { |
233 | 233 | return d.date.getTime() >= brushExtent[1].getTime() - FORTY_TWO_MINS_IN_MS && |
234 | 234 | d.date.getTime() <= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS && |
235 | | - d.color != 'none'; |
| 235 | + d.type == 'sgv'; |
236 | 236 | }); |
237 | 237 | if (nowData.length > 1) { |
238 | 238 | var prediction = predictAR(nowData); |
239 | 239 | focusData = focusData.concat(prediction); |
240 | 240 | var focusPoint = nowData[nowData.length - 1]; |
241 | | - $('.container .currentBG') |
242 | | - .text(focusPoint.sgv) |
243 | | - .css('text-decoration','line-through'); |
| 241 | + |
| 242 | + //in this case the SGV is scaled |
| 243 | + if (focusPoint.sgv < scaleBg(40)) |
| 244 | + $('.container .currentBG').text('LOW'); |
| 245 | + else if (focusPoint.sgv > scaleBg(400)) |
| 246 | + $('.container .currentBG').text('HIGH'); |
| 247 | + else |
| 248 | + $('.container .currentBG').text(focusPoint.sgv); |
| 249 | + |
| 250 | + $('.container .currentBG').css('text-decoration','line-through'); |
244 | 251 | $('.container .currentDirection') |
245 | 252 | .html(focusPoint.direction) |
246 | 253 | } else { |
|
260 | 267 | } else { |
261 | 268 | // if the brush comes back into the current time range then it should reset to the current time and sg |
262 | 269 | var nowData = data.filter(function(d) { |
263 | | - return d.color != 'none' && d.color != 'red'; |
| 270 | + return d.type == 'sgv'; |
264 | 271 | }); |
265 | 272 | nowData = [nowData[nowData.length - 2], nowData[nowData.length - 1]]; |
266 | 273 | var prediction = predictAR(nowData); |
|
304 | 311 | var secsSinceLast = (Date.now() - new Date(latestSGV.x).getTime()) / 1000; |
305 | 312 | $('#lastEntry').text(timeAgo(secsSinceLast)).toggleClass('current', secsSinceLast < 10 * 60); |
306 | 313 |
|
307 | | - $('.container .currentBG') |
308 | | - .text(scaleBg(latestSGV.y)) |
309 | | - .css('text-decoration', ''); |
| 314 | + //in this case the SGV is unscaled |
| 315 | + if (latestSGV.y < 40) |
| 316 | + $('.container .currentBG').text('LOW'); |
| 317 | + else if (latestSGV.y > 400) |
| 318 | + $('.container .currentBG').text('HIGH'); |
| 319 | + else |
| 320 | + $('.container .currentBG').text(scaleBg(latestSGV.y)); |
| 321 | + |
| 322 | + $('.container .currentBG').css('text-decoration', ''); |
310 | 323 | $('.container .currentDirection') |
311 | 324 | .html(latestSGV.direction); |
312 | 325 |
|
|
336 | 349 | .attr('cy', function (d) { return yScale(d.sgv); }) |
337 | 350 | .attr('fill', function (d) { return d.color; }) |
338 | 351 | .attr('opacity', function (d) { return futureOpacity(d.date - latestSGV.x); }) |
339 | | - .attr('r', 3); |
| 352 | + .attr('r', function(d) { if (d.type == 'mbg') return 6; else return 3;}); |
340 | 353 |
|
341 | 354 | focusCircles.exit() |
342 | 355 | .remove(); |
|
731 | 744 | .attr('cy', function (d) { return yScale2(d.sgv); }) |
732 | 745 | .attr('fill', function (d) { return d.color; }) |
733 | 746 | .style('opacity', function (d) { return highlightBrushPoints(d) }) |
734 | | - .attr('r', 2); |
| 747 | + .attr('r', function(d) { if (d.type == 'mbg') return 4; else return 2;}); |
735 | 748 |
|
736 | 749 | contextCircles.exit() |
737 | 750 | .remove(); |
|
800 | 813 | } |
801 | 814 | } |
802 | 815 | data = d[0].map(function (obj) { |
803 | | - return { date: new Date(obj.x), y: obj.y, sgv: scaleBg(obj.y), direction: obj.direction, color: sgvToColor(obj.y)} |
| 816 | + return { date: new Date(obj.x), y: obj.y, sgv: scaleBg(obj.y), direction: obj.direction, color: sgvToColor(obj.y), type: 'sgv'} |
804 | 817 | }); |
805 | 818 | // TODO: This is a kludge to advance the time as data becomes stale by making old predictor clear (using color = 'none') |
806 | 819 | // This shouldn't have to be sent and can be fixed by using xScale.domain([x0,x1]) function with |
807 | 820 | // 2 days before now as x0 and 30 minutes from now for x1 for context plot, but this will be |
808 | 821 | // required to happen when "now" event is sent from websocket.js every minute. When fixed, |
809 | 822 | // remove all "color != 'none'" code |
810 | | - data = data.concat(d[1].map(function (obj) { return { date: new Date(obj.x), y: obj.y, sgv: scaleBg(obj.y), color: 'none'} })); |
811 | | - data = data.concat(d[2].map(function (obj) { return { date: new Date(obj.x), y: obj.y, sgv: scaleBg(obj.y), color: 'red'} })); |
| 823 | + data = data.concat(d[1].map(function (obj) { return { date: new Date(obj.x), y: obj.y, sgv: scaleBg(obj.y), color: 'none', type: 'server-forecast'} })); |
| 824 | + |
| 825 | + //Add MBG's also, pretend they are SGV's |
| 826 | + data = data.concat(d[2].map(function (obj) { return { date: new Date(obj.x), y: obj.y, sgv: scaleBg(obj.y), color: 'red', type: 'mbg'} })); |
812 | 827 |
|
813 | 828 | data.forEach(function (d) { |
814 | 829 | if (d.y < 39) |
|
1092 | 1107 | color: predictedColor |
1093 | 1108 | }; |
1094 | 1109 | predicted.forEach(function (d) { |
| 1110 | + d.type = 'forecast'; |
1095 | 1111 | if (d.sgv < BG_MIN) |
1096 | 1112 | d.color = "transparent"; |
1097 | 1113 | }) |
|
0 commit comments