Skip to content

Commit

Permalink
Support of chart rendering for blood sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Apr 3, 2020
1 parent 6d293c9 commit 13d5a0c
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Following types are supported:

## Changelog
### 1.4.0 (2020-04-03)
* (Apollon77) The blood glucose request supported now
* (bluefox) The blood glucose request supported now

### 1.3.4 (2020-02-26)
* (TA2k) Fixed deconz issues in Google Home
Expand Down
16 changes: 8 additions & 8 deletions admin/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"files": {
"main.css": "./static/css/main.d4bed9c6.chunk.css",
"main.js": "./static/js/main.01ddba60.chunk.js",
"main.js.map": "./static/js/main.01ddba60.chunk.js.map",
"main.js": "./static/js/main.4d44408f.chunk.js",
"main.js.map": "./static/js/main.4d44408f.chunk.js.map",
"runtime-main.js": "./static/js/runtime-main.28893cca.js",
"runtime-main.js.map": "./static/js/runtime-main.28893cca.js.map",
"static/css/2.b1b16afe.chunk.css": "./static/css/2.b1b16afe.chunk.css",
"static/js/2.48f2b2d8.chunk.js": "./static/js/2.48f2b2d8.chunk.js",
"static/js/2.48f2b2d8.chunk.js.map": "./static/js/2.48f2b2d8.chunk.js.map",
"static/js/2.73f12e4d.chunk.js": "./static/js/2.73f12e4d.chunk.js",
"static/js/2.73f12e4d.chunk.js.map": "./static/js/2.73f12e4d.chunk.js.map",
"index.html": "./index.html",
"precache-manifest.1710c7d3aa80a7f072bb4c254fef53b2.js": "./precache-manifest.1710c7d3aa80a7f072bb4c254fef53b2.js",
"precache-manifest.634dd4bb5ad777e31dde91815e8cb52f.js": "./precache-manifest.634dd4bb5ad777e31dde91815e8cb52f.js",
"service-worker.js": "./service-worker.js",
"static/css/2.b1b16afe.chunk.css.map": "./static/css/2.b1b16afe.chunk.css.map",
"static/css/main.d4bed9c6.chunk.css.map": "./static/css/main.d4bed9c6.chunk.css.map",
"static/js/2.48f2b2d8.chunk.js.LICENSE.txt": "./static/js/2.48f2b2d8.chunk.js.LICENSE.txt",
"static/js/2.73f12e4d.chunk.js.LICENSE.txt": "./static/js/2.73f12e4d.chunk.js.LICENSE.txt",
"static/media/copy-content.svg": "./static/media/copy-content.6fe0b363.svg"
},
"entrypoints": [
"static/js/runtime-main.28893cca.js",
"static/css/2.b1b16afe.chunk.css",
"static/js/2.48f2b2d8.chunk.js",
"static/js/2.73f12e4d.chunk.js",
"static/css/main.d4bed9c6.chunk.css",
"static/js/main.01ddba60.chunk.js"
"static/js/main.4d44408f.chunk.js"
]
}
2 changes: 1 addition & 1 deletion admin/index_m.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="./manifest.json"/><script type="text/javascript" src="./vendor/socket.io.js"></script><title>React App</title><link href="./static/css/2.b1b16afe.chunk.css" rel="stylesheet"><link href="./static/css/main.d4bed9c6.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function t(t){for(var n,i,l=t[0],a=t[1],f=t[2],c=0,s=[];c<l.length;c++)i=l[c],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&s.push(o[i][0]),o[i]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(p&&p(t);s.length;)s.shift()();return u.push.apply(u,f||[]),r()}function r(){for(var e,t=0;t<u.length;t++){for(var r=u[t],n=!0,l=1;l<r.length;l++){var a=r[l];0!==o[a]&&(n=!1)}n&&(u.splice(t--,1),e=i(i.s=r[0]))}return e}var n={},o={1:0},u=[];function i(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=n,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(r,n,function(t){return e[t]}.bind(null,n));return r},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="./";var l=this["webpackJsonpiot-admin"]=this["webpackJsonpiot-admin"]||[],a=l.push.bind(l);l.push=t,l=l.slice();for(var f=0;f<l.length;f++)t(l[f]);var p=a;r()}([])</script><script src="./static/js/2.48f2b2d8.chunk.js"></script><script src="./static/js/main.01ddba60.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="./manifest.json"/><script type="text/javascript" src="./vendor/socket.io.js"></script><title>React App</title><link href="./static/css/2.b1b16afe.chunk.css" rel="stylesheet"><link href="./static/css/main.d4bed9c6.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function t(t){for(var n,i,l=t[0],a=t[1],f=t[2],c=0,s=[];c<l.length;c++)i=l[c],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&s.push(o[i][0]),o[i]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(p&&p(t);s.length;)s.shift()();return u.push.apply(u,f||[]),r()}function r(){for(var e,t=0;t<u.length;t++){for(var r=u[t],n=!0,l=1;l<r.length;l++){var a=r[l];0!==o[a]&&(n=!1)}n&&(u.splice(t--,1),e=i(i.s=r[0]))}return e}var n={},o={1:0},u=[];function i(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=n,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(r,n,function(t){return e[t]}.bind(null,n));return r},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="./";var l=this["webpackJsonpiot-admin"]=this["webpackJsonpiot-admin"]||[],a=l.push.bind(l);l.push=t,l=l.slice();for(var f=0;f<l.length;f++)t(l[f]);var p=a;r()}([])</script><script src="./static/js/2.73f12e4d.chunk.js"></script><script src="./static/js/main.4d44408f.chunk.js"></script></body></html>
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "4e34e0e8c57d4ca40ee52d9c84d73732",
"revision": "a2a36b5cb1dd3a82e5961712e45ba8eb",
"url": "./index.html"
},
{
"revision": "816be2a46e08d49bf9d5",
"revision": "7ce77c151896717836d4",
"url": "./static/css/2.b1b16afe.chunk.css"
},
{
"revision": "982920a74467f2ec3b82",
"revision": "991320466c19e817eae0",
"url": "./static/css/main.d4bed9c6.chunk.css"
},
{
"revision": "816be2a46e08d49bf9d5",
"url": "./static/js/2.48f2b2d8.chunk.js"
"revision": "7ce77c151896717836d4",
"url": "./static/js/2.73f12e4d.chunk.js"
},
{
"revision": "d09ac505fec0e9130a1d5b85fb3fa6dc",
"url": "./static/js/2.48f2b2d8.chunk.js.LICENSE.txt"
"url": "./static/js/2.73f12e4d.chunk.js.LICENSE.txt"
},
{
"revision": "982920a74467f2ec3b82",
"url": "./static/js/main.01ddba60.chunk.js"
"revision": "991320466c19e817eae0",
"url": "./static/js/main.4d44408f.chunk.js"
},
{
"revision": "52690254395a433bc1e0",
Expand Down
2 changes: 1 addition & 1 deletion admin/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");

importScripts(
"./precache-manifest.1710c7d3aa80a7f072bb4c254fef53b2.js"
"./precache-manifest.634dd4bb5ad777e31dde91815e8cb52f.js"
);

self.addEventListener('message', (event) => {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions admin/static/js/main.01ddba60.chunk.js

This file was deleted.

1 change: 0 additions & 1 deletion admin/static/js/main.01ddba60.chunk.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions admin/static/js/main.4d44408f.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions admin/static/js/main.4d44408f.chunk.js.map

Large diffs are not rendered by default.

123 changes: 88 additions & 35 deletions lib/alexaCustomBlood.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
'use strict';
const textsT = require('./texts');
const moment = require('moment');
let getImage;

function AlexaCustomBlood(adapter) {
let lang = 'de';
let defaultHistory = '';
let response = {
timer: null,
request: null,
callback: null,
sessionId: null
};

function getResponse(text, shouldEndSession, lang) {
try {
getImage = getImage || require('./getImage');
} catch (e) {
adapter.log.warn('Cannot initialize getImage: ' + e);
}

function getResponse(text, image, shouldEndSession, lang) {
let response = {
version: '1.0',
sessionAttributes: {},
response: {
outputSpeech: {
type: 'PlainText',
text: text
text
},
card: {
content: text,
text,
title: '',
type: 'Standard',
image: {
smallImageUrl: '', // "https://url-to-small-card-image...",
largeImageUrl: '' // "https://url-to-large-card-image..."
largeImageUrl: image,
}
},
shouldEndSession: shouldEndSession || false
}
};
if (lang) {
response.response.card.title = textsT(lang, 'Your blood glucose is');
response.response.card.title = textsT(lang, 'Your blood glucose');
} else {
response.response.card.title = textsT(lang, 'Error');
}
Expand All @@ -44,8 +51,9 @@ function AlexaCustomBlood(adapter) {
return response;
}

this.setLanguage = _lang => {
this.setSettings = (_lang, _defaultHistory) => {
lang = _lang || 'de';
defaultHistory = _defaultHistory;
};

this.setResponse = (resp, shouldEndSession) => {
Expand Down Expand Up @@ -130,6 +138,44 @@ function AlexaCustomBlood(adapter) {
// "shouldLinkResultBeReturned": false
// }
// };
function renderImage(bloodInfoID) {
// expected:
// {
// from: timestamp // default now - 3 hours
// to: timestamp // default now
// width: image width // default 1200
// height: image width // default 800
// format: svg/png/jpg // default png
// }
const now = Date.now();

if (!getImage) {
return Promise.reject('No getImage loaded');
}

if (!defaultHistory) {
return getImage('no history instance');
} else {
return new Promise((resolve, reject) =>
adapter.sendTo(defaultHistory, 'getHistory', {
id: bloodInfoID,
options: {
start: now - 3 * 3600000,
end: now,
aggregate: 'none' // or 'none' to get raw values
}
}, result => {
if (!result || !result.result) {
result.result = (result && result.error) || 'no data received';
}

getImage(result.result)
.then(image => resolve(image))
.catch(e => reject(e));
}));
}
}

this.process = (request, bloodInfoID, callback) => {
if (!request || !request.request) {
adapter.log.error('Invalid request: no intent!');
Expand Down Expand Up @@ -168,36 +214,43 @@ function AlexaCustomBlood(adapter) {
callback(getResponse('Kein gültiger Wert gefunden', true));
}
} else {
let unit = (obj && obj.common && obj && obj.common.unit) || 'mg/dl';
const min = moment(new Date(state.ts)).locale(_lang).fromNow();
if (_lang === 'en') {
unit = unit === 'mmol/l' || unit === 'mmol' ? 'millimole per liter' : 'milligram per deciliter';
} else if (_lang === 'ru') {
unit = unit === 'mmol/l' || unit === 'mmol' ? 'миллимоль на литр' : 'миллиграм на децилитр';
} else {
unit = unit === 'mmol/l' || unit === 'mmol' ? 'Millimol pro Liter' : 'Milligramm pro Deziliter';
}
renderImage(bloodInfoID)
.catch(e => {
adapter.log.warn('Cannot generate chart: ' + e);
return null;
})
.then(image => {
let unit = (obj && obj.common && obj && obj.common.unit) || 'mg/dl';
const min = moment(new Date(state.ts)).locale(_lang).fromNow();
if (_lang === 'en') {
unit = unit === 'mmol/l' || unit === 'mmol' ? 'millimole per liter' : 'milligram per deciliter';
} else if (_lang === 'ru') {
unit = unit === 'mmol/l' || unit === 'mmol' ? 'миллимоль на литр' : 'миллиграм на децилитр';
} else {
unit = unit === 'mmol/l' || unit === 'mmol' ? 'Millimol pro Liter' : 'Milligramm pro Deziliter';
}

let text;
if (!adapter.config.amazonAlexaBloodShortAnswer) {
if (_lang === 'en') {
text = `Blood sugar is ${state.val} ${unit === 'mmol/l' || unit === 'mmol' ? 'millimole per liter' : 'milligram per deciliter'} and was measured ${min}`;
} else if (_lang === 'ru') {
text = `Уровень сахара в крови ${state.val} ${unit === 'mmol/l' || unit === 'mmol' ? 'миллимоль на литр' : 'миллиграм на децилитр'} и измерялся ${min}.`;
} else {
text = `Blutzucker ist ${state.val} ${unit === 'mmol/l' || unit === 'mmol' ? 'Millimol pro Liter' : 'Milligramm pro Deziliter'} und wurde ${min} gemessen`;
}
} else {
if (_lang === 'en') {
text = `${state.val} ${min}`;
} else if (_lang === 'ru') {
text = `${state.val} ${min}.`;
} else {
text = `${state.val} ${min}`;
}
}
let text;
if (!adapter.config.amazonAlexaBloodShortAnswer) {
if (_lang === 'en') {
text = `Blood sugar is ${state.val} ${unit === 'mmol/l' || unit === 'mmol' ? 'millimole per liter' : 'milligram per deciliter'} and was measured ${min}`;
} else if (_lang === 'ru') {
text = `Уровень сахара в крови ${state.val} ${unit === 'mmol/l' || unit === 'mmol' ? 'миллимоль на литр' : 'миллиграм на децилитр'} и измерялся ${min}.`;
} else {
text = `Blutzucker ist ${state.val} ${unit === 'mmol/l' || unit === 'mmol' ? 'Millimol pro Liter' : 'Milligramm pro Deziliter'} und wurde ${min} gemessen`;
}
} else {
if (_lang === 'en') {
text = `${state.val} ${min}`;
} else if (_lang === 'ru') {
text = `${state.val} ${min}.`;
} else {
text = `${state.val} ${min}`;
}
}

callback(getResponse(text, true, _lang));
callback(getResponse(text, image, true, _lang));
});
}
});
});
Expand Down
Loading

0 comments on commit 13d5a0c

Please sign in to comment.