Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple uploaders in virtual assistant delta calculation #6559

Merged
merged 9 commits into from
Jan 2, 2021
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