Node status improvement for general alerts function node
This commit is contained in:
12
flows.json
12
flows.json
@ -111,7 +111,7 @@
|
||||
],
|
||||
"x": 14,
|
||||
"y": 19,
|
||||
"w": 1032,
|
||||
"w": 1152,
|
||||
"h": 202
|
||||
},
|
||||
{
|
||||
@ -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// 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' })",
|
||||
"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.length} alerts processed at ${new Date().toLocaleString()}`})",
|
||||
"outputs": 2,
|
||||
"timeout": 0,
|
||||
"noerr": 0,
|
||||
@ -511,7 +511,7 @@
|
||||
"correl": "",
|
||||
"expiry": "",
|
||||
"broker": "200f284a1171f0a8",
|
||||
"x": 780,
|
||||
"x": 900,
|
||||
"y": 180,
|
||||
"wires": []
|
||||
},
|
||||
@ -530,7 +530,7 @@
|
||||
"correl": "",
|
||||
"expiry": "",
|
||||
"broker": "200f284a1171f0a8",
|
||||
"x": 820,
|
||||
"x": 940,
|
||||
"y": 120,
|
||||
"wires": []
|
||||
},
|
||||
@ -618,7 +618,7 @@
|
||||
"targetType": "full",
|
||||
"statusVal": "",
|
||||
"statusType": "auto",
|
||||
"x": 670,
|
||||
"x": 790,
|
||||
"y": 60,
|
||||
"wires": []
|
||||
},
|
||||
@ -636,7 +636,7 @@
|
||||
"targetType": "full",
|
||||
"statusVal": "",
|
||||
"statusType": "auto",
|
||||
"x": 860,
|
||||
"x": 980,
|
||||
"y": 60,
|
||||
"wires": []
|
||||
},
|
||||
|
Reference in New Issue
Block a user