Rename Defiance file for use as local alerts template
This commit is contained in:
123
weather/local_alerts.js
Normal file
123
weather/local_alerts.js
Normal file
@@ -0,0 +1,123 @@
|
||||
const severeWarningEvents = ["Severe Thunderstorm Warning","Destructive Severe Thunderstorm Warning","Considerable Destructive Severe Thunderstorm Warning"]
|
||||
const tornadoWarningEvents = ["Tornado Warning","Radar Indicated Tornado Warning","Confirmed Tornado Warning","Tornado Emergency"]
|
||||
const tornadoWatchEvents = ["Tornado Watch"]
|
||||
const severeThunderstormWatchEvents = ["Severe Thunderstorm Watch"]
|
||||
|
||||
let alerts = msg.payload.features
|
||||
let tornado_possible = false
|
||||
let considerable_destructive = false
|
||||
let confirmed = false
|
||||
|
||||
// Filter for Severe Thunderstorm Warnings
|
||||
|
||||
let ts = alerts.filter(function(alert) {
|
||||
if (alert.properties &&
|
||||
severeWarningEvents.includes(alert.properties.event)) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
// Filter for Severe Thunderstorm Warnings with tornado detection
|
||||
// that have a tornado possible parameter
|
||||
|
||||
let tstp = alerts.filter(function(alert) {
|
||||
if (alert.properties &&
|
||||
severeWarningEvents.includes(alert.properties.event) &&
|
||||
alert.properties.parameters &&
|
||||
alert.properties.parameters.tornadoDetection &&
|
||||
alert.properties.parameters.tornadoDetection.length > 0) {
|
||||
let tornadoPossible = alert.properties.parameters.tornadoDetection[0]
|
||||
return tornadoPossible === "POSSIBLE"
|
||||
}
|
||||
})
|
||||
|
||||
if (tstp.length > 0) {
|
||||
tornado_possible = true
|
||||
}
|
||||
|
||||
// Filter for considerable destructive severe thunderstorm warnings
|
||||
|
||||
let cdst = alerts.filter(function(alert) {
|
||||
if (alert.properties &&
|
||||
alert.properties.event === "Considerable Destructive Severe Thunderstorm Warning") {
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
if (cdst.length > 0) {
|
||||
considerable_destructive = true
|
||||
}
|
||||
|
||||
// Filter for Tornado Warnings
|
||||
|
||||
let tornado = alerts.filter(function(alert) {
|
||||
if (alert.properties &&
|
||||
tornadoWarningEvents.includes(alert.properties.event)) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
let confirmed_tornado = alerts.filter(function(alert) {
|
||||
if (alert.properties &&
|
||||
alert.properties.event === "Confirmed Tornado Warning") {
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
if (confirmed_tornado.length > 0) {
|
||||
confirmed = true
|
||||
}
|
||||
|
||||
// Filter for Tornado Watches
|
||||
|
||||
let tornado_watch = alerts.filter(function(alert) {
|
||||
if (alert.properties &&
|
||||
tornadoWatchEvents.includes(alert.properties.event)) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
// Filter for Severe Thunderstorm Watches
|
||||
|
||||
let severe_thunderstorm_watch = alerts.filter(function(alert) {
|
||||
if (alert.properties &&
|
||||
severeThunderstormWatchEvents.includes(alert.properties.event)) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
// If there are any alerts, return them
|
||||
|
||||
let tstormMsg = {
|
||||
"payload": {
|
||||
"alerts": ts,
|
||||
"count": ts.length,
|
||||
"tornado_possible": tornado_possible,
|
||||
"considerable_destructive": considerable_destructive
|
||||
}
|
||||
}
|
||||
|
||||
let tornadoWarnMsg = {
|
||||
"payload": {
|
||||
"alerts": tornado,
|
||||
"count": tornado.length,
|
||||
"confirmed": confirmed
|
||||
}
|
||||
}
|
||||
|
||||
let tornadoWatchMsg = {
|
||||
"payload": {
|
||||
"alerts": tornado_watch,
|
||||
"count": tornado_watch.length
|
||||
}
|
||||
}
|
||||
|
||||
let severeThunderstormWatchMsg = {
|
||||
"payload": {
|
||||
"alerts": severe_thunderstorm_watch,
|
||||
"count": severe_thunderstorm_watch.length
|
||||
}
|
||||
}
|
||||
|
||||
node.send([tstormMsg,tornadoWarnMsg,tornadoWatchMsg,severeThunderstormWatchMsg])
|
||||
node.status({fill:'green',shape:'dot',text:'Alerts Updated'})
|
||||
Reference in New Issue
Block a user