Skip to content

Commit

Permalink
Openaps performance improvement (#5945)
Browse files Browse the repository at this point in the history
* improve openaps plugin performance

* more performance improvements

(cherry picked from commit 076a2dd)

* correct setting notEnacted variable

* remove unnecessary debug logging
  • Loading branch information
jpcunningh authored Sep 8, 2020
1 parent 22d1506 commit 89dfe21
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ client.load = function load (serverSettings, callback) {
function updateBolusRenderOver () {
var bolusRenderOver = (client.settings.bolusRenderOver || 1) + ' U and Over';
$('#bolusRenderOver').text(bolusRenderOver);
console.log('here');
}

function alarmingNow () {
Expand Down Expand Up @@ -434,7 +433,7 @@ client.load = function load (serverSettings, callback) {
brushExtent = brushedRange.map(chart.xScale2.invert);
}

console.log('brushed(): Brushed to: ', brushExtent);
// console.log('brushed(): Brushed to: ', brushExtent);

if (!brushedRange || (brushExtent[1].getTime() - brushExtent[0].getTime() !== client.focusRangeMS)) {
// ensure that brush updating is with the time range
Expand Down
56 changes: 49 additions & 7 deletions lib/plugins/openaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,42 @@ function init (ctx) {
}

function toMoments (status) {
var enacted = false;
var notEnacted = false;
if (status.openaps.enacted && status.openaps.enacted.timestamp && (status.openaps.enacted.recieved || status.openaps.enacted.received)) {
if (status.openaps.enacted.mills) {
enacted = moment(status.openaps.enacted.mills);
} else {
enacted = moment(status.openaps.enacted.timestamp);
}
} else if (status.openaps.enacted && status.openaps.enacted.timestamp && !(status.openaps.enacted.recieved || status.openaps.enacted.received)) {
if (status.openaps.enacted.mills) {
notEnacted = moment(status.openaps.enacted.mills)
} else {
notEnacted = moment(status.openaps.enacted.timestamp)
}
}

var suggested = false;
if (status.openaps.suggested && status.openaps.suggested.mills) {
suggested = moment(status.openaps.suggested.mills);
} else if (status.openaps.suggested && status.openaps.suggested.timestamp) {
suggested = moment(status.openaps.suggested.timestamp);
}

var iob = false;
if (status.openaps.iob && status.openaps.iob.mills) {
iob = moment(status.openaps.iob.mills);
} else if (status.openaps.iob && status.openaps.iob.timestamp) {
iob = moment(status.openaps.iob.timestamp);
}

return {
when: moment(status.mills)
, enacted: status.openaps.enacted && status.openaps.enacted.timestamp && (status.openaps.enacted.recieved || status.openaps.enacted.received) && moment(status.openaps.enacted.timestamp)
, notEnacted: status.openaps.enacted && status.openaps.enacted.timestamp && !(status.openaps.enacted.recieved || status.openaps.enacted.received) && moment(status.openaps.enacted.timestamp)
, suggested: status.openaps.suggested && status.openaps.suggested.timestamp && moment(status.openaps.suggested.timestamp)
, iob: status.openaps.iob && status.openaps.iob.timestamp && moment(status.openaps.iob.timestamp)
, enacted
, notEnacted
, suggested
, iob
};
}

Expand Down Expand Up @@ -175,7 +205,11 @@ function init (ctx) {

var enacted = status.openaps && status.openaps.enacted;
if (enacted && moments.enacted && (!result.lastEnacted || moments.enacted.isAfter(result.lastEnacted.moment))) {
enacted.moment = moment(enacted.timestamp);
if (enacted.mills) {
enacted.moment = moment(enacted.mills);
} else {
enacted.moment = moment(enacted.timestamp);
}
result.lastEnacted = enacted;
if (enacted.predBGs && (!result.lastPredBGs || enacted.moment.isAfter(result.lastPredBGs.moment))) {
result.lastPredBGs = _.isArray(enacted.predBGs) ? { values: enacted.predBGs } : enacted.predBGs;
Expand All @@ -184,13 +218,21 @@ function init (ctx) {
}

if (enacted && moments.notEnacted && (!result.lastNotEnacted || moments.notEnacted.isAfter(result.lastNotEnacted.moment))) {
enacted.moment = moment(enacted.timestamp);
if (enacted.mills) {
enacted.moment = moment(enacted.mills);
} else {
enacted.moment = moment(enacted.timestamp);
}
result.lastNotEnacted = enacted;
}

var suggested = status.openaps && status.openaps.suggested;
if (suggested && moments.suggested && (!result.lastSuggested || moments.suggested.isAfter(result.lastSuggested.moment))) {
suggested.moment = moment(suggested.timestamp);
if (suggested.mills) {
suggested.moment = moment(suggested.mills);
} else {
suggested.moment = moment(suggested.timestamp);
}
result.lastSuggested = suggested;
if (suggested.predBGs && (!result.lastPredBGs || suggested.moment.isAfter(result.lastPredBGs.moment))) {
result.lastPredBGs = _.isArray(suggested.predBGs) ? { values: suggested.predBGs } : suggested.predBGs;
Expand Down

0 comments on commit 89dfe21

Please sign in to comment.