2020-07-26 08:50:34 +00:00
|
|
|
/* Magic Mirror
|
|
|
|
* Module: MMM-covid19
|
|
|
|
*
|
|
|
|
* Author: Sebastian Mark
|
|
|
|
* CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
|
|
|
|
* for civil use only
|
|
|
|
*/
|
|
|
|
|
|
|
|
Module.register("MMM-covid19", {
|
|
|
|
defaults: {
|
|
|
|
region: "Bonn",
|
|
|
|
updateInterval: 3 * 60 * 60 * 1000, // 4h
|
|
|
|
fadeSpeed: 0,
|
|
|
|
showHeader: true,
|
|
|
|
appendLocationNameToHeader: true,
|
|
|
|
data_url: "https://rp-online.de/app/interaktiv_server/data/rki_nrw_mapped.json.php",
|
|
|
|
},
|
|
|
|
cases: {
|
|
|
|
new7: "N/A",
|
|
|
|
active: "N/A",
|
|
|
|
total: "N/A",
|
|
|
|
death: "N/A",
|
|
|
|
cured: "N/A",
|
|
|
|
trend: "N/A",
|
|
|
|
ts: "N/A",
|
|
|
|
},
|
|
|
|
|
|
|
|
start: function() {
|
|
|
|
// init module and set update intervall
|
|
|
|
var self = this;
|
|
|
|
Log.log(this.name + ' is started!');
|
2020-07-26 16:40:10 +00:00
|
|
|
self.update_data();
|
2020-07-26 08:50:34 +00:00
|
|
|
setInterval(function() {
|
2020-07-26 16:40:10 +00:00
|
|
|
self.update_data();
|
2020-07-26 08:50:34 +00:00
|
|
|
self.updateDom(this.config.fadeSpeed);
|
|
|
|
}, this.config.updateInterval);
|
|
|
|
},
|
|
|
|
|
|
|
|
getHeader: function() {
|
|
|
|
// set module header
|
|
|
|
if (this.config.showHeader) {
|
|
|
|
this.data.header = "COVID-19 Daten";
|
|
|
|
if (this.config.appendLocationNameToHeader) {
|
|
|
|
this.data.header += " für " + this.config.region;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.data.header;
|
|
|
|
},
|
|
|
|
|
2020-07-26 16:40:10 +00:00
|
|
|
getStyles: function () {
|
|
|
|
// load custom css for module
|
|
|
|
return ["MMM-covid19.css"];
|
|
|
|
},
|
2020-07-26 08:50:34 +00:00
|
|
|
|
2020-07-26 16:40:10 +00:00
|
|
|
getTemplate: function () {
|
|
|
|
// load template for layout
|
|
|
|
return 'MMM-covid19.njk';
|
|
|
|
},
|
2020-07-26 08:50:34 +00:00
|
|
|
|
2020-07-26 16:40:10 +00:00
|
|
|
getTemplateData: function () {
|
|
|
|
// pass variables to template
|
|
|
|
return { cases: this.cases }
|
2020-07-26 08:50:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
update_data: function() {
|
2020-07-26 13:39:18 +00:00
|
|
|
// get and parse json data from source
|
2020-07-26 08:50:34 +00:00
|
|
|
var xmlHttp = new XMLHttpRequest();
|
|
|
|
xmlHttp.open( "GET", this.config.data_url, false ); // false for synchronous request
|
|
|
|
xmlHttp.send( null );
|
|
|
|
data = JSON.parse(xmlHttp.responseText);
|
|
|
|
|
|
|
|
// extract data
|
|
|
|
this.cases.new7 = data[this.config.region]["last_7"];
|
|
|
|
this.cases.active = data[this.config.region]["active"];
|
|
|
|
this.cases.total = data[this.config.region]["cases"];
|
|
|
|
this.cases.death = data[this.config.region]["tot"];
|
|
|
|
this.cases.cured = data[this.config.region]["gesund"];
|
|
|
|
this.cases.ts = data[this.config.region]["date"];
|
2020-07-26 13:39:18 +00:00
|
|
|
|
2020-07-26 08:50:34 +00:00
|
|
|
// determine trend:
|
|
|
|
// calc this and last weeks cases and substract
|
2020-07-26 13:39:18 +00:00
|
|
|
// result is the difference of new cases between this and last week
|
2020-07-26 08:50:34 +00:00
|
|
|
// +10: red (arrow up)
|
|
|
|
// +0: orange (arrow up)
|
|
|
|
// 0: normal (arrow right)
|
|
|
|
// -0: green (arrow down)
|
2020-07-26 16:40:10 +00:00
|
|
|
currentToLastWeekDiff = (data[this.config.region]["last_7"] * 2) - data[this.config.region]["last_14"]
|
2020-07-26 14:24:02 +00:00
|
|
|
if (currentToLastWeekDiff > 10) {
|
2020-07-26 08:50:34 +00:00
|
|
|
this.cases.trend = "<span class=bad>↗</span>";
|
|
|
|
} else if (currentToLastWeekDiff > 0) {
|
|
|
|
this.cases.trend = "<span class=warn>↗</span>";
|
2020-07-26 14:24:02 +00:00
|
|
|
} else if (currentToLastWeekDiff == 0) {
|
|
|
|
this.cases.trend = "&#rarr;";
|
|
|
|
} else if (currentToLastWeekDiff < 0) {
|
|
|
|
this.cases.trend = "<span class=good>↘</span>";
|
2020-07-26 08:50:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|