Skip to content

Commit

Permalink
Merge 1142973 into d9b7cdc
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Feb 15, 2016
2 parents d9b7cdc + 1142973 commit 8f64b00
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 49 deletions.
40 changes: 38 additions & 2 deletions lib/client/browser-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var SMALL_SCREEN = 500;

function init ($) {
var lastOpenedDrawer = null;

Expand Down Expand Up @@ -63,6 +65,14 @@ function init ($) {
catch (e) { return false; }
}

function closeLastOpenedDrawer (callback) {
if (lastOpenedDrawer) {
closeDrawer(lastOpenedDrawer, callback);
} else if (callback) {
callback();
}
}

function closeDrawer(id, callback) {
lastOpenedDrawer = null;
$('html, body').css({ scrollTop: 0 });
Expand All @@ -82,7 +92,30 @@ function init ($) {
closeOpenDraw(function () {
lastOpenedDrawer = id;
if (prepare) { prepare(); }
$(id).css({display:'block', right: '0'});

var style = {display:'block', right: '0'};

var windowWidth = $(window).width();
var windowHeight = $(window).height();
var chartTop = $('#chartContainer').offset().top - 45;
var chartHeight = windowHeight - chartTop - 45;
if (windowWidth < SMALL_SCREEN || (windowHeight < SMALL_SCREEN) && windowWidth < 800) {
style.width = windowWidth + 'px';
if (chartHeight > windowHeight * 0.4) {
style.top = chartTop + 'px';
style.height = chartHeight + 'px';
} else {
style.top = '0px';
style.height = windowHeight + 'px';
}
} else {
style.top = '0px';
style.height = (windowHeight - 45) + 'px';
style.width = '350px';
}


$(id).css(style);
});

}
Expand Down Expand Up @@ -111,7 +144,9 @@ function init ($) {
notify.addClass(type ? type : 'urgent');

notify.find('span').html(note);
notify.css('left', 'calc(50% - ' + (notify.width() / 2) + 'px)');
var windowWidth = $(window).width();
var left = (windowWidth - notify.width()) / 2;
notify.css('left', left + 'px');
notify.show();
}

Expand All @@ -123,6 +158,7 @@ function init ($) {
reload: reload
, queryParms: queryParms
, closeDrawer: closeDrawer
, closeLastOpenedDrawer: closeLastOpenedDrawer
, toggleDrawer: toggleDrawer
, closeNotification: closeNotification
, showNotification: showNotification
Expand Down
2 changes: 2 additions & 0 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ function init (client, d3, $) {
// only redraw chart if chart size has changed
if ((chart.prevChartWidth !== chartWidth) || (chart.prevChartHeight !== chartHeight)) {

client.browserUtils.closeLastOpenedDrawer();

chart.prevChartWidth = chartWidth;
chart.prevChartHeight = chartHeight;

Expand Down
3 changes: 2 additions & 1 deletion lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ client.init = function init(serverSettings, plugins) {
chart.scroll(nowDate);
}

$('#chartContainer').css('top', (client.bottomOfPills() + 5) + 'px');
var top = (client.bottomOfPills() + 5);
$('#chartContainer').css({top: top + 'px', height: $(window).height() - top - 10});
}

function sgvToColor(sgv) {
Expand Down
2 changes: 1 addition & 1 deletion lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ function init (client, d3) {

client.ddata.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) {
if (t.duration && t.mills < to && t.mills + times.mins(t.duration).msecs > from) {
var text = g.append('text')
.attr('class', 'tempbasaltext')
.style('font-size', 15)
Expand Down
11 changes: 10 additions & 1 deletion lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var _ = require('lodash');
var async = require('async');
var times = require('../times');
var fitTreatmentsToBGCurve = require('./treatmenttocurve');

var ONE_DAY = 86400000
Expand Down Expand Up @@ -96,10 +97,18 @@ function mergeToTreatments (ddata, results) {
var filtered = _.filter(results, function hasId (treatment) {
return _.isObject(treatment._id);
});

var treatments = _.map(filtered, function update (treatment) {
treatment.mills = new Date(treatment.created_at).getTime();
return treatment;
});

//filter out temps older than a day and an hour ago since we don't display them
var oneDayAgo = ddata.lastUpdated - ONE_DAY - times.hour().msecs;
treatments = _.filter(treatments, function noOldTemps (treatment) {
return !treatment.eventType || treatment.eventType.indexOf('Temp Basal') === -1 || treatment.mills > oneDayAgo;
});

ddata.treatments = _.union(ddata.treatments, treatments);
}

Expand Down Expand Up @@ -185,7 +194,7 @@ function loadDeviceStatus (ddata, env, ctx, callback) {
var opts = {
find: {
created_at: {
$gte: new Date(ddata.lastUpdated - TWO_DAYS).toISOString()
$gte: new Date(ddata.lastUpdated - ONE_DAY).toISOString()
}
}
, sort: {created_at: -1}
Expand Down
34 changes: 24 additions & 10 deletions lib/data/ddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function init( ) {
var result = {
first: { }
, rest: { }
, last: { }
};

function recent (item) {
Expand All @@ -42,7 +43,7 @@ function init( ) {
return item.mills >= time - max;
}

function partition (field, filter) {
function partition (field, filter, last) {
var data;
if (filter) {
data = ddata[field].filter(filterMax);
Expand All @@ -52,18 +53,27 @@ function init( ) {

var parts = _.partition(data, recent);
result.first[field] = parts[0];
result.rest[field] = parts[1];

if (last) {
result.last[field] = parts[1];
} else {
result.rest[field] = parts[1];
}
}

partition('treatments', false);
partition('devicestatus', true);
partition('treatments', false, false);
partition('devicestatus', true, true);

result.first.sgvs = ddata.sgvs.filter(filterMax);
result.first.cals = ddata.cals;
result.first.profiles = ddata.profiles;

result.rest.mbgs = ddata.mbgs.filter(filterMax);

console.log('results.first size', JSON.stringify(result.first).length,'bytes');
console.log('results.rest size', JSON.stringify(result.rest).length,'bytes');
console.log('results.last size', JSON.stringify(result.last).length,'bytes');

return result;
};

Expand Down Expand Up @@ -112,16 +122,20 @@ function init( ) {

// cut by end events
tempbasalTreatments.forEach(function allTreatments(t) {
endevents.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
if (t.duration) {
endevents.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
}
});

// cut by overlaping events
tempbasalTreatments.forEach(function allTreatments(t) {
tempbasalTreatments.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
if (t.duration) {
tempbasalTreatments.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
}
});

// store prepared temp basal treatments
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/treatmentnotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var levels = require('../levels');
var times = require('../times');
var simplealarms = require('./simplealarms')();

var OPENAPS_WHITELIST = ['Meal Bolus', 'Carb Correction', 'Correction Bolus'];
var OPENAPS_WHITELIST = ['BG Check', 'Meal Bolus', 'Carb Correction', 'Correction Bolus'];

function init() {

Expand Down
36 changes: 14 additions & 22 deletions lib/times.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

var cache = { };

var factories = {
weeks: function weeks(value) {
return {
Expand Down Expand Up @@ -35,31 +33,25 @@ var factories = {
}
};

function getOrCreate (types) {
function create (types) {
return function withValue (value) {
var key = types + value;
var obj = cache[key];
if (!obj) {
obj = factories[types](value);
cache[key] = obj;
}
return obj;
return factories[types](value);
};
}

var times = {
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); }
, sec: function ( ) { return getOrCreate('secs')(1); }
, secs: function (value) { return getOrCreate('secs')(value); }
, msec: function ( ) { return getOrCreate('msecs')(1); }
, msecs: function (value) { return getOrCreate('msecs')(value); }
week: function ( ) { return create('weeks')(1); }
, weeks: function (value) { return create('weeks')(value); }
, day: function ( ) { return create('days')(1); }
, days: function (value) { return create('days')(value); }
, hour: function ( ) { return create('hours')(1); }
, hours: function (value) { return create('hours')(value); }
, min: function ( ) { return create('mins')(1); }
, mins: function (value) { return create('mins')(value); }
, sec: function ( ) { return create('secs')(1); }
, secs: function (value) { return create('secs')(value); }
, msec: function ( ) { return create('msecs')(1); }
, msecs: function (value) { return create('msecs')(value); }
};

module.exports = times;
6 changes: 6 additions & 0 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ function init (env, ctx, server) {
split.rest.delta = true;
socket.emit('dataUpdate', split.rest);
}, 500);

setTimeout(function sendTheLast() {
split.last.delta = true;
socket.emit('dataUpdate', split.last);
}, 10000);

}
}
console.log(LOG_WS + 'Authetication ID: ',socket.client.id, ' client: ', clientType, ' history: ' + history);
Expand Down
17 changes: 9 additions & 8 deletions static/css/drawer.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
color: #eee;
display: none;
font-size: 16px;
height: 100%;
overflow-y: auto;
overflow-y: scroll;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
position: absolute;
margin-top: 45px;
right: -200px;
width: 300px;
top: 0;
z-index: 1;
}
Expand Down Expand Up @@ -55,12 +55,12 @@ input[type=number]:invalid {
color: #eee;
display: none;
font-size: 16px;
height: 100%;
overflow-y: auto;
overflow-y: scroll;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
position: absolute;
margin-top: 45px;
right: -200px;
width: 300px;
top: 0;
z-index: 1;
}
Expand Down Expand Up @@ -332,8 +332,9 @@ ul.navigation {
color: #eee;
display: none;
font-size: 16px;
height: 100%;
overflow-y: auto;
overflow-y: scroll;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
position: absolute;
margin-top: 45px;
right: -200px;
Expand Down
3 changes: 0 additions & 3 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


html, body {
height: 100%;
margin: 0;
padding: 0;
}
Expand All @@ -17,12 +16,10 @@ body {
.container {
bottom: 0;
display: block;
height: 100%;
left: 0;
margin: 0;
padding: 0;
top: 45px;
width: 100%;
z-index: 2;
}

Expand Down

0 comments on commit 8f64b00

Please sign in to comment.