mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Handle mmol to mgdl conversions with a constant reference (#5274)
This commit is contained in:
+11
-10
@@ -4,6 +4,7 @@ var moment = require('moment-timezone');
|
||||
var _ = require('lodash');
|
||||
var parse_duration = require('parse-duration'); // https://www.npmjs.com/package/parse-duration
|
||||
var times = require('../times');
|
||||
var consts = require('../constants');
|
||||
var Storages = require('js-storage');
|
||||
|
||||
function init (client, $) {
|
||||
@@ -240,8 +241,8 @@ function init (client, $) {
|
||||
}
|
||||
|
||||
if (units == "mmol") {
|
||||
data.targetTop = data.targetTop * 18;
|
||||
data.targetBottom = data.targetBottom * 18;
|
||||
data.targetTop = data.targetTop * consts.MMOL_TO_MGDL;
|
||||
data.targetBottom = data.targetBottom * consts.MMOL_TO_MGDL;
|
||||
}
|
||||
|
||||
//special handling for absolute to support temp to 0
|
||||
@@ -298,14 +299,14 @@ function init (client, $) {
|
||||
let targetTop = parseInt(data.targetTop);
|
||||
let targetBottom = parseInt(data.targetBottom);
|
||||
|
||||
let minTarget = 4 * 18;
|
||||
let maxTarget = 18 * 18;
|
||||
let minTarget = 4 * consts.MMOL_TO_MGDL;
|
||||
let maxTarget = 18 * consts.MMOL_TO_MGDL;
|
||||
|
||||
if (units == "mmol") {
|
||||
targetTop = Math.round(targetTop / 18.0 * 10) / 10;
|
||||
targetBottom = Math.round(targetBottom / 18.0 * 10) / 10;
|
||||
minTarget = Math.round(minTarget / 18.0 * 10) / 10;
|
||||
maxTarget = Math.round(maxTarget / 18.0 * 10) / 10;
|
||||
targetTop = Math.round(targetTop / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
targetBottom = Math.round(targetBottom / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
minTarget = Math.round(minTarget / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
maxTarget = Math.round(maxTarget / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
}
|
||||
|
||||
if (targetTop > maxTarget) {
|
||||
@@ -358,8 +359,8 @@ function init (client, $) {
|
||||
var targetBottom = data.targetBottom;
|
||||
|
||||
if (units == "mmol") {
|
||||
targetTop = Math.round(data.targetTop / 18.0 * 10) / 10;
|
||||
targetBottom = Math.round(data.targetBottom / 18.0 * 10) / 10;
|
||||
targetTop = Math.round(data.targetTop / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
targetBottom = Math.round(data.targetBottom / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
}
|
||||
|
||||
pushIf(data.targetTop, translate('Target Top') + ': ' + targetTop);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var _ = require('lodash');
|
||||
var times = require('../times');
|
||||
var consts = require('../constants');
|
||||
|
||||
var DEFAULT_FOCUS = times.hours(3).msecs
|
||||
, WIDTH_SMALL_DOTS = 420
|
||||
@@ -210,8 +211,8 @@ function init (client, d3) {
|
||||
var targetTop = d.targetTop;
|
||||
|
||||
if (client.settings.units === 'mmol') {
|
||||
targetBottom = Math.round(targetBottom / 18.0 * 10) / 10;
|
||||
targetTop = Math.round(targetTop / 18.0 * 10) / 10;
|
||||
targetBottom = Math.round(targetBottom / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
targetTop = Math.round(targetTop / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
}
|
||||
|
||||
var correctionRangeText;
|
||||
@@ -632,7 +633,7 @@ function init (client, d3) {
|
||||
function treatmentTooltip () {
|
||||
var glucose = treatment.glucose;
|
||||
if (client.settings.units != client.ddata.profile.getUnits()) {
|
||||
glucose *= (client.settings.units === 'mmol' ? 0.055 : 18);
|
||||
glucose *= (client.settings.units === 'mmol' ? (1 / consts.MMOL_TO_MGDL) : consts.MMOL_TO_MGDL);
|
||||
var decimals = (client.settings.units === 'mmol' ? 10 : 1);
|
||||
|
||||
glucose = Math.round(glucose * decimals) / decimals;
|
||||
|
||||
+2
-1
@@ -4,5 +4,6 @@
|
||||
"HTTP_UNAUTHORIZED" : 401,
|
||||
"HTTP_VALIDATION_ERROR" : 422,
|
||||
"HTTP_INTERNAL_ERROR" : 500,
|
||||
"ENTRIES_DEFAULT_COUNT" : 10
|
||||
"ENTRIES_DEFAULT_COUNT" : 10,
|
||||
"MMOL_TO_MGDL": 18
|
||||
}
|
||||
|
||||
+5
-4
@@ -2,6 +2,7 @@
|
||||
|
||||
var _ = require('lodash');
|
||||
var times = require('../times');
|
||||
var consts = require('../constants');
|
||||
|
||||
var DEVICE_TYPE_FIELDS = ['uploader', 'pump', 'openaps', 'loop', 'xdripjs'];
|
||||
|
||||
@@ -213,18 +214,18 @@ function init () {
|
||||
if (t.units) {
|
||||
if (t.units == 'mmol') {
|
||||
//convert to mgdl
|
||||
t.targetTop = t.targetTop * 18;
|
||||
t.targetBottom = t.targetBottom * 18;
|
||||
t.targetTop = t.targetTop * consts.MMOL_TO_MGDL;
|
||||
t.targetBottom = t.targetBottom * consts.MMOL_TO_MGDL;
|
||||
t.units = 'mg/dl';
|
||||
}
|
||||
}
|
||||
//if we have a temp target thats below 20, assume its mmol and convert to mgdl for safety.
|
||||
if (t.targetTop < 20) {
|
||||
t.targetTop = t.targetTop * 18;
|
||||
t.targetTop = t.targetTop * consts.MMOL_TO_MGDL;
|
||||
t.units = 'mg/dl';
|
||||
}
|
||||
if (t.targetBottom < 20) {
|
||||
t.targetBottom = t.targetBottom * 18;
|
||||
t.targetBottom = t.targetBottom * consts.MMOL_TO_MGDL;
|
||||
t.units = 'mg/dl';
|
||||
}
|
||||
return t.eventType && t.eventType.indexOf('Temporary Target') > -1;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var consts = require('../constants');
|
||||
|
||||
const MAX_BG_MMOL = 22;
|
||||
const MAX_BG_MGDL = MAX_BG_MMOL * 18;
|
||||
const MAX_BG_MGDL = MAX_BG_MMOL * consts.MMOL_TO_MGDL;
|
||||
|
||||
module.exports = function fitTreatmentsToBGCurve (ddata, env, ctx) {
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
var times = require('../times');
|
||||
var moment = require('moment');
|
||||
var consts = require('../constants');
|
||||
|
||||
function init (ctx) {
|
||||
|
||||
@@ -65,7 +66,7 @@ function init (ctx) {
|
||||
var units = profile.getUnits();
|
||||
|
||||
if (sbx.settings.units != units) {
|
||||
sensitivity *= (sbx.settings.units === 'mmol' ? 0.055 : 18);
|
||||
sensitivity *= (sbx.settings.units === 'mmol' ? (1 / consts.MMOL_TO_MGDL) : consts.MMOL_TO_MGDL);
|
||||
var decimals = (sbx.settings.units === 'mmol' ? 10 : 1);
|
||||
|
||||
sensitivity = Math.round(sensitivity * decimals) / decimals;
|
||||
|
||||
@@ -4,6 +4,7 @@ var _ = require('lodash');
|
||||
var moment = require('moment');
|
||||
var times = require('../times');
|
||||
var levels = require('../levels');
|
||||
var consts = require('../constants');
|
||||
|
||||
// var ALL_STATUS_FIELDS = ['status-symbol', 'status-label', 'iob', 'meal-assist', 'freq', 'rssi']; Unused variable
|
||||
|
||||
@@ -352,7 +353,7 @@ function init (ctx) {
|
||||
var units = sbx.data.profile.getUnits();
|
||||
|
||||
if (units === 'mmol') {
|
||||
bg = Math.round(bg / 18 * 10) / 10;
|
||||
bg = Math.round(bg / consts.MMOL_TO_MGDL * 10) / 10;
|
||||
}
|
||||
|
||||
var valueParts = [
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var consts = require('../constants');
|
||||
|
||||
var glucosedistribution = {
|
||||
name: 'glucosedistribution'
|
||||
, label: 'Distribution'
|
||||
@@ -174,7 +176,7 @@ glucosedistribution.report = function report_glucosedistribution (datastorage, s
|
||||
var bg = Math.floor(entry.bgValue + bgDelta * j);
|
||||
var t = new Date(entry.displayTime.getTime() + j * timePatch);
|
||||
var newEntry = {
|
||||
sgv: displayUnits === 'mmol' ? bg / 18 : bg
|
||||
sgv: displayUnits === 'mmol' ? bg / consts.MMOL_TO_MGDL : bg
|
||||
, bgValue: bg
|
||||
, displayTime: t
|
||||
};
|
||||
@@ -217,7 +219,7 @@ glucosedistribution.report = function report_glucosedistribution (datastorage, s
|
||||
const interpolatedValue = prevEntry.bgValue + d;
|
||||
|
||||
let newEntry = {
|
||||
sgv: displayUnits === 'mmol' ? interpolatedValue / 18 : interpolatedValue
|
||||
sgv: displayUnits === 'mmol' ? interpolatedValue / consts.MMOL_TO_MGDL : interpolatedValue
|
||||
, bgValue: interpolatedValue
|
||||
, displayTime: entry.displayTime
|
||||
};
|
||||
@@ -433,11 +435,11 @@ glucosedistribution.report = function report_glucosedistribution (datastorage, s
|
||||
|
||||
var unitString = ' mg/dl';
|
||||
if (displayUnits == 'mmol') {
|
||||
TDC = TDC / 18.0;
|
||||
TDCHourly = TDCHourly / 18.0;
|
||||
TDC = TDC / consts.MMOL_TO_MGDL;
|
||||
TDCHourly = TDCHourly / consts.MMOL_TO_MGDL;
|
||||
unitString = ' mmol/L';
|
||||
|
||||
RMS = Math.sqrt(RMSTotal / events) / 18;
|
||||
RMS = Math.sqrt(RMSTotal / events) / consts.MMOL_TO_MGDL;
|
||||
}
|
||||
|
||||
TDC = Math.round(TDC * 100) / 100;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var consts = require('../constants');
|
||||
|
||||
var moment = window.moment;
|
||||
var utils = { };
|
||||
|
||||
@@ -69,7 +71,7 @@ utils.scaledTreatmentBG = function scaledTreatmentBG(treatment,data) {
|
||||
console.info('found mismatched glucose units, converting ' + treatment.units + ' into ' + client.settings.units, treatment);
|
||||
if (treatment.units === 'mmol') {
|
||||
//BG is in mmol and display in mg/dl
|
||||
treatmentGlucose = Math.round(treatment.glucose * 18);
|
||||
treatmentGlucose = Math.round(treatment.glucose * consts.MMOL_TO_MGDL);
|
||||
} else {
|
||||
//BG is in mg/dl and display in mmol
|
||||
treatmentGlucose = client.utils.scaleMgdl(treatment.glucose);
|
||||
|
||||
+4
-2
@@ -1,11 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var consts = require('./constants');
|
||||
|
||||
function mgdlToMMOL(mgdl) {
|
||||
return (Math.round((mgdl / 18) * 10) / 10).toFixed(1);
|
||||
return (Math.round((mgdl / consts.MMOL_TO_MGDL) * 10) / 10).toFixed(1);
|
||||
}
|
||||
|
||||
function mmolToMgdl(mgdl) {
|
||||
return Math.round(mgdl * 18);
|
||||
return Math.round(mgdl * consts.MMOL_TO_MGDL);
|
||||
}
|
||||
|
||||
function configure() {
|
||||
|
||||
Reference in New Issue
Block a user