Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MMM-COVID19-AMPEL.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* global Module */
  2. /* Magic Mirror
  3. * Module: MMM-COVID19-AMPEL
  4. *
  5. * By Daniel Osterkamp
  6. * MIT Licensed.
  7. */
  8. Module.register("MMM-COVID19-AMPEL", {
  9. defaults: {
  10. header: "COVID-19 Inzidenzwert",
  11. cityID: ["224"], // City ID from https://npgeo-corona-npgeo-de.hub.arcgis.com/datasets/917fc37a709542548cc3be077a786c17_0/data
  12. infoRowClass: "small", // small, medium
  13. showUpdateDateInHeader: true,
  14. showUpdateDateInRow: false,
  15. showTitle: true,
  16. showSKLK: true,
  17. showStatusLightLeft: true,
  18. showStatusLightRight: true,
  19. showCases: true,
  20. showCasesPerPeople: true,
  21. showDeathRatePerPeople: true,
  22. show7DayIncidence: true,
  23. showVaccinations: true,
  24. landModeOnly: false,
  25. numberOfDigits: 2,
  26. updateInterval: 3600000, // update interval in milliseconds
  27. fadeSpeed: 4000,
  28. updateDate: "",
  29. },
  30. getStyles: function () {
  31. return ["MMM-COVID19-AMPEL.css"];
  32. },
  33. getTranslations: function () {
  34. return {
  35. en: "translations/en.json",
  36. de: "translations/de.json",
  37. it: "translations/it.json",
  38. fr: "translations/fr.json",
  39. es: "translations/es.json"
  40. }
  41. },
  42. start: function () {
  43. this.getInfo();
  44. this.scheduleUpdate();
  45. },
  46. scheduleUpdate: function (delay) {
  47. var nextLoad = this.config.updateInterval;
  48. if (typeof delay !== "undefined" && delay >= 0) {
  49. nextLoad = delay;
  50. }
  51. var self = this;
  52. setInterval(function () {
  53. self.getInfo();
  54. }, nextLoad);
  55. },
  56. getInfo: function () {
  57. this.sendSocketNotification("GET_INCIDENTS", this.config.cityID);
  58. },
  59. socketNotificationReceived: function (notification, payload) {
  60. var self = this;
  61. if (notification === "INCIDENTS") {
  62. this.globalIncidents = payload;
  63. this.updateDom(self.config.fadeSpeed);
  64. }
  65. if (notification === "VACCINATIONS") {
  66. this.globalVaccinations = payload;
  67. var lines = this.globalVaccinations[this.globalVaccinations.length-1].split("\n");
  68. var result = lines[lines.length-2].split("\t");
  69. // this.amountPeopleFirstVaccination = result[26]
  70. this.globalVaccinations = result[29]*100;
  71. this.globalSecondVaccination = result[30]*100;
  72. // this.totalPeople = this.amountPeopleFirstVaccination/this.globalVaccinations;
  73. // this.globalThirdVaccinations = result[28]*this.totalPeople;
  74. this.updateDom(self.config.fadeSpeed);
  75. }
  76. },
  77. getHeader: function () {
  78. var headerTitle = this.config.header;
  79. var vaccinationsLabel = this.translate("VacQuota");
  80. if (this.config.showUpdateDateInHeader) {
  81. headerTitle += " " + this.config.updateDate;
  82. }
  83. if (this.config.showVaccinations && !(this.globalVaccinations === null || this.globalVaccinations === undefined ))
  84. headerTitle += " - " + vaccinationsLabel + " " + this.globalVaccinations.toFixed(this.config.numberOfDigits) + "% / " + this.globalSecondVaccination.toFixed(this.config.numberOfDigits) + "%";
  85. return headerTitle;
  86. },
  87. getDom: function () {
  88. var wrapper = document.createElement("table");
  89. if (this.globalIncidents === null || this.globalIncidents === undefined )
  90. return wrapper;
  91. if (Object.entries(this.globalIncidents).length === 0 ) return wrapper;
  92. var globalStats = this.globalIncidents;
  93. //globalStats is array with attributes and ITEMS
  94. wrapper.className = this.config.tableClass || "covidAmpel";
  95. if (this.config.showTitle) {
  96. let tableRow = document.createElement("tr");
  97. let incidentStateColora = document.createElement("td");
  98. let incidentCityName = document.createElement("td");
  99. let incidentSKLK = document.createElement("td");
  100. let incidentBLName = document.createElement("td");
  101. let incidentUpdateDate = document.createElement("td");
  102. let totalCases = document.createElement("td");
  103. let casesPerCapita = document.createElement("td");
  104. let deathPerInfection = document.createElement("td");
  105. let incident7DayNumber = document.createElement("td");
  106. let incidentStateColorb = document.createElement("td");
  107. incidentCityName.innerHTML = this.translate('Location');
  108. incidentCityName.className = this.config.infoRowClass;
  109. incidentSKLK.innerHTML = this.translate('Region');
  110. incidentSKLK.className = this.config.infoRowClass;
  111. incidentBLName.innerHTML = this.translate('Land');
  112. incidentBLName.className = this.config.infoRowClass;
  113. incidentUpdateDate.innerHTML = this.translate('Updated on');
  114. incidentUpdateDate.className = this.config.infoRowClass;
  115. totalCases.innerHTML = this.translate('Infections');
  116. totalCases.className = this.config.infoRowClass;
  117. casesPerCapita.innerHTML = this.translate('Infection rate %');
  118. casesPerCapita.className = this.config.infoRowClass;
  119. deathPerInfection.innerHTML = this.translate('Todesfälle') ;
  120. deathPerInfection.className = this.config.infoRowClass;
  121. incident7DayNumber.innerHTML = this.translate('Inzidenz');
  122. incident7DayNumber.className = this.config.infoRowClass;
  123. if (this.config.showStatusLightLeft) {
  124. tableRow.appendChild(incidentStateColora);
  125. }
  126. if (!this.config.landModeOnly) {
  127. tableRow.appendChild(incidentCityName);
  128. if (this.config.showSKLK) tableRow.appendChild(incidentSKLK);
  129. }
  130. if (this.config.landModeOnly) tableRow.appendChild(incidentBLName);
  131. if (this.config.showUpdateDateInRow) {
  132. tableRow.appendChild(incidentUpdateDate);
  133. }
  134. if (this.config.showCases && !this.config.landModeOnly) {
  135. tableRow.appendChild(totalCases);
  136. }
  137. if (this.config.showCasesPerPeople && !this.config.landModeOnly) {
  138. tableRow.appendChild(casesPerCapita);
  139. }
  140. if (this.config.showDeathRatePerPeople && !this.config.landModeOnly) {
  141. tableRow.appendChild(deathPerInfection);
  142. }
  143. if (this.config.show7DayIncidence) {
  144. tableRow.appendChild(incident7DayNumber);
  145. }
  146. if (this.config.showStatusLightRight) {
  147. tableRow.appendChild(incidentStateColorb);
  148. }
  149. wrapper.appendChild(tableRow);
  150. }
  151. globalStats.sort((a, b) => (a.attributes.GEN > b.attributes.GEN) ? 1 : -1)
  152. for (let i = 0; i < globalStats.length; i++) {
  153. const element = globalStats[i].attributes;
  154. let tableRow = document.createElement("tr");
  155. let incidentStateColora = document.createElement("td");
  156. let incidentCityName = document.createElement("td");
  157. let incidentSKLK = document.createElement("td");
  158. let incidentBLName = document.createElement("td");
  159. let incidentUpdateDate = document.createElement("td");
  160. let totalCases = document.createElement("td");
  161. let casesPerCapita = document.createElement("td");
  162. let deathPerInfection = document.createElement("td");
  163. let incident7DayNumber = document.createElement("td");
  164. let incidentStateColorb = document.createElement("td");
  165. incidentCityName.innerHTML = element.GEN;
  166. incidentCityName.className = this.config.infoRowClass;
  167. incidentSKLK.innerHTML = element.BEZ;
  168. incidentSKLK.className = this.config.infoRowClass;
  169. incidentBLName.innerHTML = element.BL;
  170. incidentBLName.className = this.config.infoRowClass;
  171. this.config.updateDate = element.last_update;
  172. if (this.config.showUpdateDateInRow) {
  173. incidentUpdateDate.innerHTML = element.last_update;
  174. incidentUpdateDate.className = this.config.infoRowClass;
  175. }
  176. if (this.config.showCases && !this.config.landModeOnly) {
  177. var cs = element.cases;
  178. totalCases.innerHTML = cs.toLocaleString();
  179. totalCases.className = this.config.infoRowClass;
  180. }
  181. if (this.config.showCasesPerPeople && !this.config.landModeOnly) {
  182. casesPerCapita.innerHTML =
  183. element.cases_per_population.toFixed(this.config.numberOfDigits) + "%";
  184. casesPerCapita.className = this.config.infoRowClass;
  185. }
  186. if (this.config.showDeathRatePerPeople && !this.config.landModeOnly) {
  187. deathPerInfection.innerHTML = element.death_rate.toFixed(this.config.numberOfDigits) + "%";
  188. deathPerInfection.className = this.config.infoRowClass;
  189. }
  190. if (this.config.show7DayIncidence && !this.config.landModeOnly) {
  191. incident7DayNumber.className = this.config.infoRowClass;
  192. incident7DayNumber.innerHTML = (
  193. Math.round(element.cases7_per_100k * 100) / 100
  194. ).toFixed(this.config.numberOfDigits);
  195. }
  196. if (this.config.show7DayIncidence && this.config.landModeOnly) {
  197. incident7DayNumber.className = this.config.infoRowClass;
  198. incident7DayNumber.innerHTML = (
  199. Math.round(element.cases7_bl_per_100k * 100) / 100
  200. ).toFixed(this.config.numberOfDigits);
  201. }
  202. incidentStateColora.innerHTML = "__";
  203. incidentStateColorb.innerHTML = "__";
  204. if (parseFloat(element.cases7_per_100k) < 35) {
  205. incidentStateColora.className = incidentStateColorb.className = "green";
  206. }
  207. if (parseFloat(element.cases7_per_100k) >= 35) {
  208. incidentStateColora.className = incidentStateColorb.className =
  209. "yellow";
  210. }
  211. if (parseFloat(element.cases7_per_100k) >= 50) {
  212. incidentStateColora.className = incidentStateColorb.className = "red";
  213. }
  214. if (parseFloat(element.cases7_per_100k) >= 100) {
  215. incidentStateColora.className = incidentStateColorb.className =
  216. "darkred";
  217. }
  218. if (parseFloat(element.cases7_per_100k) >= 300) {
  219. incidentStateColora.className = incidentStateColorb.className =
  220. "purple";
  221. }
  222. if (this.config.landModeOnly) {
  223. if (parseFloat(element.cases7_bl_per_100k) < 35) {
  224. incidentStateColora.className = incidentStateColorb.className = "green";
  225. }
  226. if (parseFloat(element.cases7_bl_per_100k) >= 35) {
  227. incidentStateColora.className = incidentStateColorb.className =
  228. "yellow";
  229. }
  230. if (parseFloat(element.cases7_bl_per_100k) >= 50) {
  231. incidentStateColora.className = incidentStateColorb.className = "red";
  232. }
  233. if (parseFloat(element.cases7_bl_per_100k) >= 100) {
  234. incidentStateColora.className = incidentStateColorb.className =
  235. "darkred";
  236. }
  237. if (parseFloat(element.cases7_bl_per_100k) >= 300) {
  238. incidentStateColora.className = incidentStateColorb.className =
  239. "purple";
  240. }
  241. }
  242. if (this.config.showStatusLightLeft) {
  243. tableRow.appendChild(incidentStateColora);
  244. }
  245. if (!this.config.landModeOnly) {
  246. tableRow.appendChild(incidentCityName);
  247. if (this.config.showSKLK) tableRow.appendChild(incidentSKLK)
  248. }
  249. if (this.config.landModeOnly) tableRow.appendChild(incidentBLName);
  250. if (this.config.showUpdateDateInRow) {
  251. tableRow.appendChild(incidentUpdateDate);
  252. }
  253. if (this.config.showCases && !this.config.landModeOnly) {
  254. tableRow.appendChild(totalCases);
  255. }
  256. if (this.config.showCasesPerPeople && !this.config.landModeOnly) {
  257. tableRow.appendChild(casesPerCapita);
  258. }
  259. if (this.config.showDeathRatePerPeople && !this.config.landModeOnly) {
  260. tableRow.appendChild(deathPerInfection);
  261. }
  262. if (this.config.show7DayIncidence && !this.config.landModeOnly) {
  263. tableRow.appendChild(incident7DayNumber);
  264. }
  265. if (this.config.show7DayIncidence && this.config.landModeOnly) {
  266. tableRow.appendChild(incident7DayNumber);
  267. }
  268. if (this.config.showStatusLightRight) {
  269. tableRow.appendChild(incidentStateColorb);
  270. }
  271. wrapper.appendChild(tableRow);
  272. }
  273. return wrapper;
  274. },
  275. });