Skip to content

Commit

Permalink
Added support for multiple uploaders in virtual assistant delta calc…
Browse files Browse the repository at this point in the history
…ulation (#6559)

* Added support for multiple uploaders in delta calculation

* Moved moment creation

* Moved delta stuff into bgnow plugin

* Typo

* Removed old implementation

* Removed accidental translations

* Added new translation key
  • Loading branch information
inventor96 authored Jan 2, 2021
1 parent 405eb0d commit 773f89e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
30 changes: 30 additions & 0 deletions lib/plugins/bgnow.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ function init (ctx) {
delta.mean5MinsAgo = delta.interpolated ?
recent.mean - delta.absolute / delta.elapsedMins * 5 : recent.mean - delta.absolute;

delta.times = {
recent: recent.mills
, previous: previous.mills
};

delta.mgdl = Math.round(recent.mean - delta.mean5MinsAgo);

delta.scaled = sbx.settings.units === 'mmol' ?
Expand Down Expand Up @@ -254,6 +259,31 @@ function init (ctx) {
});
};

function virtAsstDelta(next, slots, sbx) {
var delta = sbx.properties.delta;

next(
translate('virtAsstTitleDelta')
, translate(delta.interpolated ? 'virtAsstDeltaEstimated' : 'virtAsstDelta'
, {
params: [
delta.display == '+0' ? '0' : delta.display
, moment(delta.times.recent).from(moment(sbx.time))
, moment(delta.times.previous).from(moment(sbx.time))
]
}
)
);
}

bgnow.virtAsst = {
intentHandlers: [{
intent: "MetricNow"
, metrics: ["delta"]
, intentHandler: virtAsstDelta
}]
};

return bgnow;

}
Expand Down
20 changes: 0 additions & 20 deletions lib/plugins/virtAsstBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,6 @@ function init(env, ctx) {
callback(translate('virtAsstTitleCurrentBG'), status);
});
}, ['bg', 'blood glucose', 'number']);

// blood sugar delta
configuredPlugin.configureIntentHandler('MetricNow', function (callback, slots, sbx) {
if (sbx.properties.delta && sbx.properties.delta.display) {
entries.list({count: 2}, function(err, records) {
callback(
translate('virtAsstTitleDelta'),
translate('virtAsstDelta', {
params: [
sbx.properties.delta.display == '+0' ? '0' : sbx.properties.delta.display,
moment(records[0].date).from(moment(sbx.time)),
moment(records[1].date).from(moment(sbx.time))
]
})
);
});
} else {
callback(translate('virtAsstTitleDelta'), translate('virtAsstUnknown'));
}
}, ['delta']);
};

virtAsstBase.setupVirtAsstHandlers = function (configuredPlugin) {
Expand Down
1 change: 1 addition & 0 deletions translations/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@
,"virtAsstCGMBattOne":"Your CGM battery was %1 volts as of %2."
,"virtAsstCGMBattTwo":"Your CGM battery levels were %1 volts and %2 volts as of %3."
,"virtAsstDelta":"Your delta was %1 between %2 and %3."
,"virtAsstDeltaEstimated": "Your estimated delta was %1 between %2 and %3."
,"virtAsstUnknownIntentTitle":"Unknown Intent"
,"virtAsstUnknownIntentText":"I'm sorry, I don't know what you're asking for."
,"Fat [g]":"Fat [g]"
Expand Down

0 comments on commit 773f89e

Please sign in to comment.