Calculate 3h average only if data is available

pull/1887/head
Marco H 2022-06-12 17:46:25 +02:00
parent da9261446f
commit 02bb0ab481
1 changed files with 8 additions and 4 deletions

View File

@ -171,11 +171,15 @@
storage.writeJSON(LOG_FILE, history3);
// calculate 3h average for widget
let sum = 0;
for (let i = 0; i < history3.length; i++) {
sum += history3[i]["p"];
if (history3.length > 0) {
let sum = 0;
for (let i = 0; i < history3.length; i++) {
sum += history3[i]["p"];
}
threeHourAvrPressure = sum / history3.length;
} else {
threeHourAvrPressure = undefined;
}
threeHourAvrPressure = sum / history3.length;
}