Fix logging of entries & calculation of alarms
parent
5f11743d76
commit
c2c7d168a7
|
|
@ -129,55 +129,54 @@ function checkForAlarms(pressure) {
|
||||||
if (drop3halarm > 0 || raise3halarm > 0) {
|
if (drop3halarm > 0 || raise3halarm > 0) {
|
||||||
// we need at least 30 minutes of data for reliable detection
|
// we need at least 30 minutes of data for reliable detection
|
||||||
const diffDateAge = Math.abs(history3[0]["ts"] - ts);
|
const diffDateAge = Math.abs(history3[0]["ts"] - ts);
|
||||||
if (diffDateAge < 30 * 60) {
|
if (diffDateAge > 30 * 60) {
|
||||||
return;
|
// Get oldest entry:
|
||||||
}
|
const oldestPressure = history3[0]["p"];
|
||||||
|
if (oldestPressure != undefined && oldestPressure > 0) {
|
||||||
|
const diffPressure = Math.abs(oldestPressure - pressure);
|
||||||
|
|
||||||
// Get oldest entry:
|
// drop alarm
|
||||||
const oldestPressure = history3[0]["p"];
|
if (drop3halarm > 0 && oldestPressure > pressure) {
|
||||||
if (oldestPressure != undefined && oldestPressure > 0) {
|
if (diffPressure >= drop3halarm) {
|
||||||
const diffPressure = Math.abs(oldestPressure - pressure);
|
if (doWeNeedToWarn("dropWarnTs")) {
|
||||||
|
showAlarm((Math.round(diffPressure * 10) / 10) +
|
||||||
// drop alarm
|
" hPa/3h from " + Math.round(oldestPressure) +
|
||||||
if (drop3halarm > 0 && oldestPressure > pressure) {
|
" to " + Math.round(pressure) + " hPa",
|
||||||
if (diffPressure >= drop3halarm) {
|
"dropWarnTs");
|
||||||
if (doWeNeedToWarn("dropWarnTs")) {
|
}
|
||||||
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
|
} else {
|
||||||
Math.round(oldestPressure) + " to " +
|
if (ts > setting("dropWarnTs"))
|
||||||
Math.round(pressure) + " hPa",
|
saveSetting("dropWarnTs", 0);
|
||||||
"dropWarnTs");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ts > setting("dropWarnTs"))
|
if (ts > setting("dropWarnTs"))
|
||||||
saveSetting("dropWarnTs", 0);
|
saveSetting("dropWarnTs", 0);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (ts > setting("dropWarnTs"))
|
|
||||||
saveSetting("dropWarnTs", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// raise alarm
|
// raise alarm
|
||||||
if (raise3halarm > 0 && oldestPressure < pressure) {
|
if (raise3halarm > 0 && oldestPressure < pressure) {
|
||||||
if (diffPressure >= raise3halarm) {
|
if (diffPressure >= raise3halarm) {
|
||||||
if (doWeNeedToWarn("raiseWarnTs")) {
|
if (doWeNeedToWarn("raiseWarnTs")) {
|
||||||
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
|
showAlarm((Math.round(diffPressure * 10) / 10) +
|
||||||
Math.round(oldestPressure) + " to " +
|
" hPa/3h from " + Math.round(oldestPressure) +
|
||||||
Math.round(pressure) + " hPa",
|
" to " + Math.round(pressure) + " hPa",
|
||||||
"raiseWarnTs");
|
"raiseWarnTs");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ts > setting("raiseWarnTs"))
|
||||||
|
saveSetting("raiseWarnTs", 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ts > setting("raiseWarnTs"))
|
if (ts > setting("raiseWarnTs"))
|
||||||
saveSetting("raiseWarnTs", 0);
|
saveSetting("raiseWarnTs", 0);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (ts > setting("raiseWarnTs"))
|
|
||||||
saveSetting("raiseWarnTs", 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
history3.push(d);
|
history3.push(d);
|
||||||
|
|
||||||
// write data to storage
|
// write data to storage
|
||||||
storage.writeJSON(LOG_FILE, history3);
|
storage.writeJSON(LOG_FILE, history3);
|
||||||
|
|
||||||
|
|
@ -219,6 +218,7 @@ function check() {
|
||||||
medianPressure = Math.round(E.sum(median.slice(mid - 4, mid + 5)) / 9);
|
medianPressure = Math.round(E.sum(median.slice(mid - 4, mid + 5)) / 9);
|
||||||
if (medianPressure > 0) {
|
if (medianPressure > 0) {
|
||||||
turnOff();
|
turnOff();
|
||||||
|
draw();
|
||||||
checkForAlarms(medianPressure);
|
checkForAlarms(medianPressure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -248,17 +248,16 @@ function draw() {
|
||||||
g.setFont("6x8", 1).setFontAlign(1, 0);
|
g.setFont("6x8", 1).setFontAlign(1, 0);
|
||||||
const x = this.x, y = this.y;
|
const x = this.x, y = this.y;
|
||||||
if (medianPressure == undefined) {
|
if (medianPressure == undefined) {
|
||||||
|
|
||||||
// trigger a new check
|
// trigger a new check
|
||||||
check();
|
check();
|
||||||
|
|
||||||
// lets load last value from log (if available)
|
// lets load last value from log (if available)
|
||||||
if (history3.length > 0) {
|
if (history3.length > 0) {
|
||||||
medianPressure = history3[history3.length - 1]["p"];
|
medianPressure = history3[history3.length - 1]["p"];
|
||||||
|
g.drawString(Math.round(medianPressure), x + 24, y + 6);
|
||||||
|
} else {
|
||||||
|
g.drawString("...", x + 24, y + 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.drawString("...", x + 24, y + 6);
|
|
||||||
g.drawString(Math.round(medianPressure), x + 24, y + 6);
|
|
||||||
} else {
|
} else {
|
||||||
g.drawString(Math.round(medianPressure), x + 24, y + 6);
|
g.drawString(Math.round(medianPressure), x + 24, y + 6);
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +268,7 @@ function draw() {
|
||||||
if (threeHourAvrPressure != undefined) {
|
if (threeHourAvrPressure != undefined) {
|
||||||
if (medianPressure != undefined) {
|
if (medianPressure != undefined) {
|
||||||
const diff = Math.round(medianPressure - threeHourAvrPressure);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue