mirror of https://github.com/espruino/BangleApps
Fix warning calculation
parent
ac74ec2818
commit
5f11743d76
|
@ -3,4 +3,5 @@
|
||||||
0.03: Fix crash
|
0.03: Fix crash
|
||||||
0.04: Use Prompt with dismiss and pause
|
0.04: Use Prompt with dismiss and pause
|
||||||
Improve barometer value median calculation
|
Improve barometer value median calculation
|
||||||
0.05: Show difference of last measurement to pressure average of the the last three hours in the widget
|
0.05: Fix warning calculation
|
||||||
|
Show difference of last measurement to pressure average of the the last three hours in the widget
|
||||||
|
|
|
@ -68,9 +68,12 @@ function showAlarm(body, key) {
|
||||||
}, 20000);
|
}, 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns true if an alarm should be triggered
|
||||||
|
*/
|
||||||
function doWeNeedToWarn(key) {
|
function doWeNeedToWarn(key) {
|
||||||
const tsNow = Math.round(Date.now() / 1000); // seconds
|
const tsNow = Math.round(Date.now() / 1000); // seconds
|
||||||
return setting(key) == 0 || setting(key) < tsNow;
|
return setting(key) == undefined || setting(key) == 0 || setting(key) < tsNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForAlarms(pressure) {
|
function checkForAlarms(pressure) {
|
||||||
|
@ -96,26 +99,26 @@ function checkForAlarms(pressure) {
|
||||||
if (setting("lowalarm")) {
|
if (setting("lowalarm")) {
|
||||||
// Is below the alarm threshold?
|
// Is below the alarm threshold?
|
||||||
if (pressure <= setting("min")) {
|
if (pressure <= setting("min")) {
|
||||||
if (!doWeNeedToWarn("lastLowWarningTs")) {
|
if (!doWeNeedToWarn("lowWarnTs")) {
|
||||||
showAlarm("Pressure low: " + Math.round(pressure) + " hPa",
|
showAlarm("Pressure low: " + Math.round(pressure) + " hPa",
|
||||||
"lastLowWarningTs");
|
"lowWarnTs");
|
||||||
alreadyWarned = true;
|
alreadyWarned = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveSetting("lastLowWarningTs", 0);
|
saveSetting("lowWarnTs", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setting("highalarm")) {
|
if (setting("highalarm")) {
|
||||||
// Is above the alarm threshold?
|
// Is above the alarm threshold?
|
||||||
if (pressure >= setting("max")) {
|
if (pressure >= setting("max")) {
|
||||||
if (doWeNeedToWarn("lastHighWarningTs")) {
|
if (doWeNeedToWarn("highWarnTs")) {
|
||||||
showAlarm("Pressure high: " + Math.round(pressure) + " hPa",
|
showAlarm("Pressure high: " + Math.round(pressure) + " hPa",
|
||||||
"lastHighWarningTs");
|
"highWarnTs");
|
||||||
alreadyWarned = true;
|
alreadyWarned = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveSetting("lastHighWarningTs", 0);
|
saveSetting("highWarnTs", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +127,9 @@ function checkForAlarms(pressure) {
|
||||||
const drop3halarm = setting("drop3halarm");
|
const drop3halarm = setting("drop3halarm");
|
||||||
const raise3halarm = setting("raise3halarm");
|
const raise3halarm = setting("raise3halarm");
|
||||||
if (drop3halarm > 0 || raise3halarm > 0) {
|
if (drop3halarm > 0 || raise3halarm > 0) {
|
||||||
// we need at least 30min 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 < 10 * 60) { // todo change to 1800
|
if (diffDateAge < 30 * 60) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,34 +140,38 @@ function checkForAlarms(pressure) {
|
||||||
|
|
||||||
// drop alarm
|
// drop alarm
|
||||||
if (drop3halarm > 0 && oldestPressure > pressure) {
|
if (drop3halarm > 0 && oldestPressure > pressure) {
|
||||||
if (diffPressure > drop3halarm) {
|
if (diffPressure >= drop3halarm) {
|
||||||
if (doWeNeedToWarn("lastDropWarningTs")) {
|
if (doWeNeedToWarn("dropWarnTs")) {
|
||||||
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
|
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
|
||||||
Math.round(oldestPressure) + " to " +
|
Math.round(oldestPressure) + " to " +
|
||||||
Math.round(pressure) + " hPa",
|
Math.round(pressure) + " hPa",
|
||||||
"lastDropWarningTs");
|
"dropWarnTs");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveSetting("lastDropWarningTs", 0);
|
if (ts > setting("dropWarnTs"))
|
||||||
|
saveSetting("dropWarnTs", 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveSetting("lastDropWarningTs", 0);
|
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("lastRaiseWarningTs")) {
|
if (doWeNeedToWarn("raiseWarnTs")) {
|
||||||
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
|
showAlarm((Math.round(diffPressure * 10) / 10) + " hPa/3h from " +
|
||||||
Math.round(oldestPressure) + " to " +
|
Math.round(oldestPressure) + " to " +
|
||||||
Math.round(pressure) + " hPa",
|
Math.round(pressure) + " hPa",
|
||||||
"lastRaiseWarningTs");
|
"raiseWarnTs");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveSetting("lastRaiseWarningTs", 0);
|
if (ts > setting("raiseWarnTs"))
|
||||||
|
saveSetting("raiseWarnTs", 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
saveSetting("lastRaiseWarningTs", 0);
|
if (ts > setting("raiseWarnTs"))
|
||||||
|
saveSetting("raiseWarnTs", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue