Skip to content

Instantly share code, notes, and snippets.

@mddub mddub/- Secret
Created Feb 29, 2016

Embed
What would you like to do?
d.getOpenAPSStatus = function(config) {
return Promise.all([
d.getLastOpenAPSStatus(config),
_getActiveTempBasal(config),
]).then(function(results) {
var statusEntry = results[0][0];
if (statusEntry === undefined) {
return '-';
}
function round(rate) {
return rate === 0 ? '0' : rate.toFixed(1);
}
var minutesAgo = Math.round((Date.now() - new Date(statusEntry['created_at']).getTime()) / (60 * 1000));
var recency = (minutesAgo < 60) ? minutesAgo : Math.round(minutesAgo / 60) + 'h';
var tempReported;
var enacted = statusEntry['openaps']['enacted'];
var activeTemp = results[1];
if (enacted && enacted['rate'] !== undefined && enacted['duration'] !== undefined) {
tempReported = round(enacted['rate']) + 'x' + enacted['duration'];
} else if (activeTemp) {
var remaining = Math.round(activeTemp.duration - (Date.now() - activeTemp.start) / (60 * 1000));
tempReported = round(activeTemp.rate) + 'x' + remaining;
}
var iob = '?';
if (statusEntry['openaps']['iob'] && statusEntry['openaps']['iob']['iob'] !== undefined) {
iob = statusEntry['openaps']['iob']['iob'].toFixed(1) + 'u';
}
return '(' + recency + ') ' + iob + (tempReported ? ' ' + tempReported : '');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.