Skip to content

Commit

Permalink
added basic units module to unify all mg/dl to mmol display conversion
Browse files Browse the repository at this point in the history
also fixed Calibration Pushover message to use the configured DISPLAY_UNITS like the rest of the system
  • Loading branch information
jasoncalabrese committed Apr 15, 2015
1 parent d456cbd commit 51462bb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions bundle/bundle.source.js
Expand Up @@ -4,6 +4,7 @@

window.Nightscout = {
iob: require('../lib/iob')()
, units: require('../lib/units')()
};

console.info("Nightscout bundle ready", window.Nightscout);
Expand Down
7 changes: 6 additions & 1 deletion lib/entries.js
Expand Up @@ -2,6 +2,7 @@

var es = require('event-stream');
var sgvdata = require('sgvdata');
var units = require('./units')();

var TEN_MINS = 10 * 60 * 1000;

Expand Down Expand Up @@ -134,9 +135,13 @@ function storage(name, storage, pushover) {
if (offset > TEN_MINS) {
console.info('No MBG Pushover, offset: ' + offset + ' too big, doc.date: ' + doc.date + ', now: ' + new Date().getTime());
} else {
var mbg = doc.mbg;
if (env.DISPLAY_UNITS == 'mmol') {
mbg = units.mgdlToMMOL(mbg);
}
var msg = {
expire: 14400, // 4 hours
message: '\nMeter BG: ' + doc.mbg,
message: '\nMeter BG: ' + mbg,
title: 'Calibration',
sound: 'magic',
timestamp: new Date(doc.date),
Expand Down
3 changes: 2 additions & 1 deletion lib/pebble.js
Expand Up @@ -15,6 +15,7 @@ var DIRECTIONS = {

var iob = require("./iob")();
var async = require('async');
var units = require('./units')();

function directionToTrend (direction) {
var trend = 8;
Expand All @@ -34,7 +35,7 @@ function pebble (req, res) {

function scaleBg(bg) {
if (req.mmol) {
return (Math.round((bg / 18) * 10) / 10).toFixed(1);
return units.mgdlToMMOL(bg);
} else {
return bg;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/units.js
@@ -0,0 +1,11 @@
function mgdlToMMOL(mgdl) {
return (Math.round((mgdl / 18) * 10) / 10).toFixed(1);
}

function configure() {
return {
mgdlToMMOL: mgdlToMMOL
}
}

module.exports = configure;
3 changes: 2 additions & 1 deletion static/clock.html
Expand Up @@ -41,6 +41,7 @@ <h1 class="bgnow"></h1>
</div>
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/api/v1/status.js"></script>
<script src="/public/js/bundle.js"></script>
<script type="text/javascript">
function query ( ) {
console.log('query');
Expand All @@ -53,7 +54,7 @@ <h1 class="bgnow"></h1>
var last = new Date(rec.date);
var now = new Date( );
if (window.serverSettings.units == 'mmol') {
rec.sgv = (Math.round((rec.sgv / 18) * 10) / 10).toFixed(1);
rec.sgv = Nightscout.units.mgdlToMMOL(rec.sgv);
}
$('.bgnow').text(rec.sgv);
var threshold = 1000 * 60 * 13;
Expand Down
2 changes: 1 addition & 1 deletion static/js/client.js
Expand Up @@ -96,7 +96,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
// lixgbg: Convert mg/dL BG value to metric mmol
function scaleBg(bg) {
if (browserSettings.units == 'mmol') {
return (Math.round((bg / 18) * 10) / 10).toFixed(1);
return Nightscout.units.mgdlToMMOL(bg);
} else {
return bg;
}
Expand Down
2 changes: 1 addition & 1 deletion static/js/ui-utils.js
Expand Up @@ -11,7 +11,7 @@ function getBrowserSettings(storage) {

function scaleBg(bg) {
if (json.units == 'mmol') {
return (Math.round((bg / 18) * 10) / 10).toFixed(1);
return Nightscout.units.mgdlToMMOL(bg);
} else {
return bg;
}
Expand Down

0 comments on commit 51462bb

Please sign in to comment.