Forgot to include topic for all alerts in an area
This commit is contained in:
@ -284,7 +284,7 @@
|
||||
"type": "function",
|
||||
"z": "0e70b91ae6570376",
|
||||
"name": "Filter",
|
||||
"func": "const severeWarningEvents = [\"Severe Thunderstorm Warning\",\"Destructive Severe Thunderstorm Warning\",\"Considerable Destructive Severe Thunderstorm Warning\"]\nconst tornadoWarningEvents = [\"Tornado Warning\",\"Radar Indicated Tornado Warning\",\"Confirmed Tornado Warning\",\"Tornado Emergency\"]\nconst tornadoWatchEvents = [\"Tornado Watch\"]\nconst severeThunderstormWatchEvents = [\"Severe Thunderstorm Watch\"]\nconst area = msg.area\nconst mqttTopic = \"weather/alerts/\" + area\nconst tstormTopic = mqttTopic + \"/severe_thunderstorm_warning\"\nconst tornadoWarnTopic = mqttTopic + \"/tornado_warning\"\nconst tornadoWatchTopic = mqttTopic + \"/tornado_watch\"\nconst severeThunderstormWatchTopic = mqttTopic + \"/severe_thunderstorm_watch\"\n\nlet alerts = msg.payload.features\nlet tornado_possible = false\nlet considerable_destructive = false\nlet confirmed = false\n\n// Filter for Severe Thunderstorm Warnings\n\nlet ts = alerts.filter(function(alert) {\n if (alert.properties &&\n severeWarningEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\n// Filter for Severe Thunderstorm Warnings with tornado detection\n// that have a tornado possible parameter\n\nlet tstp = alerts.filter(function(alert) {\n if (alert.properties &&\n severeWarningEvents.includes(alert.properties.event) &&\n alert.properties.parameters &&\n alert.properties.parameters.tornadoDetection &&\n alert.properties.parameters.tornadoDetection.length > 0) {\n let tornadoPossible = alert.properties.parameters.tornadoDetection[0]\n return tornadoPossible === \"POSSIBLE\"\n }\n})\n\nif (tstp.length > 0) {\n tornado_possible = true\n}\n\n// Filter for considerable destructive severe thunderstorm warnings\n\nlet cdst = alerts.filter(function(alert) {\n if (alert.properties &&\n alert.properties.event === \"Considerable Destructive Severe Thunderstorm Warning\") {\n return true\n }\n})\n\nif (cdst.length > 0) {\n considerable_destructive = true\n}\n\n// Filter for Tornado Warnings\n\nlet tornado = alerts.filter(function(alert) {\n if (alert.properties &&\n tornadoWarningEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\nlet confirmed_tornado = alerts.filter(function(alert) {\n if (alert.properties &&\n alert.properties.event === \"Confirmed Tornado Warning\") {\n return true\n }\n})\n\nif (confirmed_tornado.length > 0) {\n confirmed = true\n}\n\n// Filter for Tornado Watches\n\nlet tornado_watch = alerts.filter(function(alert) {\n if (alert.properties &&\n tornadoWatchEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\n// Filter for Severe Thunderstorm Watches\n\nlet severe_thunderstorm_watch = alerts.filter(function(alert) {\n if (alert.properties &&\n severeThunderstormWatchEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\n// If there are any alerts, return them\n\nlet allAlerts = {\n \"payload\": msg.payload.features\n}\n\nlet tstormMsg = {\n \"payload\": {\n \"alerts\": ts,\n \"count\": ts.length,\n \"tornado_possible\": tornado_possible,\n \"considerable_destructive\": considerable_destructive\n },\n \"topic\": tstormTopic\n}\n\nlet tornadoWarnMsg = {\n \"payload\": {\n \"alerts\": tornado,\n \"count\": tornado.length,\n \"confirmed\": confirmed\n },\n \"topic\": tornadoWarnTopic\n}\n\nlet tornadoWatchMsg = {\n \"payload\": {\n \"alerts\": tornado_watch,\n \"count\": tornado_watch.length\n },\n \"topic\": tornadoWatchTopic\n}\n\nlet severeThunderstormWatchMsg = {\n \"payload\": {\n \"alerts\": severe_thunderstorm_watch,\n \"count\": severe_thunderstorm_watch.length\n },\n \"topic\": severeThunderstormWatchTopic\n}\n\n// Create status message for node\n\nlet statusMsg = {\n \"status\": {\n \"fill\": \"green\",\n \"shape\": \"dot\",\n \"text\": alerts.length + \" alerts processed at \" + new Date().toLocaleString()\n }\n}\n\n// Send messages to output nodes\n\nnode.send([allAlerts,tstormMsg,tornadoWarnMsg,tornadoWatchMsg,severeThunderstormWatchMsg,statusMsg])",
|
||||
"func": "const severeWarningEvents = [\"Severe Thunderstorm Warning\",\"Destructive Severe Thunderstorm Warning\",\"Considerable Destructive Severe Thunderstorm Warning\"]\nconst tornadoWarningEvents = [\"Tornado Warning\",\"Radar Indicated Tornado Warning\",\"Confirmed Tornado Warning\",\"Tornado Emergency\"]\nconst tornadoWatchEvents = [\"Tornado Watch\"]\nconst severeThunderstormWatchEvents = [\"Severe Thunderstorm Watch\"]\nconst area = msg.area\nconst mqttTopic = \"weather/alerts/\" + area\nconst allTopic = mqttTopic + \"/alerts\"\nconst tstormTopic = mqttTopic + \"/severe_thunderstorm_warning\"\nconst tornadoWarnTopic = mqttTopic + \"/tornado_warning\"\nconst tornadoWatchTopic = mqttTopic + \"/tornado_watch\"\nconst severeThunderstormWatchTopic = mqttTopic + \"/severe_thunderstorm_watch\"\n\nlet alerts = msg.payload.features\nlet tornado_possible = false\nlet considerable_destructive = false\nlet confirmed = false\n\n// Filter for Severe Thunderstorm Warnings\n\nlet ts = alerts.filter(function(alert) {\n if (alert.properties &&\n severeWarningEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\n// Filter for Severe Thunderstorm Warnings with tornado detection\n// that have a tornado possible parameter\n\nlet tstp = alerts.filter(function(alert) {\n if (alert.properties &&\n severeWarningEvents.includes(alert.properties.event) &&\n alert.properties.parameters &&\n alert.properties.parameters.tornadoDetection &&\n alert.properties.parameters.tornadoDetection.length > 0) {\n let tornadoPossible = alert.properties.parameters.tornadoDetection[0]\n return tornadoPossible === \"POSSIBLE\"\n }\n})\n\nif (tstp.length > 0) {\n tornado_possible = true\n}\n\n// Filter for considerable destructive severe thunderstorm warnings\n\nlet cdst = alerts.filter(function(alert) {\n if (alert.properties &&\n alert.properties.event === \"Considerable Destructive Severe Thunderstorm Warning\") {\n return true\n }\n})\n\nif (cdst.length > 0) {\n considerable_destructive = true\n}\n\n// Filter for Tornado Warnings\n\nlet tornado = alerts.filter(function(alert) {\n if (alert.properties &&\n tornadoWarningEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\nlet confirmed_tornado = alerts.filter(function(alert) {\n if (alert.properties &&\n alert.properties.event === \"Confirmed Tornado Warning\") {\n return true\n }\n})\n\nif (confirmed_tornado.length > 0) {\n confirmed = true\n}\n\n// Filter for Tornado Watches\n\nlet tornado_watch = alerts.filter(function(alert) {\n if (alert.properties &&\n tornadoWatchEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\n// Filter for Severe Thunderstorm Watches\n\nlet severe_thunderstorm_watch = alerts.filter(function(alert) {\n if (alert.properties &&\n severeThunderstormWatchEvents.includes(alert.properties.event)) {\n return true\n }\n})\n\n// If there are any alerts, return them\n\nlet allAlerts = {\n \"payload\": msg.payload.features,\n \"topic\": allTopic\n}\n\nlet tstormMsg = {\n \"payload\": {\n \"alerts\": ts,\n \"count\": ts.length,\n \"tornado_possible\": tornado_possible,\n \"considerable_destructive\": considerable_destructive\n },\n \"topic\": tstormTopic\n}\n\nlet tornadoWarnMsg = {\n \"payload\": {\n \"alerts\": tornado,\n \"count\": tornado.length,\n \"confirmed\": confirmed\n },\n \"topic\": tornadoWarnTopic\n}\n\nlet tornadoWatchMsg = {\n \"payload\": {\n \"alerts\": tornado_watch,\n \"count\": tornado_watch.length\n },\n \"topic\": tornadoWatchTopic\n}\n\nlet severeThunderstormWatchMsg = {\n \"payload\": {\n \"alerts\": severe_thunderstorm_watch,\n \"count\": severe_thunderstorm_watch.length\n },\n \"topic\": severeThunderstormWatchTopic\n}\n\n// Create status message for node\n\nlet statusMsg = {\n \"status\": {\n \"fill\": \"green\",\n \"shape\": \"dot\",\n \"text\": `${alerts.length} alerts processed at ${new Date().toLocaleString()}`\n }\n}\n\n// Send messages to output nodes\n\nnode.send([allAlerts,tstormMsg,tornadoWarnMsg,tornadoWatchMsg,severeThunderstormWatchMsg,statusMsg])",
|
||||
"outputs": 6,
|
||||
"timeout": 0,
|
||||
"noerr": 0,
|
||||
@ -472,7 +472,7 @@
|
||||
"z": "ed4ea3c2bc13d1ec",
|
||||
"g": "df425a30fbcfb2e9",
|
||||
"name": "Filter",
|
||||
"func": "const severeWarningEvents = [\"Severe Thunderstorm Warning\",\"Destructive Severe Thunderstorm Warning\",\"Considerable Destructive Severe Thunderstorm Warning\"]\nconst tornadoWarningEvents = [\"Tornado Warning\",\"Radar Indicated Tornado Warning\",\"Confirmed Tornado Warning\",\"Tornado Emergency\"]\n\nlet alerts = msg.payload\n\n// Filter for Severe Thunderstorm Warnings\n\nlet ts = alerts.filter(function(alert) {\n if (alert.raw.properties &&\n severeWarningEvents.includes(alert.raw.properties.event)) {\n return true\n }\n})\n\n// Filter for Severe Thunderstorm Warnings with tornado detection\n// that have a tornado possible parameter\n\nlet tstp = alerts.filter(function(alert) {\n if (alert.raw.properties &&\n severeWarningEvents.includes(alert.raw.properties.event) &&\n alert.raw.properties.parameters &&\n alert.raw.properties.parameters.tornadoDetection &&\n alert.raw.properties.parameters.tornadoDetection.length > 0) {\n let tornadoPossible = alert.raw.properties.parameters.tornadoDetection[0]\n return tornadoPossible === \"POSSIBLE\"\n }\n})\n\n// Filter for considerable destructive severe thunderstorm warnings\n\nlet cdst = alerts.filter(function(alert) {\n if (alert.raw.properties &&\n alert.raw.properties.event === \"Considerable Destructive Severe Thunderstorm Warning\") {\n return true\n }\n})\n\n// Filter for Tornado Warnings\n\nlet tornado = alerts.filter(function(alert) {\n if (alert.raw.properties &&\n tornadoWarningEvents.includes(alert.raw.properties.event)) {\n return true\n }\n})\n\nlet confirmed_tornado = alerts.filter(function(alert) {\n if (alert.raw.properties &&\n alert.raw.properties.event === \"Confirmed Tornado Warning\") {\n return true\n }\n})\n\n// If there are any alerts, return them\n\nlet tstormMsg = {\n \"payload\": {\n \"alerts\": ts,\n \"count\": ts.length,\n \"tornado_possible\": tstp.length,\n \"considerable_destructive\": cdst.length\n }\n}\n\nlet tornadoWarnMsg = {\n \"payload\": {\n \"alerts\": tornado,\n \"count\": tornado.length,\n \"confirmed\": confirmed_tornado.length\n }\n}\n\nnode.send([tstormMsg,tornadoWarnMsg])\nnode.status({fill:'green',shape:'dot',text:'Alerts Updated'})",
|
||||
"func": "const severeWarningEvents = [\"Severe Thunderstorm Warning\", \"Destructive Severe Thunderstorm Warning\", \"Considerable Destructive Severe Thunderstorm Warning\"]\nconst tornadoWarningEvents = [\"Tornado Warning\", \"Radar Indicated Tornado Warning\", \"Confirmed Tornado Warning\", \"Tornado Emergency\"]\n\nlet alerts = msg.payload\n\n// Helper function to safely access nested properties\nconst getNestedProperty = (obj, path, defaultValue = undefined) => {\n return path.reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : defaultValue), obj)\n}\n\n// Filter function\nconst filterAlerts = (alerts, condition) => {\n return alerts.filter(alert => {\n try {\n return condition(alert)\n } catch (e) {\n node.warn(`Error processing alert: ${e.message}`)\n return false\n }\n })\n}\n\n// Filtering logic\nconst ts = filterAlerts(alerts, alert => {\n const event = getNestedProperty(alert, ['raw', 'properties', 'event'])\n return severeWarningEvents.includes(event)\n})\n\nconst tstp = filterAlerts(alerts, alert => {\n const event = getNestedProperty(alert, ['raw', 'properties', 'event'])\n const tornadoDetection = getNestedProperty(alert, ['raw', 'properties', 'parameters', 'tornadoDetection'], [])\n return severeWarningEvents.includes(event) && tornadoDetection.includes(\"POSSIBLE\")\n})\n\nconst cdst = filterAlerts(alerts, alert => {\n const event = getNestedProperty(alert, ['raw', 'properties', 'event'])\n return event === \"Considerable Destructive Severe Thunderstorm Warning\"\n})\n\nconst tornado = filterAlerts(alerts, alert => {\n const event = getNestedProperty(alert, ['raw', 'properties', 'event'])\n return tornadoWarningEvents.includes(event)\n})\n\nconst confirmed_tornado = filterAlerts(alerts, alert => {\n const event = getNestedProperty(alert, ['raw', 'properties', 'event'])\n return event === \"Confirmed Tornado Warning\"\n})\n\n// Output messages\nlet tstormMsg = {\n \"payload\": {\n \"alerts\": ts,\n \"count\": ts.length,\n \"tornado_possible\": tstp.length,\n \"considerable_destructive\": cdst.length\n }\n}\n\nlet tornadoWarnMsg = {\n \"payload\": {\n \"alerts\": tornado,\n \"count\": tornado.length,\n \"confirmed\": confirmed_tornado.length\n }\n}\n\nnode.send([tstormMsg, tornadoWarnMsg])\nnode.status({ fill: 'green', shape: 'dot', text: 'Alerts Updated' })",
|
||||
"outputs": 2,
|
||||
"timeout": 0,
|
||||
"noerr": 0,
|
||||
|
Reference in New Issue
Block a user