From 74f60fc5d3869e0bb1ace23f38d130d84c81342b Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Wed, 26 Aug 2015 19:48:49 +0200 Subject: [PATCH 0001/2594] ar2 --- lib/language.js | 57 ++++++++++++++++++++++++++++++++++++++++-- lib/levels.js | 3 ++- lib/plugins/ar2.js | 10 +++++--- tests/language.test.js | 6 +++++ 4 files changed, 69 insertions(+), 7 deletions(-) diff --git a/lib/language.js b/lib/language.js index d03a5544670..3977b4a6641 100644 --- a/lib/language.js +++ b/lib/language.js @@ -1,5 +1,7 @@ 'use strict'; +var _ = require('lodash'); + function init() { var lang; @@ -763,7 +765,7 @@ function init() { ,he: 'גודל' } ,'(none)' : { - cs: '(Prázdný)' + cs: '(žádný)' ,de: '(nichts)' ,es: '(ninguno)' ,fr: '(aucun)' @@ -778,6 +780,19 @@ function init() { ,nb: '(ingen)' ,he: '(ללא)' } + ,'None' : { + cs: 'Žádný' + ,de: 'Nichts' + ,es: 'Ninguno' + ,fr: 'Aucun' + ,pt: 'Nenhum' + ,sv: 'Tom' + ,ro: 'Fără' + ,bg: 'няма' + ,hr: 'Prazno' + ,it: 'Nessuno' + ,dk: 'Ingen' + } ,'Result is empty' : { cs: 'Prázdný výsledek' ,de: 'Leeres Ergebnis' @@ -3391,7 +3406,7 @@ function init() { ,ro: 'Alarmă urgentă hiper' ,bg: 'Много висока КЗ' ,hr: 'Hitni alarm za hiper' - ,it: 'Allarme Urgente: Glicemia Molto Alta' + ,it: 'Allarme UrgentUrgente: Glicemia Molto Alta' ,dk: 'Høj grænse overskredet' ,fi: 'Kriittinen korkea' ,nb: 'Kritisk høy alarm' @@ -4083,6 +4098,33 @@ function init() { cs: 'nejnovější nahoře' ,bg: 'Новите най-отгоре' } + ,'15m' : { // 15 minuts + cs: '15min' + } + ,'Check BG' : { + cs: 'Kontrola glykémie' + } + ,'predicted' : { + cs: 'předpovídaná' + } + ,'w/raw' : { + cs: 'včetně RAW' + } + ,'Unknown' : { // Message level + cs: 'Neznámý' + } + ,'Urgent' : { // Message level + cs: 'Urgentní' + } + ,'Warning' : { // Message level + cs: 'Varování' + } + ,'Info' : { // Message level + cs: 'Informativní' + } + ,'Lowest' : { // Message level + cs: 'Nejnižší' + } }; @@ -4093,6 +4135,17 @@ function init() { return text; }; + language.translateInUpperCase = function translateInUpperCase(text) { + var utext = text.toUpperCase(); + _.forEach(translations, function (ts, key) { + var ukey = key.toUpperCase(); + if (ukey === utext && ts[lang]) { + return ts[lang].toUpperCase(); + } + }); + return utext; + }; + language.DOMtranslate = function DOMtranslate($) { // do translation of static text on load $('.translate').each(function () { diff --git a/lib/levels.js b/lib/levels.js index 14dce01d308..ec03e4c28c5 100644 --- a/lib/levels.js +++ b/lib/levels.js @@ -1,5 +1,6 @@ 'use strict'; +var translate = require('./language')().translate; var levels = { URGENT: 2 @@ -25,7 +26,7 @@ levels.isAlarm = function isAlarm(level) { levels.toDisplay = function toDisplay(level) { var key = level !== undefined && level.toString(); - return key && level2Display[key] || 'Unknown'; + return key && translate(level2Display[key]) || translate('Unknown'); }; levels.toLowerCase = function toLowerCase(level) { diff --git a/lib/plugins/ar2.js b/lib/plugins/ar2.js index 53a1f6f6361..1a9ba347a97 100644 --- a/lib/plugins/ar2.js +++ b/lib/plugins/ar2.js @@ -5,6 +5,8 @@ var levels = require('../levels'); var times = require('../times'); var rawbg = require('./rawbg')(); var delta = require('./delta')(); +var translate = require('../language')().translate; +var translateInUpperCase = require('../language')().translateInUpperCase; var BG_REF = 140; //Central tendency var BG_MIN = 36; //Not 39, but why? @@ -46,7 +48,7 @@ function init() { var scaled = predicted && _.map(predicted, function(p) { return sbx.scaleEntry(p) } ); if (scaled && scaled.length >= 3) { - prop.displayLine = (prop.usingRaw ? 'Raw BG' : 'BG') + ' 15m: ' + scaled[2] + ' ' + sbx.unitsLabel; + prop.displayLine = (prop.usingRaw ? translate('Raw BG') : translate('BG')) + ' ' + translate('15m') + ': ' + scaled[2] + ' ' + sbx.unitsLabel; } @@ -220,15 +222,15 @@ function selectEventType (prop, sbx) { } function buildTitle(prop, sbx) { - var rangeLabel = prop.eventName ? prop.eventName.toUpperCase() : 'Check BG'; + var rangeLabel = prop.eventName ? translateInUpperCase(prop.eventName) : translate('Check BG'); var title = levels.toDisplay(prop.level) + ', ' + rangeLabel; var sgv = sbx.lastScaledSGV(); if (sgv > sbx.scaleMgdl(sbx.settings.thresholds.bgTargetBottom) && sgv < sbx.scaleMgdl(sbx.settings.thresholds.bgTargetTop)) { - title += ' predicted'; + title += ' ' + translate('predicted'); } if (prop.usingRaw) { - title += ' w/raw'; + title += ' ' + translate('w/raw'); } return title; } diff --git a/tests/language.test.js b/tests/language.test.js index 81c457f2ba9..2959f6bf113 100644 --- a/tests/language.test.js +++ b/tests/language.test.js @@ -21,4 +21,10 @@ describe('language', function ( ) { language.translate('Carbs').should.equal('Sacharidy'); }); + it('translate to Czech uppercase', function () { + var language = require('../lib/language')(); + language.set('cs'); + language.translateInUpperCase('carbs').should.equal('SACHARIDY'); + }); + }); From 8f5be2e447ea60bf9bf2ad4c657ef9885bc346b6 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Wed, 26 Aug 2015 23:14:21 +0200 Subject: [PATCH 0002/2594] function return bug fix --- lib/language.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index 3977b4a6641..3b411d4e334 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4140,7 +4140,7 @@ function init() { _.forEach(translations, function (ts, key) { var ukey = key.toUpperCase(); if (ukey === utext && ts[lang]) { - return ts[lang].toUpperCase(); + utext = ts[lang].toUpperCase(); } }); return utext; From 3de02d8b8e7e700bf1077ec10d4f4b455e22e3a0 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Tue, 15 Sep 2015 13:07:16 +0200 Subject: [PATCH 0003/2594] reverse wrong edit --- lib/language.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index 3b411d4e334..c382285e047 100644 --- a/lib/language.js +++ b/lib/language.js @@ -3406,7 +3406,7 @@ function init() { ,ro: 'Alarmă urgentă hiper' ,bg: 'Много висока КЗ' ,hr: 'Hitni alarm za hiper' - ,it: 'Allarme UrgentUrgente: Glicemia Molto Alta' + ,it: 'Allarme Urgente: Glicemia Molto Alta' ,dk: 'Høj grænse overskredet' ,fi: 'Kriittinen korkea' ,nb: 'Kritisk høy alarm' From 18c1aa2f522af8c58af2b43da1310b7509759b62 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 18 Sep 2015 23:30:13 +0200 Subject: [PATCH 0004/2594] ci translations --- lib/language.js | 26 ++++++++++++++++++++++---- lib/plugins/ar2.js | 3 +-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/language.js b/lib/language.js index c382285e047..5169721d06c 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4128,22 +4128,40 @@ function init() { }; - language.translate = function translate(text) { + // case sensitive + language.translateCS = function translateCaseSensitive(text) { if (translations[text] && translations[text][lang]) { return translations[text][lang]; } return text; }; - language.translateInUpperCase = function translateInUpperCase(text) { + // case insensitive + language.translateCI = function translateCaseInsensitive(text) { var utext = text.toUpperCase(); _.forEach(translations, function (ts, key) { var ukey = key.toUpperCase(); if (ukey === utext && ts[lang]) { - utext = ts[lang].toUpperCase(); + text = ts[lang]; } }); - return utext; + return text; + }; + + language.translate = function translate(text, options) { + var translated; + if (options && options.ci) { + translated = language.translateCI(text); + } else { + translated = language.translateCS(text); + } + if (options && options.params) { + for (var i = 0; i < options.params.length; i++) { + var r = new RegExp('\%' + (i+1), 'g'); + translated = translated.replace(r, options.params[i]); + } + } + return translated; }; language.DOMtranslate = function DOMtranslate($) { diff --git a/lib/plugins/ar2.js b/lib/plugins/ar2.js index 1a9ba347a97..18cd2dd42c9 100644 --- a/lib/plugins/ar2.js +++ b/lib/plugins/ar2.js @@ -6,7 +6,6 @@ var times = require('../times'); var rawbg = require('./rawbg')(); var delta = require('./delta')(); var translate = require('../language')().translate; -var translateInUpperCase = require('../language')().translateInUpperCase; var BG_REF = 140; //Central tendency var BG_MIN = 36; //Not 39, but why? @@ -222,7 +221,7 @@ function selectEventType (prop, sbx) { } function buildTitle(prop, sbx) { - var rangeLabel = prop.eventName ? translateInUpperCase(prop.eventName) : translate('Check BG'); + var rangeLabel = prop.eventName ? translate(prop.eventName, { ci: true }).toUpperCase() : translate('Check BG'); var title = levels.toDisplay(prop.level) + ', ' + rangeLabel; var sgv = sbx.lastScaledSGV(); From ae0a33c95a86cfb3b0b939718666bf6323ab5bd1 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 18 Sep 2015 23:55:21 +0200 Subject: [PATCH 0005/2594] fix travis --- tests/language.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/language.test.js b/tests/language.test.js index 2959f6bf113..fb024b85965 100644 --- a/tests/language.test.js +++ b/tests/language.test.js @@ -24,7 +24,7 @@ describe('language', function ( ) { it('translate to Czech uppercase', function () { var language = require('../lib/language')(); language.set('cs'); - language.translateInUpperCase('carbs').should.equal('SACHARIDY'); + language.translate('carbs', { ci: true }).should.equal('Sacharidy'); }); }); From b310b6025037f461644d34c82ec0627e7e7a51d1 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 17 Oct 2015 00:43:54 -0700 Subject: [PATCH 0006/2594] inital work on a timeago plugin --- lib/plugins/index.js | 1 + lib/plugins/timeago.js | 136 +++++++++++++++++++++++++++++++++++++++++ lib/times.js | 18 +++++- tests/timeago.test.js | 119 ++++++++++++++++++++++++++++++++++++ 4 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 lib/plugins/timeago.js create mode 100644 tests/timeago.test.js diff --git a/lib/plugins/index.js b/lib/plugins/index.js index 23c6eaa823a..b41fcecca3e 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -43,6 +43,7 @@ function init() { , require('./boluswizardpreview')() , require('./cannulaage')() , require('./treatmentnotify')() + , require('./timeago')() ]; plugins.registerServerDefaults = function registerServerDefaults() { diff --git a/lib/plugins/timeago.js b/lib/plugins/timeago.js new file mode 100644 index 00000000000..f095aa17904 --- /dev/null +++ b/lib/plugins/timeago.js @@ -0,0 +1,136 @@ +'use strict'; + +var _ = require('lodash'); +var levels = require('../levels'); +var times = require('../times'); + +function init ( ) { + + var timeago = { + name: 'timeago' + , label: 'Timeago' + , pluginType: 'notification' + }; + + timeago.checkNotifications = function checkNotifications (sbx) { + var lastSGVEntry = sbx.lastSGVEntry() + , warn = 'off' !== sbx.extendedSettings.warn + , warnMins = sbx.extendedSettings.warnMins || 15 + , urgent = 'off' !== sbx.extendedSettings.urgent + , urgentMins = sbx.extendedSettings.urgentMins || 30 + ; + + if (!lastSGVEntry || lastSGVEntry.mills >= sbx.time) { + return; + } + + function isStale (mins) { + return sbx.time - lastSGVEntry.mills > times.mins(mins).msecs + } + + function buildMessage(agoDisplay) { + var lines = sbx.prepareDefaultLines(); + lines.unshift('Last received: ' + [agoDisplay.value, agoDisplay.label].join(' ')); + return lines.join('\n'); + } + + function sendAlarm (opts) { + var agoDisplay = timeago.calcDisplay(lastSGVEntry, sbx.time); + + sbx.notifications.requestNotify({ + level: opts.level + , title: 'Stale data, check rig?' + , message: buildMessage(agoDisplay) + , eventName: timeago.name + , plugin: timeago + , pushoverSound: opts.pushoverSound + , debug: agoDisplay + }); + } + + if (urgent && isStale(urgentMins)) { + sendAlarm({ + level: levels.URGENT + , pushoverSound: 'siren' + }) + } else if (warn && isStale(warnMins)) { + sendAlarm({ + level: levels.WARN + , pushoverSound: 'siren' + }) + } + + }; + + timeago.isMissing = function isMissing (opts) { + if (!opts || !opts.entry || isNaN(opts.entry.mills) || isNaN(opts.time) || isNaN(opts.timeSince)) { + return { + label: 'time ago' + }; + } + }; + + timeago.inTheFuture = function inTheFuture (opts) { + if (opts.entry.mills - times.mins(5).msecs > opts.time) { + return { + label: 'in the future' + }; + } + }; + + timeago.almostInTheFuture = function almostInTheFuture (opts) { + if (opts.entry.mills > opts.time) { + return { + value: 1 + , label: 'min ago' + }; + } + }; + + timeago.isLessThan = function isLessThan (limit, divisor, label) { + return function checkIsLessThan (opts) { + if (opts.timeSince < limit) { + return { + value: Math.max(1, Math.round(Math.abs(opts.timeSince / divisor))) + , label: label + }; + } + } + }; + + timeago.resolvers = [ + timeago.isMissing + , timeago.inTheFuture + , timeago.almostInTheFuture + , timeago.isLessThan(times.mins(2).msecs, times.min().msecs, 'min ago') + , timeago.isLessThan(times.hour().msecs, times.min().msecs, 'mins ago') + , timeago.isLessThan(times.hours(2).msecs, times.hour().msecs, 'hour ago') + , timeago.isLessThan(times.day().msecs, times.hour().msecs, 'hours ago') + , timeago.isLessThan(times.days(2).msecs, times.day().msecs, 'day ago') + , timeago.isLessThan(times.week().msecs, times.day().msecs, 'days ago') + , function ( ) { return { label: 'long ago' } } + ]; + + timeago.calcDisplay = function calcDisplay (entry, time) { + var opts = { + time: time + , entry: entry + }; + + if (time && entry && entry.mills) { + opts.timeSince = time - entry.mills; + } + + for (var i = 0; i < timeago.resolvers.length; i++) { + var value = timeago.resolvers[i](opts); + if (value) { + return value; + } + } + }; + + return timeago; + +} + +module.exports = init; \ No newline at end of file diff --git a/lib/times.js b/lib/times.js index 4acf8fa0d1a..0e48e6596e8 100644 --- a/lib/times.js +++ b/lib/times.js @@ -3,7 +3,17 @@ var cache = { }; var factories = { - hours: function hours(value) { + weeks: function weeks(value) { + return { + mins: value * 7 * 24 * 60, secs: value * 7 * 24 * 60 * 60, msecs: value * 7 * 24 * 60 * 60 * 1000 + }; + } + , days: function days(value) { + return { + mins: value * 24 * 60, secs: value * 24 * 60 * 60, msecs: value * 24 * 60 * 60 * 1000 + }; + } + , hours: function hours(value) { return { mins: value * 60, secs: value * 60 * 60, msecs: value * 60 * 60 * 1000 }; @@ -33,7 +43,11 @@ function getOrCreate (types) { } var times = { - hour: function ( ) { return getOrCreate('hours')(1); } + week: function ( ) { return getOrCreate('weeks')(1); } + , weeks: function (value) { return getOrCreate('weeks')(value); } + , day: function ( ) { return getOrCreate('days')(1); } + , days: function (value) { return getOrCreate('days')(value); } + , hour: function ( ) { return getOrCreate('hours')(1); } , hours: function (value) { return getOrCreate('hours')(value); } , min: function ( ) { return getOrCreate('mins')(1); } , mins: function (value) { return getOrCreate('mins')(value); } diff --git a/tests/timeago.test.js b/tests/timeago.test.js new file mode 100644 index 00000000000..91006acb32f --- /dev/null +++ b/tests/timeago.test.js @@ -0,0 +1,119 @@ +var should = require('should'); +var levels = require('../lib/levels'); +var times = require('../lib/times'); + +describe('timeago', function ( ) { + + var timeago = require('../lib/plugins/timeago')(); + var delta = require('../lib/plugins/delta')(); + + var env = require('../env')(); + var ctx = {}; + ctx.data = require('../lib/data')(env, ctx); + ctx.notifications = require('../lib/notifications')(env, ctx); + + var now = Date.now(); + + + it('Not trigger an alarm when data is current', function (done) { + ctx.notifications.initRequests(); + ctx.data.sgvs = [{mills: now, mgdl: 100, type: 'sgv'}]; + + var sbx = require('../lib/sandbox')().serverInit(env, ctx); + timeago.checkNotifications(sbx); + should.not.exist(ctx.notifications.findHighestAlarm()); + + done(); + }); + + it('Not trigger an alarm with future data', function (done) { + ctx.notifications.initRequests(); + ctx.data.sgvs = [{mills: now + times.mins(15).msecs, mgdl: 100, type: 'sgv'}]; + + var sbx = require('../lib/sandbox')().serverInit(env, ctx); + timeago.checkNotifications(sbx); + should.not.exist(ctx.notifications.findHighestAlarm()); + + done(); + }); + + it('should trigger a warning when data older than 15m', function (done) { + ctx.notifications.initRequests(); + ctx.data.sgvs = [{mills: now - times.mins(15).msecs, mgdl: 100, type: 'sgv'}]; + + var sbx = require('../lib/sandbox')().serverInit(env, ctx); + timeago.checkNotifications(sbx); + var highest = ctx.notifications.findHighestAlarm(); + highest.level.should.equal(levels.WARN); + highest.message.should.equal('Last received: 15 mins ago\nBG Now: 100 mg/dl'); + done(); + }); + + it('should trigger an urgent alarm when data older than 30m', function (done) { + ctx.notifications.initRequests(); + ctx.data.sgvs = [{mills: now - times.mins(30).msecs, mgdl: 100, type: 'sgv'}]; + + var sbx = require('../lib/sandbox')().serverInit(env, ctx); + timeago.checkNotifications(sbx); + var highest = ctx.notifications.findHighestAlarm(); + highest.level.should.equal(levels.URGENT); + highest.message.should.equal('Last received: 30 mins ago\nBG Now: 100 mg/dl'); + done(); + }); + + it('calc timeago displays', function() { + + should.deepEqual( + timeago.calcDisplay({ mills: now + times.mins(15).msecs }, now) + , {label: 'in the future'} + ); + + //TODO: current behavior, we can do better + //just a little in the future, pretend it's ok + should.deepEqual( + timeago.calcDisplay({ mills: now + times.mins(4).msecs }, now) + , {value: 1, label: 'min ago'} + ); + + should.deepEqual( + timeago.calcDisplay(null, now) + , {label: 'time ago'} + ); + + should.deepEqual( + timeago.calcDisplay({ mills: now }, now) + , {value: 1, label: 'min ago'} + ); + + should.deepEqual( + timeago.calcDisplay({ mills: now - 1 }, now) + , {value: 1, label: 'min ago'} + ); + + should.deepEqual( + timeago.calcDisplay({ mills: now - times.sec(30).msecs }, now) + , {value: 1, label: 'min ago'} + ); + + should.deepEqual( + timeago.calcDisplay({ mills: now - times.mins(30).msecs }, now) + , {value: 30, label: 'mins ago'} + ); + + should.deepEqual( + timeago.calcDisplay({ mills: now - times.hours(5).msecs }, now) + , {value: 5, label: 'hours ago'} + ); + + should.deepEqual( + timeago.calcDisplay({ mills: now - times.days(5).msecs }, now) + , {value: 5, label: 'days ago'} + ); + + should.deepEqual( + timeago.calcDisplay({ mills: now - times.days(10).msecs }, now) + , {label: 'long ago'} + ); + }) + +}); \ No newline at end of file From 3c70b7fd173a164321621ea47799e74e1e648996 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 17 Oct 2015 01:15:14 -0700 Subject: [PATCH 0007/2594] get rid of extra Math.abs --- lib/plugins/timeago.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/timeago.js b/lib/plugins/timeago.js index f095aa17904..3b806168441 100644 --- a/lib/plugins/timeago.js +++ b/lib/plugins/timeago.js @@ -91,7 +91,7 @@ function init ( ) { return function checkIsLessThan (opts) { if (opts.timeSince < limit) { return { - value: Math.max(1, Math.round(Math.abs(opts.timeSince / divisor))) + value: Math.max(1, Math.round(opts.timeSince / divisor)) , label: label }; } From ded91d6f873f31c8036d43f17221b3a50953b456 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 17 Oct 2015 01:27:06 -0700 Subject: [PATCH 0008/2594] fix some codacy issues --- lib/plugins/timeago.js | 9 ++++----- tests/timeago.test.js | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/plugins/timeago.js b/lib/plugins/timeago.js index 3b806168441..2930c899964 100644 --- a/lib/plugins/timeago.js +++ b/lib/plugins/timeago.js @@ -1,6 +1,5 @@ 'use strict'; -var _ = require('lodash'); var levels = require('../levels'); var times = require('../times'); @@ -25,7 +24,7 @@ function init ( ) { } function isStale (mins) { - return sbx.time - lastSGVEntry.mills > times.mins(mins).msecs + return sbx.time - lastSGVEntry.mills > times.mins(mins).msecs; } function buildMessage(agoDisplay) { @@ -52,12 +51,12 @@ function init ( ) { sendAlarm({ level: levels.URGENT , pushoverSound: 'siren' - }) + }); } else if (warn && isStale(warnMins)) { sendAlarm({ level: levels.WARN - , pushoverSound: 'siren' - }) + , pushoverSound: 'echo' + }); } }; diff --git a/tests/timeago.test.js b/tests/timeago.test.js index 91006acb32f..85fbc4c55f1 100644 --- a/tests/timeago.test.js +++ b/tests/timeago.test.js @@ -5,7 +5,6 @@ var times = require('../lib/times'); describe('timeago', function ( ) { var timeago = require('../lib/plugins/timeago')(); - var delta = require('../lib/plugins/delta')(); var env = require('../env')(); var ctx = {}; @@ -114,6 +113,6 @@ describe('timeago', function ( ) { timeago.calcDisplay({ mills: now - times.days(10).msecs }, now) , {label: 'long ago'} ); - }) + }); }); \ No newline at end of file From 4699bbe9cee9b7c41c7cae1fde299a3e389b96f1 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 17 Oct 2015 14:41:53 -0700 Subject: [PATCH 0009/2594] fix tests, maybe? --- tests/timeago.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/timeago.test.js b/tests/timeago.test.js index 85fbc4c55f1..0f509cb87db 100644 --- a/tests/timeago.test.js +++ b/tests/timeago.test.js @@ -38,25 +38,25 @@ describe('timeago', function ( ) { it('should trigger a warning when data older than 15m', function (done) { ctx.notifications.initRequests(); - ctx.data.sgvs = [{mills: now - times.mins(15).msecs, mgdl: 100, type: 'sgv'}]; + ctx.data.sgvs = [{mills: now - times.mins(15.8).msecs, mgdl: 100, type: 'sgv'}]; var sbx = require('../lib/sandbox')().serverInit(env, ctx); timeago.checkNotifications(sbx); var highest = ctx.notifications.findHighestAlarm(); highest.level.should.equal(levels.WARN); - highest.message.should.equal('Last received: 15 mins ago\nBG Now: 100 mg/dl'); + highest.message.should.equal('Last received: 16 mins ago\nBG Now: 100 mg/dl'); done(); }); it('should trigger an urgent alarm when data older than 30m', function (done) { ctx.notifications.initRequests(); - ctx.data.sgvs = [{mills: now - times.mins(30).msecs, mgdl: 100, type: 'sgv'}]; + ctx.data.sgvs = [{mills: now - times.mins(30.8).msecs, mgdl: 100, type: 'sgv'}]; var sbx = require('../lib/sandbox')().serverInit(env, ctx); timeago.checkNotifications(sbx); var highest = ctx.notifications.findHighestAlarm(); highest.level.should.equal(levels.URGENT); - highest.message.should.equal('Last received: 30 mins ago\nBG Now: 100 mg/dl'); + highest.message.should.equal('Last received: 31 mins ago\nBG Now: 100 mg/dl'); done(); }); From 2d52b2ab8c8b8e95af8ef4b0a0d43b182f11bfe7 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Wed, 21 Oct 2015 00:15:02 -0700 Subject: [PATCH 0010/2594] use timeago plugin for the pill; remove the olg and ugly utils.timeAgo; still lots left --- lib/client/index.js | 64 +++++++++++++----------------------------- lib/plugins/index.js | 3 +- lib/plugins/timeago.js | 58 +++++++++++++++++++++++++++++--------- lib/settings.js | 2 +- lib/utils.js | 40 -------------------------- static/css/main.css | 9 +++--- static/index.html | 1 - tests/utils.test.js | 7 ----- 8 files changed, 73 insertions(+), 111 deletions(-) diff --git a/lib/client/index.js b/lib/client/index.js index 3121f92a62d..5b2247c30f0 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -53,6 +53,7 @@ client.init = function init(serverSettings, plugins) { client.sbx = sandbox.clientInit(client.settings, client.now); client.rawbg = plugins('rawbg'); client.delta = plugins('delta'); + client.timeago = plugins('timeago'); client.direction = plugins('direction'); client.errorcodes = plugins('errorcodes'); @@ -74,8 +75,6 @@ client.init = function init(serverSettings, plugins) { client.renderer = require('./renderer')(client, d3, $); client.careportal = require('./careportal')(client, $); - var timeAgo = client.utils.timeAgo; - var container = $('.container') , bgStatus = $('.bgStatus') , currentBG = $('.bgStatus .currentBG') @@ -131,10 +130,10 @@ client.init = function init(serverSettings, plugins) { var title = ''; - var time = client.latestSGV ? client.latestSGV.mills : (prevSGV ? prevSGV.mills : -1) - , ago = timeAgo(time); + var status = client.timeago.checkStatus(client.sbx); - if (ago && ago.status !== 'current') { + if (status !== 'current') { + var ago = client.timeago.calcDisplay(client.sbx.lastSGVEntry(), client.sbx.time); title = s(ago.value) + s(ago.label, ' - ') + title; } else if (client.latestSGV) { var currentMgdl = client.latestSGV.mgdl; @@ -253,8 +252,7 @@ client.init = function init(serverSettings, plugins) { function updateCurrentSGV (entry) { var value = entry.mgdl - , ago = timeAgo(entry.mills) - , isCurrent = ago.status === 'current'; + , isCurrent = 'current' === client.timeago.checkStatus(client.sbx); if (value === 9) { currentBG.text(''); @@ -499,66 +497,44 @@ client.init = function init(serverSettings, plugins) { return alarmType === 'warnTimeAgo' || alarmType === 'urgentTimeAgo'; } - function isStale (ago) { - return client.settings.alarmTimeagoWarn && ago.status === 'warn' - || client.settings.alarmTimeagoUrgent && ago.status === 'urgent'; + function isStale (status) { + return client.settings.alarmTimeagoWarn && status === 'warn' + || client.settings.alarmTimeagoUrgent && status === 'urgent'; } function notAcked (alarm) { return Date.now() >= (alarm.lastAckTime || 0) + (alarm.silenceTime || 0); } - function checkTimeAgoAlarm(ago) { - var level = ago.status - , alarm = getClientAlarm(level + 'TimeAgo'); + function checkTimeAgoAlarm (status) { + var alarm = getClientAlarm(status + 'TimeAgo'); - if (isStale(ago) && notAcked(alarm)) { + if (isStale(status) && notAcked(alarm)) { currentAlarmType = alarm.type; console.info('generating timeAgoAlarm', alarm.type); container.addClass('alarming-timeago'); + var display = client.timeago.calcDisplay(client.sbx.lastSGVEntry(), client.sbx.time); var notify = { - title: 'Last data received ' + [ago.value, ago.label].join(' ') - , level: level === 'urgent' ? 2 : 1 + title: 'Last data received ' + [display.value, display.label].join(' ') + , level: status === 'urgent' ? 2 : 1 }; - var sound = level === 'warn' ? alarmSound : urgentAlarmSound; + var sound = status === 'warn' ? alarmSound : urgentAlarmSound; generateAlarm(sound, notify); } - container.toggleClass('alarming-timeago', ago.status !== 'current'); + container.toggleClass('alarming-timeago', status !== 'current'); - if (alarmingNow() && ago.status === 'current' && isTimeAgoAlarmType(currentAlarmType)) { + if (alarmingNow() && status === 'current' && isTimeAgoAlarmType(currentAlarmType)) { stopAlarm(true, times.min().msecs); } } function updateTimeAgo() { - var lastEntry = $('#lastEntry') - , time = client.latestSGV ? client.latestSGV.mills : -1 - , ago = timeAgo(time) - , retroMode = inRetroMode(); - - function updateTimeAgoPill() { - if (retroMode || !ago.value) { - lastEntry.find('em').hide(); - } else { - lastEntry.find('em').show().text(ago.value); - } - if (retroMode || ago.label) { - lastEntry.find('label').show().text(retroMode ? 'RETRO' : ago.label); - } else { - lastEntry.find('label').hide(); - } - } - - lastEntry.removeClass('current warn urgent'); - lastEntry.addClass(ago.status); - - if (ago.status !== 'current') { + var status = client.timeago.checkStatus(client.sbx) + if (status !== 'current') { updateTitle(); } - checkTimeAgoAlarm(ago); - - updateTimeAgoPill(); + checkTimeAgoAlarm(status); } function updateTimeAgoSoon() { diff --git a/lib/plugins/index.js b/lib/plugins/index.js index b41fcecca3e..5b1a4396ec2 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -28,6 +28,7 @@ function init() { , require('./boluswizardpreview')() , require('./cannulaage')() , require('./basalprofile')() + , require('./timeago')() , require('./upbat')() ]; @@ -87,7 +88,7 @@ function init() { }; //these plugins are either always on or have custom settings - plugins.specialPlugins = 'ar2 delta direction upbat rawbg errorcodes'; + plugins.specialPlugins = 'ar2 delta direction timeago upbat rawbg errorcodes'; plugins.shownPlugins = function(sbx) { return _.filter(enabledPlugins, function filterPlugins(plugin) { diff --git a/lib/plugins/timeago.js b/lib/plugins/timeago.js index 2930c899964..25b69478573 100644 --- a/lib/plugins/timeago.js +++ b/lib/plugins/timeago.js @@ -8,25 +8,17 @@ function init ( ) { var timeago = { name: 'timeago' , label: 'Timeago' - , pluginType: 'notification' + , pluginType: 'pill-status' + , pillFlip: true }; timeago.checkNotifications = function checkNotifications (sbx) { - var lastSGVEntry = sbx.lastSGVEntry() - , warn = 'off' !== sbx.extendedSettings.warn - , warnMins = sbx.extendedSettings.warnMins || 15 - , urgent = 'off' !== sbx.extendedSettings.urgent - , urgentMins = sbx.extendedSettings.urgentMins || 30 - ; + var lastSGVEntry = sbx.lastSGVEntry(); if (!lastSGVEntry || lastSGVEntry.mills >= sbx.time) { return; } - function isStale (mins) { - return sbx.time - lastSGVEntry.mills > times.mins(mins).msecs; - } - function buildMessage(agoDisplay) { var lines = sbx.prepareDefaultLines(); lines.unshift('Last received: ' + [agoDisplay.value, agoDisplay.label].join(' ')); @@ -47,12 +39,13 @@ function init ( ) { }); } - if (urgent && isStale(urgentMins)) { + var status = timeago.checkStatus(sbx); + if (status === 'urgent') { sendAlarm({ level: levels.URGENT , pushoverSound: 'siren' }); - } else if (warn && isStale(warnMins)) { + } else if (status === 'warn') { sendAlarm({ level: levels.WARN , pushoverSound: 'echo' @@ -61,6 +54,33 @@ function init ( ) { }; + timeago.checkStatus = function checkStatus (sbx) { + + var lastSGVEntry = sbx.lastSGVEntry() + , warn = 'off' !== sbx.settings.alarmTimeagoWarn + , warnMins = sbx.settings.alarmTimeagoWarnMins || 15 + , urgent = 'off' !== sbx.settings.alarmTimeagoUrgent + , urgentMins = sbx.settings.alarmTimeagoUrgentMins || 30 + ; + + function isStale(mins) { + return sbx.time - lastSGVEntry.mills > times.mins(mins).msecs; + } + + var status = 'current'; + + if (!lastSGVEntry) { + //assume current + } else if (urgent && isStale(urgentMins)) { + status = 'urgent'; + } else if (warn && isStale(warnMins)) { + status = 'warn'; + } + + return status; + + }; + timeago.isMissing = function isMissing (opts) { if (!opts || !opts.entry || isNaN(opts.entry.mills) || isNaN(opts.time) || isNaN(opts.timeSince)) { return { @@ -128,6 +148,18 @@ function init ( ) { } }; + timeago.updateVisualisation = function updateVisualisation (sbx) { + var agoDisplay = timeago.calcDisplay(sbx.lastSGVEntry(), sbx.time); + var inRetroMode = sbx.data.inRetroMode; + var status = timeago.checkStatus(sbx); + + sbx.pluginBase.updatePillText(timeago, { + value: inRetroMode ? null : agoDisplay.value + , label: inRetroMode ? 'RETRO' : agoDisplay.label + , pillClass: status + }); + }; + return timeago; } diff --git a/lib/settings.js b/lib/settings.js index 7939790a851..6cb45db8393 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -76,7 +76,7 @@ function init ( ) { } //TODO: getting sent in status.json, shouldn't be - settings.DEFAULT_FEATURES = ['delta', 'direction', 'upbat', 'errorcodes']; + settings.DEFAULT_FEATURES = ['delta', 'direction', 'timeago', 'upbat', 'errorcodes']; var wasSet = []; diff --git a/lib/utils.js b/lib/utils.js index 8d7a51397e0..53317fcc817 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -34,46 +34,6 @@ function init(settings) { } }; - utils.timeAgo = function timeAgo(time) { - - var now = Date.now() - , offset = time === -1 ? -1 : (now - time) / 1000 - , parts = {}; - - if (offset < MINUTE_IN_SECS * -5) { - parts = { value: 'in the future' }; - } else if (offset === -1) { - parts = { label: 'time ago' }; - } else if (offset <= MINUTE_IN_SECS * 2) { - parts = { value: 1, label: 'min ago' }; - } else if (offset < (MINUTE_IN_SECS * 60)) { - parts = { value: Math.round(Math.abs(offset / MINUTE_IN_SECS)), label: 'mins ago' }; - } else if (offset < (HOUR_IN_SECS * 2)) { - parts = { value: 1, label: 'hr ago' }; - } else if (offset < (HOUR_IN_SECS * 24)) { - parts = { value: Math.round(Math.abs(offset / HOUR_IN_SECS)), label: 'hrs ago' }; - } else if (offset < DAY_IN_SECS) { - parts = { value: 1, label: 'day ago' }; - } else if (offset <= (DAY_IN_SECS * 7)) { - parts = { value: Math.round(Math.abs(offset / DAY_IN_SECS)), label: 'day ago' }; - } else { - parts = { value: 'long ago' }; - } - - if (offset > DAY_IN_SECS * 7) { - parts.status = 'warn'; - } else if (offset < MINUTE_IN_SECS * -5 || offset > (MINUTE_IN_SECS * settings.alarmTimeagoUrgentMins)) { - parts.status = 'urgent'; - } else if (offset > (MINUTE_IN_SECS * settings.alarmTimeagoWarnMins)) { - parts.status = 'warn'; - } else { - parts.status = 'current'; - } - - return parts; - - }; - // some helpers for input "date" utils.mergeInputTime = function mergeInputTime(timestring, datestring) { return moment(datestring + ' ' + timestring, 'YYYY-MM-D HH:mm'); diff --git a/static/css/main.css b/static/css/main.css index 7852c2ec954..99d08196107 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -138,17 +138,17 @@ body { color: red; } -.alarming-timeago #lastEntry.pill.warn { +.alarming-timeago .timeago.pill.warn { border-color: yellow; } -.alarming-timeago #lastEntry.pill.warn label { +.alarming-timeago .timeago.pill.warn label { background: yellow; } -.alarming-timeago #lastEntry.pill.urgent { +.alarming-timeago .timeago.pill.urgent { border-color: red; } -.alarming-timeago #lastEntry.pill.urgent label { +.alarming-timeago .timeago.pill.urgent label { background: red; } @@ -180,6 +180,7 @@ body { .statusPills .pill { background: #808080; border-color: #808080; + margin-right: 5px; } .statusPills .pill em { diff --git a/static/index.html b/static/index.html index c59d686d586..d14eb6b4078 100644 --- a/static/index.html +++ b/static/index.html @@ -61,7 +61,6 @@
---
-
diff --git a/tests/utils.test.js b/tests/utils.test.js index d107622070b..86ea7ea12a0 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -14,13 +14,6 @@ describe('utils', function ( ) { utils.toFixed(5.499999999).should.equal('5.50'); }); - it('show format recent times to 1 minute', function () { - var result = utils.timeAgo(Date.now() - 30000); - result.value.should.equal(1); - result.label.should.equal('min ago'); - result.status.should.equal('current'); - }); - it('merge date and time', function () { var result = utils.mergeInputTime('22:35', '2015-07-14'); result.hours().should.equal(22); From c099e5c3db91e41633977d4a6539de03b14b5973 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Wed, 21 Oct 2015 00:19:37 -0700 Subject: [PATCH 0011/2594] fix some missing ;'s --- lib/client/index.js | 2 +- lib/plugins/timeago.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client/index.js b/lib/client/index.js index 5b2247c30f0..afee88b9c3d 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -530,7 +530,7 @@ client.init = function init(serverSettings, plugins) { } function updateTimeAgo() { - var status = client.timeago.checkStatus(client.sbx) + var status = client.timeago.checkStatus(client.sbx); if (status !== 'current') { updateTitle(); } diff --git a/lib/plugins/timeago.js b/lib/plugins/timeago.js index 25b69478573..9fdc5e536c3 100644 --- a/lib/plugins/timeago.js +++ b/lib/plugins/timeago.js @@ -114,7 +114,7 @@ function init ( ) { , label: label }; } - } + }; }; timeago.resolvers = [ From eb128d122ed80a32bdb4c1c814060d2c40959b89 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Wed, 21 Oct 2015 00:27:51 -0700 Subject: [PATCH 0012/2594] clean up --- lib/utils.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 53317fcc817..509208ddfc6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -6,12 +6,7 @@ var units = require('./units')(); function init(settings) { - var utils = { - }; - - var MINUTE_IN_SECS = 60 - , HOUR_IN_SECS = 3600 - , DAY_IN_SECS = 86400; + var utils = { }; utils.scaleMgdl = function scaleMgdl (mgdl) { if (settings.units === 'mmol' && mgdl) { From 811104d277a834e18c6b0df041aedd8abf03c932 Mon Sep 17 00:00:00 2001 From: Ben West Date: Fri, 23 Oct 2015 14:04:18 -0700 Subject: [PATCH 0013/2594] increase upload limit --- lib/api/treatments/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/api/treatments/index.js b/lib/api/treatments/index.js index 65a7cccdba6..764dec74a16 100644 --- a/lib/api/treatments/index.js +++ b/lib/api/treatments/index.js @@ -11,9 +11,9 @@ function configure (app, wares, ctx) { // text body types get handled as raw buffer stream api.use(wares.bodyParser.raw( )); // json body types get handled as parsed json - api.use(wares.bodyParser.json( )); + api.use(wares.bodyParser.json({limit: '50mb'})); // also support url-encoded content-type - api.use(wares.bodyParser.urlencoded({ extended: true })); + api.use(wares.bodyParser.urlencoded({limit: '50mb', extended: true })); // List treatments available api.get('/treatments/', function(req, res) { From cc24cf05e3f92a138327903d431f378de0703f51 Mon Sep 17 00:00:00 2001 From: Ben West Date: Fri, 23 Oct 2015 14:11:01 -0700 Subject: [PATCH 0014/2594] squashing 10 commits getting it wrong * try again * try with compression * fix export * try 1MB limit * try with different version of body-parser * try limits again * try setting limit AGAIN * keep trying * try harder-er * try alternate verisno None of these attempts appeared fruitful, but hard to tell if they were required or not. --- app.js | 2 ++ lib/api/treatments/index.js | 16 +++++++++------- lib/middleware/index.js | 4 +++- package.json | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index fa807b81a5d..f893201786a 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ var express = require('express'); var compression = require('compression'); +var bodyParser = require('body-parser'); function create (env, ctx) { /////////////////////////////////////////////////// // api and json object variables @@ -17,6 +18,7 @@ function create (env, ctx) { // fallback to standard filter function return compression.filter(req, res); }})); + // app.use(bodyParser({limit: 1048576 * 50, extended: true })); //if (env.api_secret) { // console.log("API_SECRET", env.api_secret); diff --git a/lib/api/treatments/index.js b/lib/api/treatments/index.js index 764dec74a16..4afa0ee4407 100644 --- a/lib/api/treatments/index.js +++ b/lib/api/treatments/index.js @@ -6,14 +6,16 @@ function configure (app, wares, ctx) { var express = require('express'), api = express.Router( ); - // invoke common middleware - api.use(wares.sendJSONStatus); + api.use(wares.compression( )); + api.use(wares.bodyParser({limit: 1048576 * 50})); // text body types get handled as raw buffer stream - api.use(wares.bodyParser.raw( )); + api.use(wares.bodyParser.raw({limit: 1048576 })); // json body types get handled as parsed json - api.use(wares.bodyParser.json({limit: '50mb'})); + api.use(wares.bodyParser.json({limit: 1048576 })); // also support url-encoded content-type - api.use(wares.bodyParser.urlencoded({limit: '50mb', extended: true })); + api.use(wares.bodyParser.urlencoded({limit: 1048576 , extended: true })); + // invoke common middleware + api.use(wares.sendJSONStatus); // List treatments available api.get('/treatments/', function(req, res) { @@ -37,9 +39,9 @@ function configure (app, wares, ctx) { }); } if (app.settings.treatments_auth) { - api.post('/treatments/', wares.verifyAuthorization, post_response); + api.post('/treatments/', wares.bodyParser({limit: 1048576 * 50 }), wares.verifyAuthorization, post_response); } else { - api.post('/treatments/', post_response); + api.post('/treatments/', wares.bodyParser({limit: 1048576 * 50 }), post_response); } api.delete('/treatments/:_id', wares.verifyAuthorization, function(req, res) { ctx.treatments.remove(req.params._id, function ( ) { diff --git a/lib/middleware/index.js b/lib/middleware/index.js index 29255958a4c..8cdcb1b18b2 100644 --- a/lib/middleware/index.js +++ b/lib/middleware/index.js @@ -3,7 +3,8 @@ var wares = { verifyAuthorization : require('./verify-token'), sendJSONStatus : require('./send-json-status'), - bodyParser : require('body-parser') + bodyParser : require('body-parser'), + compression : require('compression') }; function extensions (list) { @@ -15,6 +16,7 @@ function configure (env) { verifyAuthorization: wares.verifyAuthorization(env), sendJSONStatus: wares.sendJSONStatus( ), bodyParser: wares.bodyParser, + compression: wares.compression, extensions: extensions }; } diff --git a/package.json b/package.json index bf3bda8540e..b8c44ad8f95 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "dependencies": { "async": "^0.9.0", - "body-parser": "^1.4.3", + "body-parser": "^1.14.1", "bootevent": "0.0.1", "bower": "^1.3.8", "browserify-express": "^0.1.4", @@ -74,9 +74,9 @@ "request": "^2.58.0", "sgvdata": "git://github.com/ktind/sgvdata.git#wip/protobuf", "share2nightscout-bridge": "git://github.com/bewest/share2nightscout-bridge.git#wip/generalize", + "simple-statistics": "~0.7.0", "socket.io": "^1.3.5", - "traverse": "^0.6.6", - "simple-statistics": "~0.7.0" + "traverse": "^0.6.6" }, "devDependencies": { "istanbul": "~0.3.5", From 5dc49692432229892613fb022c9aa176eb62f5ff Mon Sep 17 00:00:00 2001 From: Ben West Date: Fri, 23 Oct 2015 15:25:25 -0700 Subject: [PATCH 0015/2594] try at global level? --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index f893201786a..9618fde24ed 100644 --- a/app.js +++ b/app.js @@ -23,7 +23,7 @@ function create (env, ctx) { //if (env.api_secret) { // console.log("API_SECRET", env.api_secret); //} - app.use('/api/v1', api); + app.use('/api/v1', bodyParser({limit: 1048576 * 50 }), api); // pebble data From 75b84dd13f2f9dc89b506718716640208aa713ee Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Wed, 28 Oct 2015 22:56:57 -0700 Subject: [PATCH 0016/2594] pull the ticker and notifications into the client align client and server sandboxe inits some more update tests --- lib/bootevent.js | 2 +- lib/bus.js | 4 +- lib/client/index.js | 68 ++++++++++++++++++----------- lib/sandbox.js | 25 +++++++---- tests/basalprofileplugin.test.js | 15 ++++--- tests/boluswizardpreview.test.js | 42 ++++++++++-------- tests/cannulaage.test.js | 32 ++++++++------ tests/cob.test.js | 16 +++---- tests/delta.test.js | 75 +++++++++++++++++++++----------- tests/direction.test.js | 8 +++- tests/rawbg.test.js | 10 +++-- tests/sandbox.test.js | 22 +++++----- tests/upbat.test.js | 49 +++++++++++++-------- 13 files changed, 222 insertions(+), 146 deletions(-) diff --git a/lib/bootevent.js b/lib/bootevent.js index 2e2665dfa33..3b946bead04 100644 --- a/lib/bootevent.js +++ b/lib/bootevent.js @@ -31,7 +31,7 @@ function boot (env) { ctx.devicestatus = require('./devicestatus')(env.devicestatus_collection, ctx); ctx.profile = require('./profile')(env.profile_collection, ctx); ctx.pebble = require('./pebble')(env, ctx); - ctx.bus = require('./bus')(env, ctx); + ctx.bus = require('./bus')(env.settings, ctx); ctx.data = require('./data')(env, ctx); ctx.notifications = require('./notifications')(env, ctx); diff --git a/lib/bus.js b/lib/bus.js index 11dd7337939..5828130fa92 100644 --- a/lib/bus.js +++ b/lib/bus.js @@ -2,10 +2,10 @@ var Stream = require('stream'); -function init (env) { +function init (settings) { var beats = 0; var started = new Date( ); - var interval = env.settings.heartbeat * 1000; + var interval = settings.heartbeat * 1000; var stream = new Stream; diff --git a/lib/client/index.js b/lib/client/index.js index 2a3f012e179..d2cb82ac967 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -28,7 +28,6 @@ client.init = function init(serverSettings, plugins) { , isInitialData = false , SGVdata = [] , MBGdata = [] - , latestUpdateTime , prevSGV , devicestatusData , opacity = {current: 1, DAY: 1, NIGHT: 0.5} @@ -47,11 +46,34 @@ client.init = function init(serverSettings, plugins) { client.forecastTime = times.mins(30).msecs; client.data = []; client.browserUtils = require('./browser-utils')($); - client.settings = require('./browser-settings')(client, plugins, serverSettings, $); - client.utils = require('../utils')(client.settings); client.ticks = require('./ticks'); - client.sbx = sandbox.clientInit(client.settings, client.now); + //containers + var container = $('.container') + , bgStatus = $('.bgStatus') + , currentBG = $('.bgStatus .currentBG') + , majorPills = $('.bgStatus .majorPills') + , minorPills = $('.bgStatus .minorPills') + , statusPills = $('.status .statusPills') + ; + + client.tooltip = d3.select('body').append('div') + .attr('class', 'tooltip') + .style('opacity', 0); + + client.settings = require('./browser-settings')(client, plugins, serverSettings, $); + + client.ctx = { + data: {} + , bus: require('../bus')(client.settings, client.ctx) + , settings: client.settings + , notifications: require('../notifications')(client.settings, client.ctx) + , pluginBase: plugins.base(majorPills, minorPills, statusPills, bgStatus, client.tooltip, $.localStorage) + }; + + client.utils = require('../utils')(client.ctx.settings); + + client.sbx = sandbox.clientInit(client.ctx, client.now); client.rawbg = plugins('rawbg'); client.delta = plugins('delta'); client.timeago = plugins('timeago'); @@ -64,10 +86,6 @@ client.init = function init(serverSettings, plugins) { client.hashauth = require('../hashauth'); client.hashauth.init(client, $).initAuthentication(); - client.tooltip = d3.select('body').append('div') - .attr('class', 'tooltip') - .style('opacity', 0); - client.foucusRangeMS = times.hours(3).msecs; client.brushed = brushed; client.formatTime = formatTime; @@ -76,13 +94,11 @@ client.init = function init(serverSettings, plugins) { client.renderer = require('./renderer')(client, d3, $); client.careportal = require('./careportal')(client, $); - var container = $('.container') - , bgStatus = $('.bgStatus') - , currentBG = $('.bgStatus .currentBG') - , majorPills = $('.bgStatus .majorPills') - , minorPills = $('.bgStatus .minorPills') - , statusPills = $('.status .statusPills') - ; + client.ctx.bus.on('tick', function timedReload (tick) { + console.info('tick', tick.now); + }); + + client.ctx.bus.uptime( ); client.dataExtent = function dataExtent ( ) { return client.data.length > 0 ? @@ -271,19 +287,19 @@ client.init = function init(serverSettings, plugins) { } function updatePlugins (sgvs, time) { - var pluginBase = plugins.base(majorPills, minorPills, statusPills, bgStatus, client.tooltip, $.localStorage); client.sbx = sandbox.clientInit( - client.settings + client.ctx , new Date(time).getTime() //make sure we send a timestamp - , pluginBase, { - sgvs: sgvs - , cals: [client.cal] - , treatments: client.treatments - , profile: profile - , uploaderBattery: devicestatusData && devicestatusData.uploaderBattery - , inRetroMode: inRetroMode() - }); + , { + sgvs: sgvs + , cals: [client.cal] + , treatments: client.treatments + , profile: profile + , uploaderBattery: devicestatusData && devicestatusData.uploaderBattery + , inRetroMode: inRetroMode() + } + ); //all enabled plugins get a chance to set properties, even if they aren't shown plugins.setProperties(client.sbx); @@ -835,7 +851,7 @@ client.init = function init(serverSettings, plugins) { if (d.sgvs) { // change the next line so that it uses the prediction if the signal gets lost (max 1/2 hr) - latestUpdateTime = Date.now(); + client.ctx.data.lastUpdated = Date.now(); client.latestSGV = SGVdata[SGVdata.length - 1]; prevSGV = SGVdata[SGVdata.length - 2]; } diff --git a/lib/sandbox.js b/lib/sandbox.js index 12f1e8ce6a8..53d236b8c87 100644 --- a/lib/sandbox.js +++ b/lib/sandbox.js @@ -24,6 +24,16 @@ function init ( ) { return sbx2; } + /** + * A view into the safe notification functions for plugins + * + * @param ctx + * @returns {{notification}} + */ + function safeNotifications (ctx) { + return _.pick(ctx.notifications, ['requestNotify', 'requestSnooze', 'requestClear']); + } + /** * Initialize the sandbox using server state * @@ -37,9 +47,7 @@ function init ( ) { sbx.time = Date.now(); sbx.settings = env.settings; sbx.data = ctx.data.clone(); - - //don't expose all of notifications, ctx.notifications will decide what to do after all plugins chime in - sbx.notifications = _.pick(ctx.notifications, ['levels', 'requestNotify', 'requestSnooze', 'requestClear']); + sbx.notifications = safeNotifications(ctx); var profile = require('./profilefunctions')(); //Plugins will expect the right profile based on time @@ -67,14 +75,15 @@ function init ( ) { * @param data - svgs, treatments, profile, etc * @returns {{sbx}} */ - sbx.clientInit = function clientInit (settings, time, pluginBase, data) { + sbx.clientInit = function clientInit (ctx, time, data) { reset(); - sbx.settings = settings; - sbx.showPlugins = settings.showPlugins; + sbx.settings = ctx.settings; + sbx.showPlugins = ctx.showPlugins; sbx.time = time; sbx.data = data; - sbx.pluginBase = pluginBase; + sbx.pluginBase = ctx.pluginBase; + sbx.notifications = safeNotifications(ctx); if (sbx.pluginBase) { sbx.pluginBase.forecastPoints = []; @@ -82,7 +91,7 @@ function init ( ) { sbx.extendedSettings = {empty: true}; sbx.withExtendedSettings = function getPluginExtendedSettingsOnly (plugin) { - return withExtendedSettings(plugin, settings.extendedSettings, sbx); + return withExtendedSettings(plugin, sbx.settings.extendedSettings, sbx); }; extend(); diff --git a/tests/basalprofileplugin.test.js b/tests/basalprofileplugin.test.js index 2d1b354350b..964d92f4c60 100644 --- a/tests/basalprofileplugin.test.js +++ b/tests/basalprofileplugin.test.js @@ -50,20 +50,21 @@ describe('basalprofile', function ( ) { var profile = require('../lib/profilefunctions')([profileData]); it('update basal profile pill', function (done) { - - var clientSettings = {}; var data = {}; - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.value.should.equal('0.175U'); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText(plugin, options) { + options.value.should.equal('0.175U'); + done(); + } } }; var time = new Date('2015-06-21T00:00:00').getTime(); - var sbx = sandbox.clientInit(clientSettings, time, pluginBase, data); + var sbx = sandbox.clientInit(ctx, time, data); sbx.data.profile = profile; basal.updateVisualisation(sbx); diff --git a/tests/boluswizardpreview.test.js b/tests/boluswizardpreview.test.js index 3954342e1c1..317ea0084fe 100644 --- a/tests/boluswizardpreview.test.js +++ b/tests/boluswizardpreview.test.js @@ -129,12 +129,16 @@ describe('boluswizardpreview', function ( ) { }; var sandbox = require('../lib/sandbox')(); - var pluginBase = {}; - var clientSettings = { units: 'mmol' }; + var ctx = { + settings: { + units: 'mmol' + } + , pluginBase: {} + }; var data = {sgvs: [{mills: before, mgdl: 100}, {mills: now, mgdl: 100}]}; data.treatments = [{mills: now, insulin: '1.0'}]; data.profile = require('../lib/profilefunctions')([profileData]); - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); var iob = require('../lib/plugins/iob')(); sbx.properties.iob = iob.calcTotal(data.treatments, data.profile, now); @@ -165,12 +169,16 @@ describe('boluswizardpreview', function ( ) { }; var sandbox = require('../lib/sandbox')(); - var pluginBase = {}; - var clientSettings = { units: 'mmol' }; + var ctx = { + settings: { + units: 'mmol' + } + , pluginBase: {} + }; var data = {sgvs: [{mills: before, mgdl: 175}, {mills: now, mgdl: 153}]}; data.treatments = [{mills: now, insulin: '0.45'}]; data.profile = require('../lib/profilefunctions')([profileData]); - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); var iob = require('../lib/plugins/iob')(); sbx.properties.iob = iob.calcTotal(data.treatments, data.profile, now); @@ -257,16 +265,17 @@ describe('boluswizardpreview', function ( ) { }); it('set a pill to the BWP with infos', function (done) { - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.label.should.equal('BWP'); - options.value.should.equal('0.50U'); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText(plugin, options) { + options.label.should.equal('BWP'); + options.value.should.equal('0.50U'); + done(); + } } }; - var clientSettings = {}; - var loadedProfile = require('../lib/profilefunctions')(); loadedProfile.loadData([profile]); @@ -276,16 +285,11 @@ describe('boluswizardpreview', function ( ) { , profile: loadedProfile }; - var sbx = require('../lib/sandbox')().clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = require('../lib/sandbox')().clientInit(ctx, Date.now(), data); iob.setProperties(sbx); boluswizardpreview.setProperties(sbx); boluswizardpreview.updateVisualisation(sbx); - - ctx.notifications.resetStateForTests(); - ctx.notifications.initRequests(); - ctx.data.profiles = [profile]; - }); }); \ No newline at end of file diff --git a/tests/cannulaage.test.js b/tests/cannulaage.test.js index 60ecdfd4281..68509fd466f 100644 --- a/tests/cannulaage.test.js +++ b/tests/cannulaage.test.js @@ -21,8 +21,6 @@ describe('cage', function ( ) { it('set a pill to the current cannula age', function (done) { - var clientSettings = {}; - var data = { treatments: [ {eventType: 'Site Change', notes: 'Foo', mills: Date.now() - 48 * 60 * 60000} @@ -30,15 +28,18 @@ describe('cage', function ( ) { ] }; - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.value.should.equal('24h'); - options.info[1].value.should.equal('Bar'); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText(plugin, options) { + options.value.should.equal('24h'); + options.info[1].value.should.equal('Bar'); + done(); + } } }; - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); cage.updateVisualisation(sbx); }); @@ -54,15 +55,18 @@ describe('cage', function ( ) { ] }; - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.value.should.equal('0h'); - options.info.length.should.equal(1); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText(plugin, options) { + options.value.should.equal('0h'); + options.info.length.should.equal(1); + done(); + } } }; - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); cage.updateVisualisation(sbx); }); diff --git a/tests/cob.test.js b/tests/cob.test.js index 336dffe41b3..9f424012782 100644 --- a/tests/cob.test.js +++ b/tests/cob.test.js @@ -64,9 +64,6 @@ describe('COB', function ( ) { }); it('set a pill to the current COB', function (done) { - - var clientSettings = {}; - var data = { treatments: [{ carbs: '8' @@ -75,15 +72,18 @@ describe('COB', function ( ) { , profile: profile }; - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.value.should.equal('8g'); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText (plugin, options) { + options.value.should.equal('8g'); + done(); + } } }; var sandbox = require('../lib/sandbox')(); - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); cob.setProperties(sbx); cob.updateVisualisation(sbx); diff --git a/tests/delta.test.js b/tests/delta.test.js index cd250d499d5..c82cc5a3c6e 100644 --- a/tests/delta.test.js +++ b/tests/delta.test.js @@ -10,24 +10,24 @@ describe('Delta', function ( ) { var delta = require('../lib/plugins/delta')(); var sandbox = require('../lib/sandbox')(); - var pluginBase = {}; var now = Date.now(); var before = now - FIVE_MINS; it('should calculate BG Delta', function (done) { - var clientSettings = { units: 'mg/dl' }; - var data = {sgvs: [{mills: before, mgdl: 100}, {mills: now, mgdl: 105}]}; - - var callbackPluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.label.should.equal(clientSettings.units); - options.value.should.equal('+5'); - options.info.length.should.equal(0); - done(); + var ctx = { + settings: { units: 'mg/dl' } + , pluginBase: { + updatePillText: function mockedUpdatePillText (plugin, options) { + options.label.should.equal(ctx.settings.units); + options.value.should.equal('+5'); + options.info.length.should.equal(0); + done(); + } } }; + var data = {sgvs: [{mills: before, mgdl: 100}, {mills: now, mgdl: 105}]}; - var sbx = sandbox.clientInit(clientSettings, Date.now(), callbackPluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); delta.setProperties(sbx); @@ -44,18 +44,23 @@ describe('Delta', function ( ) { var clientSettings = { units: 'mg/dl' }; var data = {sgvs: [{mills: before - SIX_MINS, mgdl: 100}, {mills: now, mgdl: 105}]}; - var callbackPluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.label.should.equal(clientSettings.units); - options.value.should.equal('+2 *'); - findInfoValue('Elapsed Time', options.info).should.equal('11 mins'); - findInfoValue('Absolute Delta', options.info).should.equal('5 mg/dl'); - findInfoValue('Interpolated', options.info).should.equal('103 mg/dl'); - done(); + var ctx = { + settings: { + units: 'mg/dl' + } + , pluginBase: { + updatePillText: function mockedUpdatePillText(plugin, options) { + options.label.should.equal(ctx.settings.units); + options.value.should.equal('+2 *'); + findInfoValue('Elapsed Time', options.info).should.equal('11 mins'); + findInfoValue('Absolute Delta', options.info).should.equal('5 mg/dl'); + findInfoValue('Interpolated', options.info).should.equal('103 mg/dl'); + done(); + } } }; - var sbx = sandbox.clientInit(clientSettings, Date.now(), callbackPluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); delta.setProperties(sbx); @@ -69,9 +74,15 @@ describe('Delta', function ( ) { }); it('should calculate BG Delta in mmol', function (done) { - var clientSettings = { units: 'mmol' }; + var ctx = { + settings: { + units: 'mmol' + } + , pluginBase: {} + }; + var data = {sgvs: [{mills: before, mgdl: 100}, {mills: now, mgdl: 105}]}; - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); sbx.offerProperty = function mockedOfferProperty (name, setter) { name.should.equal('delta'); @@ -87,9 +98,15 @@ describe('Delta', function ( ) { }); it('should calculate BG Delta in mmol and not show a change because of rounding', function (done) { - var clientSettings = { units: 'mmol' }; + var ctx = { + settings: { + units: 'mmol' + } + , pluginBase: {} + }; + var data = {sgvs: [{mills: before, mgdl: 85}, {mills: now, mgdl: 85}]}; - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); sbx.offerProperty = function mockedOfferProperty (name, setter) { name.should.equal('delta'); @@ -105,9 +122,15 @@ describe('Delta', function ( ) { }); it('should calculate BG Delta in mmol by interpolating when more than 5mins apart', function (done) { - var clientSettings = { units: 'mmol' }; + var ctx = { + settings: { + units: 'mmol' + } + , pluginBase: {} + }; + var data = {sgvs: [{mills: before - SIX_MINS, mgdl: 100}, {mills: now, mgdl: 105}]}; - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); sbx.offerProperty = function mockedOfferProperty (name, setter) { name.should.equal('delta'); diff --git a/tests/direction.test.js b/tests/direction.test.js index bf421795d01..d7890714970 100644 --- a/tests/direction.test.js +++ b/tests/direction.test.js @@ -4,10 +4,14 @@ require('should'); describe('BG direction', function ( ) { function setupSandbox(data, pluginBase) { - var clientSettings = {}; + var ctx = { + settings: {} + , pluginBase: pluginBase || {} + }; + var sandbox = require('../lib/sandbox')(); - return sandbox.clientInit(clientSettings, Date.now(), pluginBase || {}, data); + return sandbox.clientInit(ctx, Date.now(), data); } it('set the direction property - Flat', function (done) { diff --git a/tests/rawbg.test.js b/tests/rawbg.test.js index 135525ca149..b252f7b1b32 100644 --- a/tests/rawbg.test.js +++ b/tests/rawbg.test.js @@ -7,17 +7,19 @@ describe('Raw BG', function ( ) { var sandbox = require('../lib/sandbox')(); var now = Date.now(); - var pluginBase = {}; var data = { sgvs: [{unfiltered: 113680, filtered: 111232, mgdl: 110, noise: 1, mills: now}] , cals: [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, mills: now}] }; - var clientSettings = { - units: 'mg/dl' + var ctx = { + settings: { + units: 'mg/dl' + } + , pluginBase: {} }; it('should calculate Raw BG', function (done) { - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); sbx.offerProperty = function mockedOfferProperty (name, setter) { name.should.equal('rawbg'); diff --git a/tests/sandbox.test.js b/tests/sandbox.test.js index b6c491d85a6..e6d0ab5b094 100644 --- a/tests/sandbox.test.js +++ b/tests/sandbox.test.js @@ -6,22 +6,24 @@ describe('sandbox', function ( ) { var now = Date.now(); it('init on client', function (done) { - var clientSettings = { - units: 'mg/dl' - , thresholds:{ - bgHigh: 260 - , bgTargetTop: 180 - , bgTargetBottom: 80 - , bgLow: 55 + var ctx = { + settings: { + units: 'mg/dl' + , thresholds:{ + bgHigh: 260 + , bgTargetTop: 180 + , bgTargetBottom: 80 + , bgLow: 55 + } } + , pluginBase: {} }; - var pluginBase = {}; var data = {sgvs: [{mgdl: 100, mills: now}]}; - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); - sbx.pluginBase.should.equal(pluginBase); + sbx.pluginBase.should.equal(ctx.pluginBase); sbx.data.should.equal(data); sbx.lastSGVMgdl().should.equal(100); diff --git a/tests/upbat.test.js b/tests/upbat.test.js index 27f227f7f19..26e39d46646 100644 --- a/tests/upbat.test.js +++ b/tests/upbat.test.js @@ -4,11 +4,13 @@ require('should'); describe('Uploader Battery', function ( ) { var data = {uploaderBattery: 20}; - var clientSettings = {}; it('display uploader battery status', function (done) { var sandbox = require('../lib/sandbox')(); - var sbx = sandbox.clientInit(clientSettings, Date.now(), {}, data); + var ctx = { + settings: {} + }; + var sbx = sandbox.clientInit(ctx, Date.now(), data); sbx.offerProperty = function mockedOfferProperty (name, setter) { name.should.equal('upbat'); @@ -26,17 +28,20 @@ describe('Uploader Battery', function ( ) { }); it('set a pill to the uploader battery status', function (done) { - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.value.should.equal('20%'); - options.labelClass.should.equal('icon-battery-25'); - options.pillClass.should.equal('urgent'); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText(plugin, options) { + options.value.should.equal('20%'); + options.labelClass.should.equal('icon-battery-25'); + options.pillClass.should.equal('urgent'); + done(); + } } }; var sandbox = require('../lib/sandbox')(); - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, data); + var sbx = sandbox.clientInit(ctx, Date.now(), data); var upbat = require('../lib/plugins/upbat')(); upbat.setProperties(sbx); upbat.updateVisualisation(sbx); @@ -44,30 +49,36 @@ describe('Uploader Battery', function ( ) { }); it('hide the pill if there is no uploader battery status', function (done) { - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.hide.should.equal(true); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText (plugin, options) { + options.hide.should.equal(true); + done(); + } } }; var sandbox = require('../lib/sandbox')(); - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, {}); + var sbx = sandbox.clientInit(ctx, Date.now(), {}); var upbat = require('../lib/plugins/upbat')(); upbat.setProperties(sbx); upbat.updateVisualisation(sbx); }); it('hide the pill if there is uploader battery status is -1', function (done) { - var pluginBase = { - updatePillText: function mockedUpdatePillText (plugin, options) { - options.hide.should.equal(true); - done(); + var ctx = { + settings: {} + , pluginBase: { + updatePillText: function mockedUpdatePillText(plugin, options) { + options.hide.should.equal(true); + done(); + } } }; var sandbox = require('../lib/sandbox')(); - var sbx = sandbox.clientInit(clientSettings, Date.now(), pluginBase, {uploaderBattery: -1}); + var sbx = sandbox.clientInit(ctx, Date.now(), {uploaderBattery: -1}); var upbat = require('../lib/plugins/upbat')(); upbat.setProperties(sbx); upbat.updateVisualisation(sbx); From a1ef18d3a12acc8bbb89e9a8f4ee523b41ce7f6e Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Fri, 30 Oct 2015 00:18:26 -0700 Subject: [PATCH 0017/2594] adjust inputMatrix --- lib/client/careportal.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/client/careportal.js b/lib/client/careportal.js index a1d0b4d6839..30d87098e9f 100644 --- a/lib/client/careportal.js +++ b/lib/client/careportal.js @@ -57,7 +57,7 @@ function init (client, $) { careportal.filterInputs = function filterInputs ( event ) { var inputMatrix = { - '': { bg: true, insulin: true, carbs: true, prebolus: true, duration: false, percent: false, absolute: false } + '': { bg: true, insulin: true, carbs: true, prebolus: false, duration: false, percent: false, absolute: false } , 'BG Check': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } , 'Snack Bolus': { bg: true, insulin: true, carbs: true, prebolus: true, duration: false, percent: false, absolute: false } , 'Meal Bolus': { bg: true, insulin: true, carbs: true, prebolus: true, duration: false, percent: false, absolute: false } @@ -67,10 +67,10 @@ function init (client, $) { , 'Note': { bg: true, insulin: false, carbs: false, prebolus: false, duration: true, percent: false, absolute: false } , 'Question': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } , 'Exercise': { bg: false, insulin: false, carbs: false, prebolus: false, duration: true, percent: false, absolute: false } - , 'Site Change': { bg: false, insulin: true, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } - , 'Sensor Start': { bg: false, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } - , 'Sensor Change': { bg: false, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } - , 'Insulin Change': { bg: false, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } + , 'Site Change': { bg: true, insulin: true, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } + , 'Sensor Start': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } + , 'Sensor Change': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } + , 'Insulin Change': { bg: true, insulin: true, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } , 'Temp Basal Start': { bg: true, insulin: false, carbs: false, prebolus: false, duration: true, percent: true, absolute: true } , 'Temp Basal End': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } , 'D.A.D. Alert': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false } From 108e68b6394edcf1f1c07c5a9d1f0edae170b70b Mon Sep 17 00:00:00 2001 From: adriansolcan Date: Sat, 31 Oct 2015 08:27:24 +0200 Subject: [PATCH 0018/2594] RO update Oct, 31 2015 RO update Oct, 31 2015 --- lib/language.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/language.js b/lib/language.js index 1c8bb9b9cf6..f0480b253b1 100644 --- a/lib/language.js +++ b/lib/language.js @@ -2798,6 +2798,7 @@ function init() { } ,'Logarithmic (Dynamic)' : { it: 'Logaritmica (Dinamica)' + ,ro: 'Logaritmic (Dinamic)' } ,'Silence for 30 minutes' : { cs: 'Ztlumit na 30 minut' @@ -4364,6 +4365,7 @@ function init() { ,'Loading temp basal data' : { cs: 'Nahrávám dočasné bazály' ,it: 'Caricamento basale temporanea' + ,ro: 'Se încarcă date bazală temporară' } }; From 0e91a7cdb5493a13825b9c67e3e2df198ff14362 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 31 Oct 2015 10:05:37 -0700 Subject: [PATCH 0019/2594] adjust tooltip left to prevent it from going off the screen --- lib/client/renderer.js | 15 +++++++++++---- lib/plugins/pluginbase.js | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/client/renderer.js b/lib/client/renderer.js index c5c92086c7c..854bb9fc3f7 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -7,6 +7,7 @@ var DEFAULT_FOCUS = times.hours(3).msecs , WIDTH_SMALL_DOTS = 420 , WIDTH_BIG_DOTS = 800 , TOOLTIP_TRANS_MS = 200 // milliseconds + , TOOLTIP_WIDTH = 150 //min-width + padding ; function init (client, d3) { @@ -38,6 +39,12 @@ function init (client, d3) { return radius / focusRangeAdjustment(); }; + function tooltipLeft ( ) { + var windowWidth = $(client.tooltip).parent().parent().width(); + var left = d3.event.pageX + TOOLTIP_WIDTH < windowWidth ? d3.event.pageX : windowWidth - TOOLTIP_WIDTH - 10; + return left + 'px' + } + function hideTooltip ( ) { client.tooltip.transition() .duration(TOOLTIP_TRANS_MS) @@ -147,7 +154,7 @@ function init (client, d3) { (rawbgInfo.value ? '
' + translate('Raw BG') + ': ' + rawbgInfo.value : '') + (rawbgInfo.noise ? '
' + translate('Noise') + ': ' + rawbgInfo.noise : '') + '
' + translate('Time') + ': ' + client.formatTime(new Date(d.mills))) - .style('left', (d3.event.pageX) + 'px') + .style('left', tooltipLeft()) .style('top', (d3.event.pageY + 15) + 'px'); } @@ -232,7 +239,7 @@ function init (client, d3) { .on('mouseover', function (d) { client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9); client.tooltip.html(d.isAnnouncement ? announcementTooltip(d) : treatmentTooltip(d)) - .style('left', (d3.event.pageX) + 'px') + .style('left', tooltipLeft()) .style('top', (d3.event.pageY + 15) + 'px'); }) .on('mouseout', hideTooltip); @@ -280,7 +287,7 @@ function init (client, d3) { .on('mouseover', function (d) { client.tooltip.transition().duration(TOOLTIP_TRANS_MS).style('opacity', .9); client.tooltip.html(d.isAnnouncement ? announcementTooltip(d) : treatmentTooltip(d)) - .style('left', (d3.event.pageX) + 'px') + .style('left', tooltipLeft()) .style('top', (d3.event.pageY + 15) + 'px'); }) .on('mouseout', hideTooltip); @@ -420,7 +427,7 @@ function init (client, d3) { (treatment.enteredBy ? '' + translate('Entered By') + ': ' + treatment.enteredBy + '
' : '') + (treatment.notes ? '' + translate('Notes') + ': ' + treatment.notes : '') ) - .style('left', (d3.event.pageX) + 'px') + .style('left', tooltipLeft()) .style('top', (d3.event.pageY + 15) + 'px'); } diff --git a/lib/plugins/pluginbase.js b/lib/plugins/pluginbase.js index eed09d50f32..400a5a1fc6b 100644 --- a/lib/plugins/pluginbase.js +++ b/lib/plugins/pluginbase.js @@ -2,7 +2,7 @@ var _ = require('lodash'); -var TOOLTIP_WIDTH = 250; //min-width + padding +var TOOLTIP_WIDTH = 275; //min-width + padding function init (majorPills, minorPills, statusPills, bgStatus, tooltip) { @@ -85,7 +85,7 @@ function init (majorPills, minorPills, statusPills, bgStatus, tooltip) { tooltip.transition().duration(200).style('opacity', .9); var windowWidth = $(tooltip).parent().parent().width(); - var left = event.pageX + TOOLTIP_WIDTH < windowWidth ? event.pageX : windowWidth - TOOLTIP_WIDTH; + var left = event.pageX + TOOLTIP_WIDTH < windowWidth ? event.pageX : windowWidth - TOOLTIP_WIDTH - 10; tooltip.html(html) .style('left', left + 'px') .style('top', (event.pageY + 15) + 'px'); From cd61375ec0ab25d27b4a5a298764d88fb3f787c2 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 31 Oct 2015 10:07:34 -0700 Subject: [PATCH 0020/2594] version bump to 0.8.2 --- bower.json | 2 +- package.json | 2 +- static/index.html | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index b51c0e2cdad..57c271450a2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "nightscout", - "version": "0.8.2-beta2", + "version": "0.8.2", "dependencies": { "jquery": "2.1.0", "jQuery-Storage-API": "~1.7.2", diff --git a/package.json b/package.json index cb508bd42ea..cb232d95fd5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Nightscout", - "version": "0.8.2-beta2", + "version": "0.8.2", "description": "Nightscout acts as a web-based CGM (Continuous Glucose Montinor) to allow multiple caregivers to remotely view a patients glucose data in realtime.", "license": "AGPL-3.0", "author": "Nightscout Team", diff --git a/static/index.html b/static/index.html index cb024fe5b6c..90ae04c73ae 100644 --- a/static/index.html +++ b/static/index.html @@ -25,10 +25,10 @@ - - + + - + @@ -284,8 +284,8 @@ - - + + From 65d9ee4d1ac9bcce0be432982d070e59cc4f2c93 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Sun, 1 Nov 2015 16:58:14 +0100 Subject: [PATCH 0021/2594] codacy --- lib/client/renderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/renderer.js b/lib/client/renderer.js index 3e36d014250..45acc98d20a 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -42,7 +42,7 @@ function init (client, d3) { function tooltipLeft ( ) { var windowWidth = $(client.tooltip).parent().parent().width(); var left = d3.event.pageX + TOOLTIP_WIDTH < windowWidth ? d3.event.pageX : windowWidth - TOOLTIP_WIDTH - 10; - return left + 'px' + return left + 'px'; } function hideTooltip ( ) { From f1294d818ee154652fa1b4d1023905686e927bd9 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Sun, 1 Nov 2015 22:34:32 +0100 Subject: [PATCH 0022/2594] make prefiltered treatments available in sbx --- lib/client/index.js | 28 +++++++++++++++++++--------- lib/client/renderer.js | 2 +- lib/report_plugins/daytoday.js | 4 ++-- static/report/js/report.js | 4 ++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/client/index.js b/lib/client/index.js index 8db328840e0..d428abd6936 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -1,4 +1,5 @@ 'use strict'; +'use strict'; var _ = require('lodash'); var $ = (global && global.$) || require('jquery'); @@ -285,6 +286,10 @@ client.init = function init(serverSettings, plugins) { sgvs: sgvs , cals: [client.cal] , treatments: client.treatments + , tempbasalTreatments: client.tempbasalTreatments + , profileTreatments: client.profileTreatments + , sitechangeTreatments: client.sitechangeTreatments + , sensorTreatments: client.sensorTreatments , profile: profile , uploaderBattery: devicestatusData && devicestatusData.uploaderBattery , inRetroMode: inRetroMode() @@ -817,23 +822,28 @@ client.init = function init(serverSettings, plugins) { MBGdata = mergeDataUpdate(d.delta,MBGdata, d.mbgs); client.treatments = mergeDataUpdate(d.delta, client.treatments, d.treatments); + // filter & prepare 'Site Change' events + client.sitechangeTreatments = client.treatments.filter( function filterSensor(t) { + return t.eventType.indexOf('Site Change') > -1; + }).sort(function (a,b) { return a.mills > b.mills; }); + // filter & prepare 'Sensor' events - client.sensortreatments = client.treatments.filter( function filterSensor(t) { + client.sensorTreatments = client.treatments.filter( function filterSensor(t) { return t.eventType.indexOf('Sensor') > -1; }).sort(function (a,b) { return a.mills > b.mills; }); // filter & prepare 'Profile Switch' events - client.profiletreatments = client.treatments.filter( function filterProfiles(t) { + client.profileTreatments = client.treatments.filter( function filterProfiles(t) { return t.eventType === 'Profile Switch'; }).sort(function (a,b) { return a.mills > b.mills; }); // filter & prepare temp basals - var tempbasaltreatments = client.treatments.filter( function filterBasals(t) { + var tempbasalTreatments = client.treatments.filter( function filterBasals(t) { return t.eventType && t.eventType.indexOf('Temp Basal') > -1; }); // cut temp basals by end events // better to do it only on data update - var endevents = tempbasaltreatments.filter(function filterEnd(t) { + var endevents = tempbasalTreatments.filter(function filterEnd(t) { return ! t.duration; }); @@ -844,26 +854,26 @@ client.init = function init(serverSettings, plugins) { } // cut by end events - tempbasaltreatments.forEach(function allTreatments(t) { + tempbasalTreatments.forEach(function allTreatments(t) { endevents.forEach(function allEndevents(e) { cutIfInInterval(t, e); }); }); // cut by overlaping events - tempbasaltreatments.forEach(function allTreatments(t) { - tempbasaltreatments.forEach(function allEndevents(e) { + tempbasalTreatments.forEach(function allTreatments(t) { + tempbasalTreatments.forEach(function allEndevents(e) { cutIfInInterval(t, e); }); }); // store prepared temp basal treatments - client.tempbasaltreatments = tempbasaltreatments.filter(function filterEnd(t) { + client.tempbasalTreatments = tempbasalTreatments.filter(function filterEnd(t) { return t.duration; }); // Resend new treatments to profile - client.profilefunctions.updateTreatments(client.profiletreatments, client.tempbasaltreatments); + client.profilefunctions.updateTreatments(client.profileTreatments, client.tempbasalTreatments); // Do some reporting on the console diff --git a/lib/client/renderer.js b/lib/client/renderer.js index 45acc98d20a..8a7f4efe634 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -623,7 +623,7 @@ function init (client, d3) { .attr('d', area); //console.log(tempbasals); - client.tempbasaltreatments.forEach(function (t) { + client.tempbasalTreatments.forEach(function (t) { // only if basal and focus interval overlap and there is a chance to fit if (t.mills < to && t.mills + times.mins(t.duration).msecs > from) { var text = g.append('text') diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index 5f35e3bf9a7..9a9b2345908 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -257,7 +257,7 @@ daytoday.report = function report_daytoday(datastorage,sorteddaystoshow,options) var lastbasal = 0; var basals = context.append('g'); - profile.updateTreatments([], datastorage.tempbasaltreatments); + profile.updateTreatments([], datastorage.tempbasalTreatments); for (var dt=moment(from); dt < to; dt.add(5, 'minutes')) { if (options.iob) { @@ -362,7 +362,7 @@ daytoday.report = function report_daytoday(datastorage,sorteddaystoshow,options) .attr('stroke-width', 1) .attr('d', area); - datastorage.tempbasaltreatments.forEach(function (t) { + datastorage.tempbasalTreatments.forEach(function (t) { // only if basal and focus interval overlap and there is a chance to fit if (t.mills < to.format('x') && t.mills + times.mins(t.duration).msecs > from.format('x')) { var text = g.append('text') diff --git a/static/report/js/report.js b/static/report/js/report.js index 3cae18ca326..910da6e26d0 100644 --- a/static/report/js/report.js +++ b/static/report/js/report.js @@ -583,8 +583,8 @@ treatment.mills = timestamp.getTime(); return treatment; }); - datastorage.tempbasaltreatments = treatmentData.slice(); - datastorage.tempbasaltreatments.sort(function(a, b) { return a.mills - b.mills; }); + datastorage.tempbasalTreatments = treatmentData.slice(); + datastorage.tempbasalTreatments.sort(function(a, b) { return a.mills - b.mills; }); } }).done(function () { callback(); From 5ceeedfabb8b2cda1c9e7b1143a3c937d72fd071 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Sun, 1 Nov 2015 22:40:44 +0100 Subject: [PATCH 0023/2594] fix iob,cob curves in reports --- lib/report_plugins/daytoday.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index 9a9b2345908..f53f832a344 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -262,14 +262,14 @@ daytoday.report = function report_daytoday(datastorage,sorteddaystoshow,options) for (var dt=moment(from); dt < to; dt.add(5, 'minutes')) { if (options.iob) { var iob = Nightscout.plugins('iob').calcTotal(data.treatments,profile,dt.toDate()).iob; - if (dt!==from) { + if (!dt.isSame(from)) { iobpolyline += ', '; } iobpolyline += (xScale2(dt) + padding.left) + ',' + (yInsulinScale(iob) + padding.top) + ' '; } if (options.cob) { var cob = Nightscout.plugins('cob').cobTotal(data.treatments,profile,dt.toDate()).cob; - if (dt!==from) { + if (!dt.isSame(from)) { cobpolyline += ', '; } cobpolyline += (xScale2(dt.toDate()) + padding.left) + ',' + (yCarbsScale(cob) + padding.top) + ' '; From 02dfd9df962e2ea8a1ee90a0f8a8a8dee58a2f78 Mon Sep 17 00:00:00 2001 From: bogdangorescu Date: Mon, 2 Nov 2015 12:29:32 +0200 Subject: [PATCH 0024/2594] RO update Nov, 2 2015 Update Romanian --- lib/language.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index a255acffd26..42c18882fd5 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4443,7 +4443,7 @@ function init() { ,'Find and remove treatments in the future' : { cs: 'Najít a odstranit záznamy ošetření v budoucnosti' ,nb: 'Finn og fjern fremtidige behandlinger' - ,ro: 'Caută și elimină tratamente din viiotr' + ,ro: 'Caută și elimină tratamente din viitor' ,bg: 'Намери и премахни събития в бъдещето' ,it: 'Individuare e rimuovere le somministrazioni (prossimamente)' } @@ -4678,87 +4678,117 @@ function init() { } ,'Save current record before changing to new?' : { cs: 'Uložit současný záznam před změnou na nový?' + ,ro: 'Salvez înregistrarea curentă înainte de a trece mai departe?' } ,'Profile Switch' : { cs: 'Přepnutí profilu' + ,ro: 'Schimbă profilul' } ,'Profile' : { cs: 'Profil' + ,ro: 'Profil' } ,'General profile settings' : { cs: 'Obecná nastavení profilu' + ,ro: 'Setări generale profil' } ,'Title' : { cs: 'Název' + ,ro: 'Titlu' } ,'Database records' : { cs: 'Záznamy v databázi' + ,ro: 'Înregistrări' } ,'Add new record' : { cs: 'Přidat nový záznam' + ,ro: 'Adaugă înregistrare nouă' } ,'Remove this record' : { cs: 'Vymazat tento záznam' + ,ro: 'Șterge această înregistrare' } ,'Clone this record to new' : { cs: 'Zkopíruj tento záznam do nového' + ,ro: 'Duplică această înregistrare' } ,'Record valid from' : { cs: 'Záznam platný od' + ,ro: 'Înregistarea validă de la' } ,'Stored profiles' : { cs: 'Uložené profily' + ,ro: 'Profile salvate' } ,'Timezone' : { cs: 'Časová zóna' + ,ro: 'Fus orar' } ,'Duration of Insulin Activity (DIA)' : { cs: 'Doba působnosti inzulínu (DIA)' + ,ro: 'Durata de acțiune a insulinei' } ,'Represents the typical duration over which insulin takes effect. Varies per patient and per insulin type. Typically 3-4 hours for most pumped insulin and most patients. Sometimes also called insulin lifetime.' : { cs: 'Představuje typickou dobu, po kterou inzulín působí. Bývá různá podle pacienta a inzulínu. Typicky 3-4 hodiny pro pacienty s pumpou.' + ,ro: 'Reprezintă durata tipică pentru care insulina are efect. Este diferită la fiecare pacient și pentru fiecare tip de insulină' + + + } ,'Insulin to carb ratio (I:C)' : { cs: 'Inzulíno-sacharidový poměr (I:C).' + ,ro: 'Rată insulină la carbohidrați (ICR)' } ,'hours' : { cs: 'hodiny' + ,ro: 'ore' } ,'g/hour' : { cs: 'g/hod' + ,ro: 'g/oră' } ,'g carbs per U insulin. The ratio of how many grams of carbohydrates are offset by each U of insulin.' : { cs: 'gramy na jednotku inzulínu. Poměr, jaké množství sacharidů pokryje jednotku inzulínu.' + ,ro: 'g carbohidrați pentru o unitate de insulină. Câte grame de carbohidrați sunt acoperite de 1U insulină.' } ,'Insulin Sensitivity Factor (ISF)' : { cs: 'Citlivost inzulínu (ISF)' + ,ro: 'Factor de sensilibtate la insulină (ISF)' } ,'mg/dL or mmol/L per U insulin. The ratio of how much BG changes with each U of corrective insulin.' : { cs: 'mg/dL nebo mmol/L na jednotku inzulínu. Poměr, jak se změní glykémie po podaní jednotky inzulínu' + ,ro: 'mg/dL sau mmol/L pentru 1U insulină. Cât de mult influențează glicemia o corecție de o unitate de insulină.' } ,'Carbs activity / absorption rate' : { cs: 'Rychlost absorbce sacharidů' + ,ro: 'Rata de absorbție' } ,'grams per unit time. Represents both the change in COB per unit of time, as well as the amount of carbs that should take effect over that time. Carb absorption / activity curves are less well understood than insulin activity, but can be approximated using an initial delay followed by a constant rate of absorption (g/hr).' : { cs: 'gramy za jednotku času. Reprezentuje jak změnu COB za jednoku času, tak množství sacharidů, které se za tu dobu projevily. Křivka absorbce sacharidů je mnohem méně pochopitelná než IOB, ale může být aproximována počáteční pauzou následovanou konstantní hodnotou absorbce (g/hod).' + ,ro: 'grame pe unitatea de timp. Reprezintă atât schimbarea COB pe unitatea de timp, cât și cantitatea de carbohidrați care ar influența în perioada de timp. Graficele ratei de absorbție sunt mai puțin înțelese decât senzitivitatea la insulină, dar se poate aproxima folosind o întârziere implicită și apoi o rată constantă de aborbție (g/h).' } ,'Basal rates [unit/hour]' : { cs: 'Bazály [U/hod].' + ,ro: 'Rata bazală [unitate/oră]' } ,'Target BG range [mg/dL,mmol/L]' : { cs: 'Cílový rozsah glykémií [mg/dL,mmol/L]' + ,ro: 'Intervalul țintă al glicemiei [mg/dL, mmol/L]' } ,'Start of record validity' : { cs: 'Začátek platnosti záznamu' + ,ro: 'De când este valabilă înregistrarea' } ,'Icicle' : { cs: 'Rampouch' + ,ro: 'Țurțure' } ,'Render Basal' : { cs: 'Zobrazení bazálu' + ,ro: 'Afișează bazala' } ,'Profile used' : { cs: 'Použitý profil' + ,ro: 'Profilul folosit' } }; From 73adaf268ad18d53dfd274133c94d8932ca67f8c Mon Sep 17 00:00:00 2001 From: bogdangorescu Date: Mon, 2 Nov 2015 13:22:20 +0200 Subject: [PATCH 0025/2594] RO update Nov, 2 2015 - v2 Added a missing semicolon --- lib/language.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index 42c18882fd5..99f76c9e3a8 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4788,7 +4788,7 @@ function init() { } ,'Profile used' : { cs: 'Použitý profil' - ,ro: 'Profilul folosit' + ,ro: 'Profil folosit' } }; From 946683b535755e231c737fb8eec353686f28f87c Mon Sep 17 00:00:00 2001 From: bogdangorescu Date: Mon, 2 Nov 2015 13:32:25 +0200 Subject: [PATCH 0026/2594] RO update Nov, 2 2015 - v3 Found the problem with the missing semicolon --- lib/language.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/language.js b/lib/language.js index 99f76c9e3a8..d82252574c5 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4731,8 +4731,6 @@ function init() { ,'Represents the typical duration over which insulin takes effect. Varies per patient and per insulin type. Typically 3-4 hours for most pumped insulin and most patients. Sometimes also called insulin lifetime.' : { cs: 'Představuje typickou dobu, po kterou inzulín působí. Bývá různá podle pacienta a inzulínu. Typicky 3-4 hodiny pro pacienty s pumpou.' ,ro: 'Reprezintă durata tipică pentru care insulina are efect. Este diferită la fiecare pacient și pentru fiecare tip de insulină' - - + } ,'Insulin to carb ratio (I:C)' : { cs: 'Inzulíno-sacharidový poměr (I:C).' From 4ee1a49147aaf50a6a42a936c1703c00a41ce31b Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Mon, 2 Nov 2015 18:37:30 +0100 Subject: [PATCH 0027/2594] better handling 0 basal values --- lib/client/careportal.js | 6 +++--- lib/report_plugins/treatments.js | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/client/careportal.js b/lib/client/careportal.js index 81a2ed792cc..e5a7e73b4d2 100644 --- a/lib/client/careportal.js +++ b/lib/client/careportal.js @@ -119,8 +119,8 @@ function init (client, $) { $('#eventType').append(''); }); $('#eventType').change(careportal.filterInputs); - $('#percent').change(careportal.filterInputs); - $('#absolute').change(careportal.filterInputs); + $('#percent').on('input', careportal.filterInputs); + $('#absolute').on('input', careportal.filterInputs); careportal.filterInputs(); }; @@ -217,7 +217,7 @@ function init (client, $) { pushIf(data.insulin, translate('Insulin Given') + ': ' + data.insulin); pushIf(data.duration, translate('Duration') + ': ' + data.duration); pushIf(data.percent, translate('Percent') + ': ' + data.percent); - pushIf(data.absolute, translate('Basal value') + ': ' + data.absolute); + pushIf('absolute' in data, translate('Basal value') + ': ' + data.absolute); pushIf(data.profile, translate('Profile') + ': ' + data.profile); pushIf(data.preBolus, translate('Carb Time') + ': ' + data.preBolus + ' ' + translate('mins')); pushIf(data.notes, translate('Notes') + ': ' + data.notes); diff --git a/lib/report_plugins/treatments.js b/lib/report_plugins/treatments.js index c37768d0a8a..6ec52807b41 100644 --- a/lib/report_plugins/treatments.js +++ b/lib/report_plugins/treatments.js @@ -117,7 +117,7 @@ treatments.report = function report_treatments(datastorage, sorteddaystoshow, op pushIf(data.insulin, translate('Insulin Given') + ': ' + data.insulin); pushIf(data.duration, translate('Duration') + ': ' + data.duration); pushIf(data.percent, translate('Percent') + ': ' + data.percent); - pushIf(data.absolute, translate('Basal value') + ': ' + data.absolute); + pushIf(!isNaN(data.absolute), translate('Basal value') + ': ' + data.absolute); pushIf(data.preBolus, translate('Carb Time') + ': ' + data.preBolus + ' ' + translate('mins')); pushIf(data.notes, translate('Notes') + ': ' + data.notes); pushIf(data.enteredBy, translate('Entered By') + ': ' + data.enteredBy); @@ -197,6 +197,9 @@ treatments.report = function report_treatments(datastorage, sorteddaystoshow, op data.units = options.units; delete data.mills; delete data.created_at; + if (data.absolute === '') { + delete data.absolute; + } $( this ).dialog('close'); saveTreatmentRecord(data); delete datastorage[day]; @@ -220,7 +223,7 @@ treatments.report = function report_treatments(datastorage, sorteddaystoshow, op $('#rped_insulinGiven').val(data.insulin ? data.insulin : ''); $('#rped_duration').val(data.duration ? data.duration : ''); $('#rped_percent').val(data.percent ? data.percent : ''); - $('#rped_absolute').val(data.absolute ? data.absolute : ''); + $('#rped_absolute').val('absolute' in data ? data.absolute : ''); $('#rped_profile').val(data.profile ? data.profile : ''); $('#rped_adnotes').val(data.notes ? data.notes : ''); $('#rped_enteredBy').val(data.enteredBy ? data.enteredBy : ''); @@ -311,7 +314,7 @@ treatments.report = function report_treatments(datastorage, sorteddaystoshow, op .append($('').attr('align','center').append(tr.carbs ? tr.carbs : '')) .append($('').attr('align','center').append(tr.duration ? tr.duration : '')) .append($('').attr('align','center').append(tr.percent ? tr.percent : '')) - .append($('').attr('align','center').append(tr.absolute ? tr.absolute : '')) + .append($('').attr('align','center').append('absolute' in tr ? tr.absolute : '')) .append($('').attr('align','center').append(tr.profile ? tr.profile : '')) .append($('').append(tr.enteredBy ? tr.enteredBy : '')) .append($('').append(tr.notes ? tr.notes : '')) From 098e80f7a481ac155a8a532586bca83faebc904c Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Mon, 2 Nov 2015 18:48:19 +0100 Subject: [PATCH 0028/2594] show duration in exercise tooltip --- lib/client/renderer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/client/renderer.js b/lib/client/renderer.js index 8a7f4efe634..f928db17312 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -178,6 +178,7 @@ function init (client, d3) { (d.eventType ? ''+translate('Treatment type')+': ' + translate(client.careportal.resolveEventName(d.eventType)) + '
' : '') + (d.glucose ? ''+translate('BG')+': ' + d.glucose + (d.glucoseType ? ' (' + translate(d.glucoseType) + ')': '') + '
' : '') + (d.enteredBy ? ''+translate('Entered By')+': ' + d.enteredBy + '
' : '') + + (d.duration ? ''+translate('Duration')+': ' + d.duration + ' min
' : '') + (d.notes ? ''+translate('Notes')+': ' + d.notes : ''); } From 1e262957917b542b12558f60fb5628fedc5e89a4 Mon Sep 17 00:00:00 2001 From: Matteo Neri Date: Mon, 2 Nov 2015 19:39:51 +0100 Subject: [PATCH 0029/2594] Update language Italian.0.9.0.js partially updated. Matteo --- lib/language.js | 53 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/lib/language.js b/lib/language.js index f0480b253b1..bcfc02d084d 100644 --- a/lib/language.js +++ b/lib/language.js @@ -660,7 +660,7 @@ function init() { ,ro: 'Încarc baza de date de alimente' ,bg: 'Зареждане на данни с храни' ,hr: 'Učitavanje baze podataka o hrani' - ,it: 'Carico dati alimenti' + ,it: 'Carico database alimenti' ,dk: 'Indlæser mad database' ,fi: 'Lataan ruokatietokantaa' ,nb: 'Leser matdatabase' @@ -1503,7 +1503,7 @@ function init() { ,ro: 'CI' ,bg: 'ГИ' ,hr: 'GI' - ,it: 'GI' + ,it: 'IG-Indice Glicemico' ,dk: 'GI' ,fi: 'GI' ,nb: 'GI' @@ -1674,7 +1674,7 @@ function init() { ,bg: 'Редактор за храна' ,hr: 'Editor hrane' ,sv: 'Födoämneseditor' - ,it: 'Modifica alimenti' + ,it: 'NS - Database Alimenti' ,dk: 'Mad editor' ,fi: 'Muokkaa ruokia' ,nb: 'Mat editor' @@ -1831,7 +1831,7 @@ function init() { ,ro: 'Tratamente' ,bg: 'Събития' ,hr: 'Tretmani' - ,it: 'Somministrazione' + ,it: 'Somministrazioni' ,dk: 'Behandling' ,fi: 'Hoitotoimenpiteet' ,nb: 'Behandlinger' @@ -2515,7 +2515,7 @@ function init() { ,ro: 'Editare profil' ,bg: 'Редактор на профила' ,hr: 'Editor profila' - ,it: 'NS - Dati personali' + ,it: 'NS - Dati Personali' ,dk: 'Profil editor' ,fi: 'Profiilin muokkaus' ,nb: 'Profileditor' @@ -2621,7 +2621,7 @@ function init() { ,ro: 'Dispozitiv autentificat' ,bg: 'Устройстово е разпознато' ,hr: 'Uređaj autenticiran' - ,it: 'Dispositivo autenticato' + ,it: 'Disp. autenticato' ,dk: 'Enhed godkendt' ,fi: 'Laite autentikoitu' ,nb: 'Enhet godkjent' @@ -2636,7 +2636,7 @@ function init() { ,ro: 'Dispozitiv neautentificat' ,bg: 'Устройсройството не е разпознато' ,hr: 'Uređaj nije autenticiran' - ,it: 'Dispositivo non autenticato' + ,it: 'Disp. non autenticato' ,dk: 'Enhed ikke godkendt' ,fi: 'Laite ei ole autentikoitu' ,nb: 'Enhet ikke godkjent' @@ -2800,6 +2800,39 @@ function init() { it: 'Logaritmica (Dinamica)' ,ro: 'Logaritmic (Dinamic)' } + ,'Render Basal' : { + it: 'Grafico Basale' + } + ,'Icicle' : { + it: 'Inverso' + } + ,'Care Portal' : { + it: 'Somministrazioni' + } + ,'Profile' : { + it: 'Profilo' + } + ,'Insulin-on-Board' : { + it: 'IOB-Insulina a Bordo' + } + ,'Carbs-on-Board' : { + it: 'COB-Carboidrati a Bordo' + } + ,'Bolus Wizard Preview' : { + it: 'BWP-Calcolatore di bolo' + } + ,'Bolus Wizard' : { + it: 'BW-Calcolatore di bolo' + } + ,'Value Loaded' : { + it: 'Valori Caricati' + } + ,'Cannula Age' : { + it: 'CAGE-Cambio Ago' + } + ,'Basal Profile' : { + it: 'BASAL-Profilo Basale' + } ,'Silence for 30 minutes' : { cs: 'Ztlumit na 30 minut' ,de: 'Ausschalten für 30 Minuten' @@ -3005,7 +3038,7 @@ function init() { ,bg: 'Въвеждане на събитие' ,hr: 'Evidencija tretmana' ,sv: 'Ange händelse' - ,it: 'Somministrazione' + ,it: 'Somministrazioni' ,dk: 'Log en hændelse' ,fi: 'Tallenna tapahtuma' ,nb: 'Logg en hendelse' @@ -3149,7 +3182,7 @@ function init() { ,ro: 'Schimbare loc pompă' ,bg: 'Смяна на сет' ,hr: 'Promjena seta' - ,it: '(CAGE) Cambio Ago' + ,it: 'CAGE-Cambio Ago' ,dk: 'Skift insulin infusionssted' ,fi: 'Pumpun kanyylin vaihto' ,nb: 'Pumpebytte' @@ -3739,7 +3772,7 @@ function init() { ,ro: 'Calculator sugestie bolus' ,bg: 'Болус съветник ' ,hr: 'Bolus wizard' - ,it: 'Calcolatore di Bolo' + ,it: 'BW-Calcolatore di Bolo' ,dk: 'Bolusberegner' ,fi: 'Annosopas' ,nb: 'Boluskalkulator' From f80e70bd4c9d5b6e2e691504db95b25aa62faa78 Mon Sep 17 00:00:00 2001 From: Matteo Neri Date: Mon, 2 Nov 2015 19:59:59 +0100 Subject: [PATCH 0030/2594] Update language Italian.0.9.0.js correct --- lib/language.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/language.js b/lib/language.js index bcfc02d084d..061b651c13b 100644 --- a/lib/language.js +++ b/lib/language.js @@ -2821,9 +2821,6 @@ function init() { ,'Bolus Wizard Preview' : { it: 'BWP-Calcolatore di bolo' } - ,'Bolus Wizard' : { - it: 'BW-Calcolatore di bolo' - } ,'Value Loaded' : { it: 'Valori Caricati' } From 8b695cb87a57010446c43d3bb3320e4b19a47490 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Mon, 2 Nov 2015 21:11:38 +0100 Subject: [PATCH 0031/2594] travis fix & cs translation --- lib/language.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/language.js b/lib/language.js index 7f2ebb0b427..05650edb758 100644 --- a/lib/language.js +++ b/lib/language.js @@ -2996,35 +2996,28 @@ function init() { ,it: 'Logaritmica (Dinamica)' ,ro: 'Logaritmic (Dinamic)' } - ,'Render Basal' : { - it: 'Grafico Basale' - } - ,'Icicle' : { - it: 'Inverso' - } - ,'Care Portal' : { - it: 'Somministrazioni' - } - ,'Profile' : { - it: 'Profilo' - } ,'Insulin-on-Board' : { - it: 'IOB-Insulina a Bordo' + cs: 'IOB' + ,it: 'IOB-Insulina a Bordo' } ,'Carbs-on-Board' : { - it: 'COB-Carboidrati a Bordo' + cs: 'COB' + ,it: 'COB-Carboidrati a Bordo' } ,'Bolus Wizard Preview' : { - it: 'BWP-Calcolatore di bolo' + cs: 'BWP-Náhled bolusového kalk.' + ,it: 'BWP-Calcolatore di bolo' } ,'Value Loaded' : { it: 'Valori Caricati' } ,'Cannula Age' : { - it: 'CAGE-Cambio Ago' + cs: 'CAGE-Stáří kanyly' + ,it: 'CAGE-Cambio Ago' } ,'Basal Profile' : { - it: 'BASAL-Profilo Basale' + cs: 'Bazál' + ,it: 'BASAL-Profilo Basale' } ,'Silence for 30 minutes' : { cs: 'Ztlumit na 30 minut' @@ -4412,6 +4405,7 @@ function init() { } ,'Care Portal' : { cs: 'Portál ošetření' + ,it: 'Somministrazioni' } ,'Medium/Unknown' : { // GI of food cs: 'Střední/Neznámá' @@ -4716,6 +4710,7 @@ function init() { } ,'Profile' : { cs: 'Profil' + ,it: 'Profilo' ,ro: 'Profil' } ,'General profile settings' : { @@ -4808,10 +4803,12 @@ function init() { } ,'Icicle' : { cs: 'Rampouch' + ,it: 'Inverso' ,ro: 'Țurțure' } ,'Render Basal' : { cs: 'Zobrazení bazálu' + ,it: 'Grafico Basale' ,ro: 'Afișează bazala' } ,'Profile used' : { From da206a37db755bdb63b0258443c0f510cef1cbbe Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 2 Nov 2015 17:25:13 -0800 Subject: [PATCH 0032/2594] codacy; --- lib/client/renderer.js | 2 +- static/profile/js/profileeditor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client/renderer.js b/lib/client/renderer.js index f928db17312..38a13c194cf 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -697,7 +697,7 @@ function init (client, d3) { .attr('dy', '.35em') .attr('transform', function (t) { return 'rotate(-90 ' + chart().xScale(t.mills) + ',' + chart().yScaleBasals(topOfText) + ') ' + - 'translate(' + chart().xScale(t.mills) + ',' + chart().yScaleBasals(topOfText) + ')' + 'translate(' + chart().xScale(t.mills) + ',' + chart().yScaleBasals(topOfText) + ')'; }) .text(function (t) { var sign = t.first ? '↑↑↑' : '---'; diff --git a/static/profile/js/profileeditor.js b/static/profile/js/profileeditor.js index 43c5af2478d..ec956cdf85d 100644 --- a/static/profile/js/profileeditor.js +++ b/static/profile/js/profileeditor.js @@ -326,7 +326,7 @@ var record = mongorecords[currentrecord]; var newname = 'New profile'; while (record.store[newname]) { - newname += '1' + newname += '1'; } record.store[newname] = _.cloneDeep(defaultprofile); currentprofile = newname; From 293bfa861cedb58dbe7bcea9062469e8faf0609e Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 2 Nov 2015 17:32:56 -0800 Subject: [PATCH 0033/2594] codacy;; --- lib/client/boluscalc.js | 2 +- static/profile/js/profileeditor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index 9bb21f5a31d..93469febce9 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -442,7 +442,7 @@ function init(client, $, plugins) { console.log('Insulin calculation result: ',record); return record; - } + }; function gatherData ( ) { var data = {}; diff --git a/static/profile/js/profileeditor.js b/static/profile/js/profileeditor.js index ec956cdf85d..d962ca66e17 100644 --- a/static/profile/js/profileeditor.js +++ b/static/profile/js/profileeditor.js @@ -356,7 +356,7 @@ var record = mongorecords[currentrecord]; var newname = $('#pe_profile_name').val() + ' (copy)'; while (record.store[newname]) { - newname += '1' + newname += '1'; } record.store[newname] = _.cloneDeep(record.store[currentprofile]); currentprofile = newname; From 26e3dc7cbb6666f3054e16cfc9a31e7bb56a7436 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 2 Nov 2015 17:37:07 -0800 Subject: [PATCH 0034/2594] codacy;;; --- lib/client/boluscalc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index 93469febce9..e4c73043766 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -484,7 +484,7 @@ function init(client, $, plugins) { } maybePrevent(event); return false; - } + }; function buildConfirmText(data) { var text = [ From 35fe512148a6c245375d66bd0b5b9502490c44dd Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 2 Nov 2015 18:26:24 -0800 Subject: [PATCH 0035/2594] codacy;;;; --- lib/client/boluscalc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index e4c73043766..1c2a175e97b 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -613,7 +613,7 @@ function init(client, $, plugins) { } }).done(function() { if (callback) { callback(); } }); maybePrevent(event); - } + }; boluscalc.loadFoodQuickpicks = function loadFoodQuickpicks( ) { // Load quickpicks @@ -762,6 +762,6 @@ function init(client, $, plugins) { setDateAndTime(); return boluscalc; -}; +} module.exports = init; \ No newline at end of file From cc62d436f2ddc38245f0e1f3f22b8a635bc691dd Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Tue, 3 Nov 2015 18:18:51 +0100 Subject: [PATCH 0036/2594] make food database optional (enable=food) --- lib/client/index.js | 2 ++ static/index.html | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/client/index.js b/lib/client/index.js index d428abd6936..637da1a1b31 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -777,6 +777,8 @@ client.init = function init(serverSettings, plugins) { } $('#treatmentDrawerToggle').toggle(client.settings.showPlugins.indexOf('careportal') > -1); $('#boluscalcDrawerToggle').toggle(client.settings.showPlugins.indexOf('boluscalc') > -1); + // hide food control if not enabled + $('.foodcontrol').toggle(client.settings.enable.indexOf('food') > -1); container.toggleClass('has-minor-pills', plugins.hasShownType('pill-minor', client.settings)); function prepareData ( ) { diff --git a/static/index.html b/static/index.html index f34ef4259a9..1a12d1e6b85 100644 --- a/static/index.html +++ b/static/index.html @@ -83,7 +83,7 @@
@@ -331,7 +331,7 @@ - + Quickpick:
From 3f038a422d48acd89791ae36635ac441618ef13c Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Tue, 3 Nov 2015 20:35:25 +0100 Subject: [PATCH 0037/2594] Calculation is in range message --- lib/client/boluscalc.js | 17 +++++++++++++---- lib/language.js | 3 +++ static/index.html | 7 +++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index 9bb21f5a31d..6edd2b2c1c8 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -291,22 +291,31 @@ function init(client, $, plugins) { $('#bc_rouding').text(record.roundingcorrection.toFixed(2)); $('#bc_insulintotal').text(record.insulin.toFixed(2)); - // Carbs needed if too much iob - if (record.insulin<0) { + // Carbs needed if too much iob or in range message when nothing entered and in range + var outcome = record.bg - record.insulin * isf; + if (record.othercorrection === 0 && record.carbs === 0 && record.cob === 0 && outcome > targetBGLow && outcome < targetBGHigh) { + $('#bc_carbsneeded').text(''); + $('#bc_insulinover').text(''); + $('#bc_carbsneededtr').css('display','none'); + $('#bc_insulinneededtr').css('display','none'); + $('#bc_calculationintarget').css('display',''); + } else if (record.insulin<0) { $('#bc_carbsneeded').text(record.carbsneeded+' g'); $('#bc_insulinover').text(record.insulin.toFixed(2)); $('#bc_carbsneededtr').css('display',''); $('#bc_insulinneededtr').css('display','none'); + $('#bc_calculationintarget').css('display','none'); } else { $('#bc_carbsneeded').text(''); $('#bc_insulinover').text(''); $('#bc_carbsneededtr').css('display','none'); $('#bc_insulinneededtr').css('display',''); + $('#bc_calculationintarget').css('display','none'); } // Show basal rate var basal = client.sbx.data.profile.getTempBasal(record.eventTime); - $('#bc_basal').text((basal.treatment ? 'T ' : '') + basal.tempbasal.toFixed(3)); + $('#bc_basal').text((basal.treatment ? 'T: ' : '') + basal.tempbasal.toFixed(3)); }; boluscalc.gatherBoluscalcData = function gatherBoluscalcData() { @@ -437,7 +446,7 @@ function init(client, $, plugins) { // Carbs needed if too much iob record.carbsneeded = 0; if (record.insulin<0) { - record.carbsneeded = Math.round(-total * ic); + record.carbsneeded = Math.ceil(-total * ic); } console.log('Insulin calculation result: ',record); diff --git a/lib/language.js b/lib/language.js index d82252574c5..af96ceeefd1 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4788,6 +4788,9 @@ function init() { cs: 'Použitý profil' ,ro: 'Profil folosit' } + ,'Calculation is in target range.' : { + cs: 'Kalkulace je v cílovém rozsahu.' + } }; diff --git a/static/index.html b/static/index.html index 1a12d1e6b85..8a055699a65 100644 --- a/static/index.html +++ b/static/index.html @@ -448,6 +448,13 @@ 0.00 + + + + + Calculation is in target range. + + From 756949d45d5fcef5adc490951bfdeff03fbd8d09 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Thu, 5 Nov 2015 17:08:22 +0100 Subject: [PATCH 0038/2594] use prefiltered array in canulaage plugin --- lib/plugins/cannulaage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/cannulaage.js b/lib/plugins/cannulaage.js index 400e7e6794b..dfb5cff4c4b 100644 --- a/lib/plugins/cannulaage.js +++ b/lib/plugins/cannulaage.js @@ -64,9 +64,9 @@ cage.findLatestTimeChange = function findLatestTimeChange(sbx) { var prevDate = 0; - _.each(sbx.data.treatments, function eachTreatment (treatment) { + _.each(sbx.data.sitechangeTreatments, function eachTreatment (treatment) { var treatmentDate = treatment.mills; - if (treatment.eventType === 'Site Change' && treatmentDate > prevDate && treatmentDate <= sbx.time) { + if (treatmentDate > prevDate && treatmentDate <= sbx.time) { prevDate = treatmentDate; returnValue.treatmentDate = treatmentDate; From 604f0cba08d301a75a645d65fdd36c4f98042d4a Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Thu, 5 Nov 2015 20:41:12 +0100 Subject: [PATCH 0039/2594] SAGE --- lib/plugins/index.js | 2 + lib/plugins/sensorage.js | 173 +++++++++++++++++++++++++++++++++++++++ lib/times.js | 10 ++- 3 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 lib/plugins/sensorage.js diff --git a/lib/plugins/index.js b/lib/plugins/index.js index 6e4bba3823b..a27aec89072 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -27,6 +27,7 @@ function init() { , require('./cob')() , require('./boluswizardpreview')() , require('./cannulaage')() + , require('./sensorage')() , require('./basalprofile')() , require('./upbat')() , require('./careportal')() @@ -44,6 +45,7 @@ function init() { , require('./cob')() , require('./boluswizardpreview')() , require('./cannulaage')() + , require('./sensorage')() , require('./treatmentnotify')() ]; diff --git a/lib/plugins/sensorage.js b/lib/plugins/sensorage.js new file mode 100644 index 00000000000..c15d74636ca --- /dev/null +++ b/lib/plugins/sensorage.js @@ -0,0 +1,173 @@ +'use strict'; + +var _ = require('lodash'); +var moment = require('moment'); +var times = require('../times'); + +var sage = { + name: 'sage' + , label: 'Sensor Age' + , pluginType: 'pill-minor' +}; + +function init() { + return sage; +} + +module.exports = init; + +sage.getPrefs = function getPrefs(sbx) { + // SAGE_INFO = 6d SAGE_WARN=6d20h SAGE_URGENT=6d22h + return { + 'info' : sbx.extendedSettings.info ? sbx.extendedSettings.info : times.days(6).hours, + 'warn' : sbx.extendedSettings.warn ? sbx.extendedSettings.warn : times.days(7).hours - 4, + 'urgent' : sbx.extendedSettings.urgent ? sbx.extendedSettings.urgent : times.days(7).hours - 2, + 'enableAlerts' : sbx.extendedSettings.enableAlerts + }; +}; + +sage.checkNotifications = function checkNotifications(sbx) { + + var info = sage.findLatestTimeChange(sbx); + var sensorInfo = info[info.min]; + var prefs = sage.getPrefs(sbx); + + if (!prefs.enableAlerts || !sensorInfo.checkForAlert) { return; } + + var sendNotification = false; + var title = 'Sensor age ' + sensorInfo.days +' days' + sensorInfo.hours +' hours'; + var sound = 'incoming'; + var msg = ', change due soon'; + var level = 1; + + if (sensorInfo.age === Number(prefs.info)) { sendNotification = true; } + if (sensorInfo.age === Number(prefs.warn)) { sendNotification = true; msg = ', time to change'; } + if (sensorInfo.age === Number(prefs.urgent)) { sendNotification = true; msg = ', sensor will stop!'; sound = 'persistent'; level = 2;} + + if (sendNotification) { + sbx.notifications.requestNotify({ + level: level + , title: title + , message: title + msg + , pushoverSound: sound + , plugin: sage + , debug: { + sensorInfo: sensorInfo + } + }); + } +}; + +function minButValid(record) { + if (!record['Sensor Start'].age) { + return 'Sensor Change'; + } + if (!record['Sensor Change'].age) { + return 'Sensor Start'; + } + if (record['Sensor Start'].age < record['Sensor Change'].age) { + return 'Sensor Start'; + } + if (record['Sensor Start'].age > record['Sensor Change'].age) { + return 'Sensor Change'; + } + alert('Some bug'); +} + +sage.findLatestTimeChange = function findLatestTimeChange(sbx) { + + var returnValue = { + 'Sensor Start': {'message':'', 'found': false, 'age': 0, 'treatmentDate': null, 'checkForAlert': false} + , 'Sensor Change': {'message':'', 'found': false, 'age': 0, 'treatmentDate': null, 'checkForAlert': false} + }; + + var prevDate = { + 'Sensor Start': 0 + ,'Sensor Change': 0 + }; + + _.each(sbx.data.sensorTreatments, function eachTreatment (treatment) { + ['Sensor Start', 'Sensor Change'].forEach( function eachEvent(event) { + var treatmentDate = treatment.mills; + if (treatment.eventType === event && treatmentDate > prevDate[event] && treatmentDate <= sbx.time) { + + prevDate[event] = treatmentDate; + returnValue[event].treatmentDate = treatmentDate; + + //allow for 10 minute period after a full hour during which we'll alert the user + var a = moment(sbx.time); + var b = moment(returnValue[event].treatmentDate); + var days = a.diff(b,'days'); + var hours = a.diff(b,'hours') - days * 24; + var age = a.diff(b,'hours'); + var minFractions = a.diff(b,'minutes') - age * 60; + + returnValue[event].checkForAlert = minFractions <= 10; + + if (!returnValue[event].found) { + returnValue[event].found = true; + returnValue[event].age = age; + returnValue[event].days = days; + returnValue[event].hours = hours; + } else { + if (age >= 0 && age < returnValue[event].age) { + returnValue[event].age = age; + returnValue[event].days = days; + returnValue[event].hours = hours; + if (treatment.notes) { + returnValue[event].message = treatment.notes; + } else { + returnValue[event].message = ''; + } + } + } + } + }); + }); + + // clear Sensor Start if both found and Sensort Change is newer + if (returnValue['Sensor Change'].found && returnValue['Sensor Start'].found && returnValue['Sensor Start'].treatmentDate < returnValue['Sensor Change'].treatmentDate) { + returnValue['Sensor Start'] = {'message':'', 'found': false, 'age': 0, 'treatmentDate': null, 'checkForAlert': false}; + } + returnValue.min = minButValid(returnValue); + + return returnValue; +}; + +sage.updateVisualisation = function updateVisualisation (sbx) { + + var sensorInfo = sage.findLatestTimeChange(sbx); + var prefs = sage.getPrefs(sbx); + var info = []; + var shownAge; + + ['Sensor Change', 'Sensor Start'].forEach( function eachEvent(event) { + if (sensorInfo[event].found) { + info.push( { label: event, value: new Date(sensorInfo[event].treatmentDate).toLocaleString() } ); + shownAge = ''; + if (sensorInfo[event].age > 24) { + shownAge += sensorInfo[event].days + ' days '; + } + shownAge += sensorInfo[event].hours + ' hours'; + info.push( { label: 'Duration', value: shownAge } ); + if (sensorInfo[event].message !== '') { + info.push({label: 'Notes:', value: sensorInfo[event].message}); + } + } + }); + shownAge = ''; + if (sensorInfo[sensorInfo.min].found) { + if (sensorInfo[sensorInfo.min].age > 24) { + shownAge += sensorInfo[sensorInfo.min].days + 'd'; + } + shownAge += sensorInfo[sensorInfo.min].hours + 'h'; + } else { + shownAge = 'n/a '; + } + + sbx.pluginBase.updatePillText(sage, { + value: shownAge + , label: 'SAGE' + , info: info + }); +}; \ No newline at end of file diff --git a/lib/times.js b/lib/times.js index 9d37c533218..51c5194d776 100644 --- a/lib/times.js +++ b/lib/times.js @@ -3,7 +3,12 @@ var cache = { }; var factories = { - hours: function hours(value) { + days: function days(value) { + return { + hours: value * 24 ,mins: value * 24 * 60, secs: value * 24 * 60 * 60, msecs: value * 24 * 60 * 60 * 1000 + }; + } + , hours: function hours(value) { return { days: value / 24 ,mins: value * 60, secs: value * 60 * 60, msecs: value * 60 * 60 * 1000 }; @@ -38,7 +43,8 @@ function getOrCreate (types) { } var times = { - hour: function ( ) { return getOrCreate('hours')(1); } + days: function (value) { return getOrCreate('days')(value); } + , hour: function ( ) { return getOrCreate('hours')(1); } , hours: function (value) { return getOrCreate('hours')(value); } , min: function ( ) { return getOrCreate('mins')(1); } , mins: function (value) { return getOrCreate('mins')(value); } From 8690893016c9a3f4ffbba8ed363a8fa322fc75c6 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Thu, 5 Nov 2015 20:47:41 +0100 Subject: [PATCH 0040/2594] codacy --- lib/plugins/sensorage.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/plugins/sensorage.js b/lib/plugins/sensorage.js index c15d74636ca..c7fbd4a4897 100644 --- a/lib/plugins/sensorage.js +++ b/lib/plugins/sensorage.js @@ -137,7 +137,6 @@ sage.findLatestTimeChange = function findLatestTimeChange(sbx) { sage.updateVisualisation = function updateVisualisation (sbx) { var sensorInfo = sage.findLatestTimeChange(sbx); - var prefs = sage.getPrefs(sbx); var info = []; var shownAge; From 19f946ea75f464d8537f6bf893051ceccd3c631d Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Thu, 5 Nov 2015 20:59:13 +0100 Subject: [PATCH 0041/2594] fix canulaage.test --- tests/cannulaage.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cannulaage.test.js b/tests/cannulaage.test.js index 60ecdfd4281..2c19ebf7666 100644 --- a/tests/cannulaage.test.js +++ b/tests/cannulaage.test.js @@ -24,7 +24,7 @@ describe('cage', function ( ) { var clientSettings = {}; var data = { - treatments: [ + sitechangeTreatments: [ {eventType: 'Site Change', notes: 'Foo', mills: Date.now() - 48 * 60 * 60000} , {eventType: 'Site Change', notes: 'Bar', mills: Date.now() - 24 * 60 * 60000} ] @@ -48,7 +48,7 @@ describe('cage', function ( ) { var clientSettings = {}; var data = { - treatments: [ + sitechangeTreatments: [ {eventType: 'Site Change', notes: 'Foo', mills: Date.now() - 48 * 60 * 60000} , {eventType: 'Site Change', notes: '', mills: Date.now() - 59 * 60000} ] @@ -73,7 +73,7 @@ describe('cage', function ( ) { var before = Date.now() - (48 * 60 * 60 * 1000); - ctx.data.treatments = [{eventType: 'Site Change', mills: before}]; + ctx.data.sitechangeTreatments = [{eventType: 'Site Change', mills: before}]; var sbx = prepareSandbox(); sbx.extendedSettings = { 'enableAlerts': 'TRUE' }; From 12374aee91b4df2fda15cf2d19e1188c6d50e47d Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Thu, 5 Nov 2015 22:40:02 +0100 Subject: [PATCH 0042/2594] fix rendering profiles --- lib/client/renderer.js | 11 +++++------ lib/profilefunctions.js | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/client/renderer.js b/lib/client/renderer.js index f928db17312..6d2eb6e843b 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -666,9 +666,7 @@ function init (client, d3) { from += times.mins(20 * mult).msecs; var mode = client.settings.extendedSettings.basal.render; - var data = client.treatments.filter(function(treatment) { - return treatment.eventType === 'Profile Switch'; - }); + var data = client.profileTreatments.slice(); data.push({ //eventType: 'Profile Switch' profile: client.profilefunctions.activeProfileToTime(from) @@ -681,11 +679,12 @@ function init (client, d3) { treatProfiles.transition() .attr('transform', function (t) { // change text of record on left side - if (t.first) { - $(this).text('↑↑↑ ' + t.profile + ' ↑↑↑'); - } return 'rotate(-90,' + chart().xScale(t.mills) + ',' + chart().yScaleBasals(topOfText) + ') ' + 'translate(' + chart().xScale(t.mills) + ',' + chart().yScaleBasals(topOfText) + ')'; + }) + .text(function (t) { + var sign = t.first ? '↑↑↑' : '---'; + return sign + ' ' + t.profile + ' ' + sign; }); treatProfiles.enter().append('text') diff --git a/lib/profilefunctions.js b/lib/profilefunctions.js index 68c92488cd8..125af53d906 100644 --- a/lib/profilefunctions.js +++ b/lib/profilefunctions.js @@ -68,7 +68,7 @@ function init(profileData) { //round to the minute for better caching var minuteTime = Math.round(time / 60000) * 60000; - var cacheKey = (minuteTime + valueType + spec_profile); + var cacheKey = (minuteTime + valueType + spec_profile + profile.profiletreatments_hash); var returnValue = profile.timeValueCache[cacheKey]; if (returnValue) { @@ -115,11 +115,11 @@ function init(profileData) { }; profile.getUnits = function getUnits(spec_profile) { - return profile.getCurrentProfile(spec_profile)['units']; + return profile.getCurrentProfile(null, spec_profile)['units']; }; profile.getTimezone = function getTimezone(spec_profile) { - return profile.getCurrentProfile(spec_profile)['timezone']; + return profile.getCurrentProfile(null, spec_profile)['timezone']; }; profile.hasData = function hasData() { @@ -207,7 +207,7 @@ function init(profileData) { profile.getTempBasal = function getTempBasal(time, spec_profile) { - var cacheKey = 'basal' + time + profile.tempbasaltreatments_hash + spec_profile; + var cacheKey = 'basal' + time + profile.tempbasaltreatments_hash + profile.profiletreatments_hash + spec_profile; var returnValue = profile.timeValueCache[cacheKey]; if (returnValue) { From 694569e7d97f3cc4e44603ce3f60b2dbb403e363 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 6 Nov 2015 12:41:06 +0100 Subject: [PATCH 0043/2594] hide COB from boluscalc when cob not enabled, hide profile when there is only one --- lib/client/boluscalc.js | 5 ++++- lib/client/index.js | 2 ++ static/index.html | 37 +++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index a42a38bf87b..35fce1f9aff 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -150,9 +150,12 @@ function init(client, $, plugins) { boluscalc.prepare = function prepare( ) { foods = []; $('#bc_profile').empty(); - client.profilefunctions.listBasalProfiles().forEach(function (p) { + var profiles = client.profilefunctions.listBasalProfiles(); + profiles.forEach(function (p) { $('#bc_profile').append(''); }); + $('#bc_profileLabel').toggle(profiles.length > 1); + $('#bc_usebg').prop('checked','checked'); $('#bc_usecarbs').prop('checked','checked'); $('#bc_usecob').prop('checked',''); diff --git a/lib/client/index.js b/lib/client/index.js index 637da1a1b31..3a088ce2b79 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -779,6 +779,8 @@ client.init = function init(serverSettings, plugins) { $('#boluscalcDrawerToggle').toggle(client.settings.showPlugins.indexOf('boluscalc') > -1); // hide food control if not enabled $('.foodcontrol').toggle(client.settings.enable.indexOf('food') > -1); + // hide cob control if not enabled + $('.cobcontrol').toggle(client.settings.enable.indexOf('cob') > -1); container.toggleClass('has-minor-pills', plugins.hasShownType('pill-minor', client.settings)); function prepareData ( ) { diff --git a/static/index.html b/static/index.html index 8a055699a65..9437bf3a73e 100644 --- a/static/index.html +++ b/static/index.html @@ -361,7 +361,7 @@ - + @@ -491,20 +491,25 @@
+
+ -
@@ -531,10 +536,6 @@ -
From c6710d9474de17b7df1e81511de7806ef38bc226 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Sat, 7 Nov 2015 10:35:39 +0100 Subject: [PATCH 0044/2594] boluscalc projection fix --- lib/client/boluscalc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index 35fce1f9aff..165ab0c5035 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -295,8 +295,8 @@ function init(client, $, plugins) { $('#bc_insulintotal').text(record.insulin.toFixed(2)); // Carbs needed if too much iob or in range message when nothing entered and in range - var outcome = record.bg - record.insulin * isf; - if (record.othercorrection === 0 && record.carbs === 0 && record.cob === 0 && outcome > targetBGLow && outcome < targetBGHigh) { + var outcome = record.bg - record.iob * isf; + if (record.othercorrection === 0 && record.carbs === 0 && record.cob === 0 && record.bg > 0 && outcome > targetBGLow && outcome < targetBGHigh) { $('#bc_carbsneeded').text(''); $('#bc_insulinover').text(''); $('#bc_carbsneededtr').css('display','none'); From 86691d94e2f25acac8ba668de2ff0f3360f4ca13 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Sat, 7 Nov 2015 12:13:18 +0100 Subject: [PATCH 0045/2594] README.md upadte --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4278d62c49f..d47a35dfb21 100644 --- a/README.md +++ b/README.md @@ -233,6 +233,9 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm #### Built-in/Example Plugins: + * `careportal` - Allow to enter treatment entries. + * `boluscalc` - Enable Bolus Wizard. + * `food` - Enable adding food from database in Bolus Wizard and enable Food Editor. * `rawbg` (Raw BG) - Calculates BG using sensor and calibration records from and displays an alternate BG values and noise levels. * `iob` (Insulin-on-Board) - Adds the IOB pill visualization in the client and calculates values that used by other plugins. Uses treatments with insulin doses and the `dia` and `sens` fields from the [treatment profile](#treatment-profile). * `cob` (Carbs-on-Board) - Adds the COB pill visualization in the client and calculates values that used by other plugins. Uses treatments with carb doses and the `carbs_hr`, `carbratio`, and `sens` fields from the [treatment profile](#treatment-profile). @@ -246,7 +249,8 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `CAGE_INFO` (`44`) - If time since last `Site Change` matches `CAGE_INFO`, user will be warned of upcoming cannula change * `CAGE_WARN` (`48`) - If time since last `Site Change` matches `CAGE_WARN`, user will be alarmed to to change the cannula * `CAGE_URGENT` (`72`) - If time since last `Site Change` matches `CAGE_URGENT`, user will be issued a persistent warning of overdue change. - * `CAGE_DISPLAY` (`hours`) - Possible values are 'hours' or 'days'. If 'days' is selected and age of canula is greater than 24h number is displayed like `1.2d` + * `CAGE_DISPLAY` (`hours`) - Possible values are 'hours' or 'days'. If 'days' is selected and age of canula is greater than 24h number is displayed in days + * `sage` (Sensor Age) - Calculates the number of days and hours since the last `Sensor Start` and `Sensor Change` treatment that was recorded. * `treatmentnotify` (Treatment Notifications) - Generates notifications when a treatment has been entered and snoozes alarms minutes after a treatment. Default snooze is 10 minutes, and can be set using the `TREATMENTNOTIFY_SNOOZE_MINS` [extended setting](#extended-settings). * `basal` (Basal Profile) - Adds the Basal pill visualization to display the basal rate for the current time. Also enables the `bwp` plugin to calculate correction temp basal suggestions. Uses the `basal` field from the [treatment profile](#treatment-profile). Also uses the extended setting: * `BASAL_RENDER` (`none`) - Possible values are `none`, `default`, or `icicle` (inverted) From befba2247f611dbf382d35d4baa3809a565e7398 Mon Sep 17 00:00:00 2001 From: Bog Dan Date: Sun, 8 Nov 2015 07:56:14 +0200 Subject: [PATCH 0046/2594] RO update Nov, 08 2015 Added measurement units, name of Care Portal, drag and drop food, In the future. --- lib/language.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/language.js b/lib/language.js index 4a0dffccf57..16f119bc450 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4389,29 +4389,37 @@ function init() { ,it: 'Lingua' } ,'Add new' : { - cs: 'Přidat nový' + cs: 'Přidat nový', + ,ro: 'Adaugă' } ,'g' : { // grams shortcut cs: 'g' + ,ro: ''g } ,'ml' : { // milliliters shortcut cs: 'ml' + ,ro: 'ml' } ,'pcs' : { // pieces shortcut cs: 'ks' + ,ro: 'buc' } ,'Drag&drop food here' : { cs: 'Sem táhni & pusť jídlo' + ,ro: 'Drag&drop aliment aici' } ,'Care Portal' : { cs: 'Portál ošetření' ,it: 'Somministrazioni' + ,ro: 'Care Portal' } ,'Medium/Unknown' : { // GI of food cs: 'Střední/Neznámá' + ,ro: 'Mediu/Necunoscut' } ,'IN THE FUTURE' : { cs: 'V BUDOUCNOSTI' + ,ro: 'ÎN VIITOR' } ,'Update' : { // Update button cs: 'Aktualizovat' @@ -4739,7 +4747,7 @@ function init() { } ,'Record valid from' : { cs: 'Záznam platný od' - ,ro: 'Înregistarea validă de la' + ,ro: 'Înregistare validă de la' } ,'Stored profiles' : { cs: 'Uložené profily' From d5e72878eb3943206815bfca8a838a81e72256e2 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 7 Nov 2015 22:19:15 -0800 Subject: [PATCH 0047/2594] prevent careportal from being hidden by old stored settings --- lib/client/browser-settings.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/client/browser-settings.js b/lib/client/browser-settings.js index 30e4bb79edb..5ca48eb2c05 100644 --- a/lib/client/browser-settings.js +++ b/lib/client/browser-settings.js @@ -2,6 +2,9 @@ var _ = require('lodash'); +// VERSION 1 - 0.9.0 - 2015-Nov-07 - initial version +var STORAGE_VERSION = 1; + function init (client, plugins, serverSettings, $) { var storage = $.localStorage; @@ -132,7 +135,8 @@ function init (client, plugins, serverSettings, $) { language: $('#language').val(), scaleY: $('#scaleY').val(), basalrender: $('#basalrender').val(), - showPlugins: checkedPluginNames() + showPlugins: checkedPluginNames(), + storageVersion: 1 }); event.preventDefault(); @@ -154,6 +158,27 @@ function init (client, plugins, serverSettings, $) { return stored !== undefined && stored !== null ? stored : serverSettings.settings[name]; }); + settings.thresholds = serverSettings.settings.thresholds; + settings.enable = serverSettings.settings.enable; + + if (settings.enable.indexOf('ar2') < 0) { + settings.enable += ' ar2'; + } + + var previousVersion = parseInt(storage.get('storageVersion')); + + //un-versioned settings + if (isNaN(previousVersion)) { + //special showPlugins handling for careportal + //prevent careportal from being hidden by old stored settings + if (settings.isEnabled('careportal')) { + var storedShowPlugins = storage.get('showPlugins'); + if (storedShowPlugins && storedShowPlugins.indexOf('careportal') === -1) { + settings.showPlugins += ' careportal'; + } + } + } + if (!settings.extendedSettings.basal) { settings.extendedSettings.basal = {}; } @@ -165,13 +190,6 @@ function init (client, plugins, serverSettings, $) { showLocalstorageError(); } - settings.thresholds = serverSettings.settings.thresholds; - settings.enable = serverSettings.settings.enable; - - if (settings.enable.indexOf('ar2') < 0) { - settings.enable += ' ar2'; - } - plugins.init(settings); loadForm(); From 70eb400716a9fa218190a732037428b021a25c88 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 7 Nov 2015 22:27:13 -0800 Subject: [PATCH 0048/2594] really use the STORAGE_VERSION constant, good catch codacy --- lib/client/browser-settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/browser-settings.js b/lib/client/browser-settings.js index 5ca48eb2c05..7defb334e4b 100644 --- a/lib/client/browser-settings.js +++ b/lib/client/browser-settings.js @@ -136,7 +136,7 @@ function init (client, plugins, serverSettings, $) { scaleY: $('#scaleY').val(), basalrender: $('#basalrender').val(), showPlugins: checkedPluginNames(), - storageVersion: 1 + storageVersion: STORAGE_VERSION }); event.preventDefault(); From 52f6f45fd7a917721b90a64707da4cced2899cde Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 7 Nov 2015 22:30:59 -0800 Subject: [PATCH 0049/2594] a little refactoring --- lib/client/browser-settings.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/client/browser-settings.js b/lib/client/browser-settings.js index 7defb334e4b..7d016b4ed8e 100644 --- a/lib/client/browser-settings.js +++ b/lib/client/browser-settings.js @@ -150,21 +150,7 @@ function init (client, plugins, serverSettings, $) { $('#save').hide(); } - settings.extendedSettings = serverSettings.extendedSettings; - - try { - settings.eachSetting(function setEach (name) { - var stored = storage.get(name); - return stored !== undefined && stored !== null ? stored : serverSettings.settings[name]; - }); - - settings.thresholds = serverSettings.settings.thresholds; - settings.enable = serverSettings.settings.enable; - - if (settings.enable.indexOf('ar2') < 0) { - settings.enable += ' ar2'; - } - + function handleStorageVersions ( ) { var previousVersion = parseInt(storage.get('storageVersion')); //un-versioned settings @@ -178,7 +164,23 @@ function init (client, plugins, serverSettings, $) { } } } + } + + settings.extendedSettings = serverSettings.extendedSettings; + try { + settings.eachSetting(function setEach (name) { + var stored = storage.get(name); + return stored !== undefined && stored !== null ? stored : serverSettings.settings[name]; + }); + + settings.thresholds = serverSettings.settings.thresholds; + settings.enable = serverSettings.settings.enable; + + if (settings.enable.indexOf('ar2') < 0) { + settings.enable += ' ar2'; + } + handleStorageVersions(); if (!settings.extendedSettings.basal) { settings.extendedSettings.basal = {}; } From a9f83b6150a9e68af9d34342c02b462af5a8d19d Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sat, 7 Nov 2015 22:44:32 -0800 Subject: [PATCH 0050/2594] litte css tweak to center bg over tons of pills --- static/css/main.css | 1 + 1 file changed, 1 insertion(+) diff --git a/static/css/main.css b/static/css/main.css index 7852c2ec954..433faf8d583 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -220,6 +220,7 @@ body { margin: 10px; border: 2px solid #000; border-radius: 5px; + display: inline-block; width: 360px; } From 2329845f36dc164abad7c4a56260b3791c65ba55 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sun, 8 Nov 2015 09:24:51 -0800 Subject: [PATCH 0051/2594] sort treatments so the last is the most recent --- lib/data.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/data.js b/lib/data.js index 93044f70d31..5fd19010521 100644 --- a/lib/data.js +++ b/lib/data.js @@ -44,6 +44,8 @@ function init(env, ctx) { function loadComplete (err, result) { data.treatments = _.uniq(data.treatments, false, function (item) { return item._id.toString(); }); + //sort treatments so the last is the most recent + data.treatments = _.sortBy(data.treatments, function (item) { return item.created_at; }); data.updateTreatmentDisplayBGs(); if (err) { console.error(err); From ff7f68bdc5b62f0a8fce447343858f611a14dd38 Mon Sep 17 00:00:00 2001 From: Bog Dan Date: Mon, 9 Nov 2015 01:04:30 +0200 Subject: [PATCH 0052/2594] RO update Oct, 09 2015 Removed a double entry from text --- lib/language.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index 16f119bc450..7a91e5222bf 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4390,7 +4390,7 @@ function init() { } ,'Add new' : { cs: 'Přidat nový', - ,ro: 'Adaugă' + ,ro: 'Adaugă nou' } ,'g' : { // grams shortcut cs: 'g' From df02712dd7afd5226478b65d8cd6183f41e0a715 Mon Sep 17 00:00:00 2001 From: Bog Dan Date: Mon, 9 Nov 2015 20:07:27 +0200 Subject: [PATCH 0053/2594] RO update Nov, 09 2015 Removed text from outside single quotes. --- lib/language.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index 7a91e5222bf..591df0b807a 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4394,7 +4394,7 @@ function init() { } ,'g' : { // grams shortcut cs: 'g' - ,ro: ''g + ,ro: 'g' } ,'ml' : { // milliliters shortcut cs: 'ml' From 44a5ab915b2ba85e619198fbadbdcf7ce308c0ad Mon Sep 17 00:00:00 2001 From: Bog Dan Date: Mon, 9 Nov 2015 20:21:09 +0200 Subject: [PATCH 0054/2594] RO update Nov, 09 2015 Delete a character that was misplaced --- lib/language.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index 591df0b807a..66ad47a9b96 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4389,7 +4389,7 @@ function init() { ,it: 'Lingua' } ,'Add new' : { - cs: 'Přidat nový', + cs: 'Přidat nový' ,ro: 'Adaugă nou' } ,'g' : { // grams shortcut From 447e4e0d4d357bc22f7848d5cc8651997aba8213 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Mon, 9 Nov 2015 21:21:36 +0100 Subject: [PATCH 0055/2594] make profile history and multiple profiles optional --- README.md | 3 +++ env.js | 2 ++ lib/client/boluscalc.js | 9 ++++++++- lib/client/index.js | 2 ++ lib/plugins/index.js | 5 +++-- lib/plugins/profile.js | 16 ++++++++++++++++ lib/settings.js | 2 +- static/index.html | 2 +- static/profile/index.html | 5 ++--- static/profile/js/profileeditor.js | 3 +++ 10 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 lib/plugins/profile.js diff --git a/README.md b/README.md index d47a35dfb21..2c339349bdb 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,9 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `AR2_CONE_FACTOR` (`2`) - to adjust size of cone, use `0` for a single line. * `simplealarms` (Simple BG Alarms) - Uses `BG_HIGH`, `BG_TARGET_TOP`, `BG_TARGET_BOTTOM`, `BG_LOW` thresholds to generate alarms. * Enabled by default if 1 of these thresholds is set **OR** `ALARM_TYPES` includes `simple`. + * `profile` (Treatment Profile) - Add link to Profile Editor and allow to enter treatment profile settings. Also uses the extended setting: + * `PROFILE_HISTORY` (`off`) - possible values `on` or `off`. Enable/disable NS ability to keep history of your profiles (still experimental) + * `PROFILE_MULTIPLE` (`off`) - possible values `on` or `off`. Enable/disable NS ability to handle and switch between multiple treatment profiles #### Built-in/Example Plugins: diff --git a/env.js b/env.js index 03b53f84094..cc7995f808c 100644 --- a/env.js +++ b/env.js @@ -158,6 +158,8 @@ function findExtendedSettings (envs) { extended[enable] = exts; var ext = _.camelCase(env.substring(split + 1).toLowerCase()); if (!isNaN(value)) { value = Number(value); } + if (typeof value === 'string' && value.toLowerCase() === 'on') { value = true; } + if (typeof value === 'string' && value.toLowerCase() === 'off') { value = false; } exts[ext] = value; } } diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index 165ab0c5035..0da8f5fbaab 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -33,6 +33,13 @@ function init(client, $, plugins) { } } + function isProfileEnabled(profiles) { + return client.settings.enable.indexOf('profile') > -1 + && client.settings.extendedSettings.profile + && client.settings.extendedSettings.profile.multiple + && profiles.length > 1; + } + function isTouch() { try { document.createEvent('TouchEvent'); return true; } catch (e) { return false; } @@ -154,7 +161,7 @@ function init(client, $, plugins) { profiles.forEach(function (p) { $('#bc_profile').append(''); }); - $('#bc_profileLabel').toggle(profiles.length > 1); + $('#bc_profileLabel').toggle(isProfileEnabled(profiles)); $('#bc_usebg').prop('checked','checked'); $('#bc_usecarbs').prop('checked','checked'); diff --git a/lib/client/index.js b/lib/client/index.js index 3a088ce2b79..409dc4a4a1c 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -781,6 +781,8 @@ client.init = function init(serverSettings, plugins) { $('.foodcontrol').toggle(client.settings.enable.indexOf('food') > -1); // hide cob control if not enabled $('.cobcontrol').toggle(client.settings.enable.indexOf('cob') > -1); + // hide profile controls if not enabled + $('.profilecontrol').toggle(client.settings.enable.indexOf('profile') > -1); container.toggleClass('has-minor-pills', plugins.hasShownType('pill-minor', client.settings)); function prepareData ( ) { diff --git a/lib/plugins/index.js b/lib/plugins/index.js index a27aec89072..0df2526390e 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -30,8 +30,9 @@ function init() { , require('./sensorage')() , require('./basalprofile')() , require('./upbat')() - , require('./careportal')() - , require('./boluscalc')() + , require('./careportal')() // fake plugin to show/hide + , require('./boluscalc')() // fake plugin to show/hide + , require('./profile')() // fake plugin to hold extended settings ]; var serverDefaultPlugins = [ diff --git a/lib/plugins/profile.js b/lib/plugins/profile.js new file mode 100644 index 00000000000..e35caec0e1c --- /dev/null +++ b/lib/plugins/profile.js @@ -0,0 +1,16 @@ +'use strict'; + +// this is just a fake plugin to hold extended settings + +function init() { + + var profile = { + name: 'profile' + , label: 'Profile' + , pluginType: 'fake' + }; + + return profile; +} + +module.exports = init; \ No newline at end of file diff --git a/lib/settings.js b/lib/settings.js index c489fa48b54..1836fde6008 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -77,7 +77,7 @@ function init ( ) { } //TODO: getting sent in status.json, shouldn't be - settings.DEFAULT_FEATURES = ['delta', 'direction', 'upbat', 'errorcodes']; + settings.DEFAULT_FEATURES = ['delta', 'direction', 'upbat', 'errorcodes', 'profile']; var wasSet = []; diff --git a/static/index.html b/static/index.html index 9437bf3a73e..7b61002d429 100644 --- a/static/index.html +++ b/static/index.html @@ -82,7 +82,7 @@
diff --git a/static/profile/index.html b/static/profile/index.html index bc20ca4e60a..7fee3f106f6 100644 --- a/static/profile/index.html +++ b/static/profile/index.html @@ -60,7 +60,7 @@

Profile Editor

- + -
Record valid from: @@ -80,7 +79,7 @@

Profile Editor

- +