Fix logging of entries & calculation of alarms

master
Marco Heiming 2022-06-22 15:40:36 +02:00
parent 5f11743d76
commit c2c7d168a7
1 changed files with 35 additions and 36 deletions

View File

@ -129,10 +129,7 @@ function checkForAlarms(pressure) {
if (drop3halarm > 0 || raise3halarm > 0) {
// we need at least 30 minutes of data for reliable detection
const diffDateAge = Math.abs(history3[0]["ts"] - ts);
if (diffDateAge < 30 * 60) {
return;
}
if (diffDateAge > 30 * 60) {
// Get oldest entry:
const oldestPressure = history3[0]["p"];
if (oldestPressure != undefined && oldestPressure > 0) {
@ -142,9 +139,9 @@ function checkForAlarms(pressure) {
if (drop3halarm > 0 && oldestPressure > pressure) {
if (diffPressure >= drop3halarm) {
if (doWeNeedToWarn("dropWarnTs")) {
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
Math.round(oldestPressure) + " to " +
Math.round(pressure) + " hPa",
showAlarm((Math.round(diffPressure * 10) / 10) +
" hPa/3h from " + Math.round(oldestPressure) +
" to " + Math.round(pressure) + " hPa",
"dropWarnTs");
}
} else {
@ -160,9 +157,9 @@ function checkForAlarms(pressure) {
if (raise3halarm > 0 && oldestPressure < pressure) {
if (diffPressure >= raise3halarm) {
if (doWeNeedToWarn("raiseWarnTs")) {
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
Math.round(oldestPressure) + " to " +
Math.round(pressure) + " hPa",
showAlarm((Math.round(diffPressure * 10) / 10) +
" hPa/3h from " + Math.round(oldestPressure) +
" to " + Math.round(pressure) + " hPa",
"raiseWarnTs");
}
} else {
@ -176,8 +173,10 @@ function checkForAlarms(pressure) {
}
}
}
}
history3.push(d);
// write data to storage
storage.writeJSON(LOG_FILE, history3);
@ -219,6 +218,7 @@ function check() {
medianPressure = Math.round(E.sum(median.slice(mid - 4, mid + 5)) / 9);
if (medianPressure > 0) {
turnOff();
draw();
checkForAlarms(medianPressure);
}
}
@ -248,17 +248,16 @@ function draw() {
g.setFont("6x8", 1).setFontAlign(1, 0);
const x = this.x, y = this.y;
if (medianPressure == undefined) {
// trigger a new check
check();
// lets load last value from log (if available)
if (history3.length > 0) {
medianPressure = history3[history3.length - 1]["p"];
}
g.drawString("...", x + 24, y + 6);
g.drawString(Math.round(medianPressure), x + 24, y + 6);
} else {
g.drawString("...", x + 24, y + 6);
}
} else {
g.drawString(Math.round(medianPressure), x + 24, y + 6);
}
@ -269,7 +268,7 @@ function draw() {
if (threeHourAvrPressure != undefined) {
if (medianPressure != undefined) {
const diff = Math.round(medianPressure - threeHourAvrPressure);
g.drawString((diff > 0 ? "+" : "") + diff, x + 24, y + 6 + 10);
g.drawString((diff > 0 ? "+" : "" + diff), x + 24, y + 6 + 10);
}
}
}