Function for filtering weather alerts

This commit is contained in:
2025-03-16 03:59:03 -04:00
parent b4fbc2f5e6
commit 96c4918d76

View File

@ -0,0 +1,46 @@
let alerts = msg.payload
// Filter for Severe Thunderstorm Warnings
let ts = alerts.filter(function(alert) {
if (alert.raw.properties &&
alert.raw.properties.event === "Severe Thunderstorm Warning") {
return true
}
})
// Filter for Severe Thunderstorm Warnings with tornado detection
// that have a tornado possible parameter
let tstp = alerts.filter(function(alert) {
if (alert.raw.properties &&
alert.raw.properties.event === "Severe Thunderstorm Warning" &&
alert.raw.properties.parameters &&
alert.raw.properties.parameters.tornadoDetection &&
alert.raw.properties.parameters.tornadoDetection.length > 0) {
let tornadoPossible = alert.raw.properties.parameters.tornadoDetection[0]
return tornadoPossible === "POSSIBLE"
}
})
// Filter for Flash Flood Warnings
let flash_flood = alerts.filter(function(alert) {
if (alert.raw.properties &&
alert.raw.properties.event === "Flash Flood Warning") {
return true
}
})
// If there are any alerts, return them
msg.ts = ts
msg.ts_count = ts.length
msg.tstp = tstp
msg.tstp_count = tstp.length
msg.flash_flood = flash_flood
msg.flash_flood_count = flash_flood.length
return msg