atmosx-nwws-parser 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/bootstrap.js +1 -0
- package/index.js +18 -2
- package/package.json +1 -1
- package/src/events.js +60 -46
- package/src/stanza.js +2 -2
- package/src/vtec.js +1 -1
- package/test.js +1 -0
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ let Client = new AtmosXWireParser({
|
|
|
25
25
|
onlyCap: false, // Set to true to only receive CAP messages only
|
|
26
26
|
betterEvents: true, // Set to true to receive better event handling
|
|
27
27
|
ugcPolygons: false, // Set to true to receive UGC Polygons instead of reading from raw products.
|
|
28
|
+
expiryCheck: true, // Set to true to check for expired alerts and remove them from the list
|
|
28
29
|
filteredAlerts: [] // Alerts you want to only log, leave empty to receive all alerts (Ex. ["Tornado Warning", "Radar Indicated Tornado Warning"])
|
|
29
30
|
},
|
|
30
31
|
xmpp: {
|
|
@@ -33,7 +34,7 @@ let Client = new AtmosXWireParser({
|
|
|
33
34
|
},
|
|
34
35
|
cacheSettings: {
|
|
35
36
|
maxMegabytes: 2, // Maximum cache size in megabytes
|
|
36
|
-
readCache: false, // Set to true if you wish to reupload the cache from earlier
|
|
37
|
+
readCache: false, // Set to true if you wish to reupload the cache from earlier (Now supports reading from CAP, SPS, and Alerts)
|
|
37
38
|
cacheDir: `./cache`, // Directory for cache files
|
|
38
39
|
},
|
|
39
40
|
authentication: {
|
package/bootstrap.js
CHANGED
package/index.js
CHANGED
|
@@ -27,8 +27,24 @@ class NoaaWeatherWireServiceCore {
|
|
|
27
27
|
|
|
28
28
|
if (loader.settings.cacheSettings.readCache && loader.settings.cacheSettings.cacheDir) {
|
|
29
29
|
let target = `${loader.settings.cacheSettings.cacheDir}/nwws-raw-category-defaults-raw-vtec.bin`;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
let targetCap = `${loader.settings.cacheSettings.cacheDir}/nwws-raw-category-defaults-cap-vtec.bin`;
|
|
31
|
+
let targetStatements = `${loader.settings.cacheSettings.cacheDir}/nwws-raw-category-special-weather-statements-raw.bin`;
|
|
32
|
+
let targetMesoscale = `${loader.settings.cacheSettings.cacheDir}/nwws-raw-category-mesoscale-discussions-raw.bin`;
|
|
33
|
+
let targetStormReports = `${loader.settings.cacheSettings.cacheDir}/nwws-raw-category-local-storm-reports-raw.bin`;
|
|
34
|
+
if (loader.packages.fs.existsSync(target) && !loader.settings.alertSettings.onlyCap) {
|
|
35
|
+
this.forwardCustomStanza(loader.packages.fs.readFileSync(target, 'utf8'), { awipsid: 'alert', isCap: false, raw: true, issue: undefined });
|
|
36
|
+
}
|
|
37
|
+
if (loader.packages.fs.existsSync(targetCap) && loader.settings.alertSettings.onlyCap) {
|
|
38
|
+
this.forwardCustomStanza(loader.packages.fs.readFileSync(targetCap, 'utf8'), { awipsid: 'alert', isCap: true, raw: false, issue: undefined });
|
|
39
|
+
}
|
|
40
|
+
if (loader.packages.fs.existsSync(targetStatements)) {
|
|
41
|
+
this.forwardCustomStanza(loader.packages.fs.readFileSync(targetStatements, 'utf8'), { awipsid: 'SPS001', isCap: false, raw: true, issue: undefined });
|
|
42
|
+
}
|
|
43
|
+
if (loader.packages.fs.existsSync(targetMesoscale)) {
|
|
44
|
+
this.forwardCustomStanza(loader.packages.fs.readFileSync(targetMesoscale, 'utf8'), { awipsid: 'SWOMCD001', isCap: false, raw: true, issue: undefined });
|
|
45
|
+
}
|
|
46
|
+
if (loader.packages.fs.existsSync(targetStormReports)) {
|
|
47
|
+
this.forwardCustomStanza(loader.packages.fs.readFileSync(targetStormReports, 'utf8'), { awipsid: 'LSR001', isCap: false, raw: true, issue: undefined });
|
|
32
48
|
}
|
|
33
49
|
}
|
|
34
50
|
|
package/package.json
CHANGED
package/src/events.js
CHANGED
|
@@ -26,13 +26,14 @@ class NoaaWeatherWireServiceEvents {
|
|
|
26
26
|
let tags = [`No tags found`];
|
|
27
27
|
let eventName = event.properties.event
|
|
28
28
|
let dmgTheat = event.properties.parameters.thunderstormDamageThreat?.[0] || event.properties.parameters.tornadoDamageThreat?.[0] || `N/A`;
|
|
29
|
+
let torThreat = event.properties.parameters.tornadoDetection || `N/A`;
|
|
29
30
|
let description = event.properties.description.toLowerCase() || `No description available.`;
|
|
30
31
|
if (description.includes(`flash flood emergency`) && eventName == `Flash Flood Warning`) eventName = `Flash Flood Emergency`;
|
|
31
|
-
if (description.includes(`particularly dangerous situation`) && eventName == `Tornado Warning` && dmgTheat == `CONSIDERABLE`) eventName = `
|
|
32
|
-
if (description.includes(`particularly dangerous situation`) && eventName == `Tornado Watch`) eventName = `
|
|
33
|
-
if (description.includes(`extremely dangerous situation`) && eventName == `Severe Thunderstorm Warning`) eventName = `
|
|
32
|
+
if (description.includes(`particularly dangerous situation`) && eventName == `Tornado Warning` && dmgTheat == `CONSIDERABLE`) eventName = `PDS Tornado Warning`;
|
|
33
|
+
if (description.includes(`particularly dangerous situation`) && eventName == `Tornado Watch`) eventName = `PDS Tornado Watch`;
|
|
34
|
+
if (description.includes(`extremely dangerous situation`) && eventName == `Severe Thunderstorm Warning`) eventName = `EDS Severe Thunderstorm Warning`;
|
|
34
35
|
if (description.includes(`tornado emergency`) && eventName == `Tornado Warning` && dmgTheat == `CATASTROPHIC`) eventName = `Tornado Emergency`;
|
|
35
|
-
|
|
36
|
+
|
|
36
37
|
if (eventName == `Tornado Warning`) {
|
|
37
38
|
eventName = `Radar Indicated Tornado Warning`;
|
|
38
39
|
if (event.properties.parameters.tornadoDetection == `RADAR INDICATED`) eventName = `Radar Indicated Tornado Warning`;
|
|
@@ -41,6 +42,7 @@ class NoaaWeatherWireServiceEvents {
|
|
|
41
42
|
if (eventName == `Severe Thunderstorm Warning`) {
|
|
42
43
|
if (dmgTheat == `CONSIDERABLE`) eventName = `Considerable Severe Thunderstorm Warning`;
|
|
43
44
|
if (dmgTheat == `DESTRUCTIVE`) eventName = `Destructive Severe Thunderstorm Warning`;
|
|
45
|
+
if (torThreat == `POSSIBLE`) eventName = `${eventName} (TPROB)`;
|
|
44
46
|
}
|
|
45
47
|
if (eventName == `Flash Flood Warning`) {
|
|
46
48
|
if (dmgTheat == `CONSIDERABLE`) eventName = `Considerable Flash Flood Warning`;
|
|
@@ -70,7 +72,13 @@ class NoaaWeatherWireServiceEvents {
|
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
if (loader.settings.alertSettings.filteredAlerts && loader.settings.alertSettings.filteredAlerts.length > 0) {
|
|
73
|
-
|
|
75
|
+
let pSet = new Set((loader.settings.alertSettings.filteredAlerts || []).map(p => String(p).toLowerCase()));
|
|
76
|
+
alerts = alerts.filter(alert => pSet.has(String(alert.properties?.event || '').toLowerCase()));
|
|
77
|
+
}
|
|
78
|
+
if (loader.settings.alertSettings.expiryCheck) {
|
|
79
|
+
alerts = alerts.filter(alert =>
|
|
80
|
+
new Date(alert.properties.expires) > new Date()
|
|
81
|
+
);
|
|
74
82
|
}
|
|
75
83
|
if (alerts.length === 0) { return; }
|
|
76
84
|
loader.static.events.emit(`onAlert`, alerts);
|
|
@@ -84,47 +92,52 @@ class NoaaWeatherWireServiceEvents {
|
|
|
84
92
|
*/
|
|
85
93
|
|
|
86
94
|
newCapEvent = async function(stanza) {
|
|
87
|
-
let message = stanza.message.
|
|
88
|
-
let
|
|
89
|
-
let
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
let
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
95
|
+
let message = stanza.message.match(/<\?xml[\s\S]*?<\/alert>/g) ?.map(xml => xml.trim()) || [];
|
|
96
|
+
let alerts = []
|
|
97
|
+
for (let msg of message) {
|
|
98
|
+
msg = msg.substring(msg.indexOf(`<?xml version="1.0"`), msg.lastIndexOf(`>`) + 1);
|
|
99
|
+
let data = loader.packages.xml2js.Parser();
|
|
100
|
+
let result = await data.parseStringPromise(msg);
|
|
101
|
+
let tracking = result.alert.info[0].parameter.find(p => p.valueName[0] == "VTEC")?.value[0] || "N/A";
|
|
102
|
+
let action = "N/A";
|
|
103
|
+
if (tracking !== "N/A") {
|
|
104
|
+
let splitVTEC = tracking.split(".");
|
|
105
|
+
tracking = `${splitVTEC[2]}-${splitVTEC[3]}-${splitVTEC[4]}-${splitVTEC[5]}`;
|
|
106
|
+
action = loader.definitions.status[splitVTEC[1]];
|
|
107
|
+
} else {
|
|
108
|
+
action = result.alert.msgType[0];
|
|
109
|
+
tracking = `${result.alert.info[0].parameter.find(p => p.valueName[0] == "WMOidentifier")?.value[0]}-${result.alert.info[0].area[0].geocode.filter(g => g.valueName[0] == "UGC").map(g => g.value[0]).join("-")}`;
|
|
110
|
+
}
|
|
111
|
+
let alert = {
|
|
112
|
+
id: `Wire-${tracking}`,
|
|
113
|
+
tracking: tracking,
|
|
114
|
+
action: action,
|
|
115
|
+
history: [{ description: result.alert.info[0].description[0], action: action, issued: new Date(stanza.attributes.issue) }],
|
|
116
|
+
properties: {
|
|
117
|
+
areaDesc: result.alert.info[0].area[0].areaDesc[0],
|
|
118
|
+
expires: new Date(result.alert.info[0].expires[0]),
|
|
119
|
+
sent: new Date(result.alert.sent[0]),
|
|
120
|
+
messageType: action,
|
|
121
|
+
event: result.alert.info[0].event[0],
|
|
122
|
+
sender: result.alert.sender[0],
|
|
123
|
+
senderName: result.alert.info[0].senderName[0],
|
|
124
|
+
description: result.alert.info[0].description[0],
|
|
125
|
+
geocode: { UGC: result.alert.info[0].area[0].geocode.filter(g => g.valueName[0] == "UGC").map(g => g.value[0]) },
|
|
126
|
+
parameters: {
|
|
127
|
+
WMOidentifier: [result.alert.info[0].parameter.find(p => p.valueName[0] == "WMOidentifier")?.value[0] || "N/A"],
|
|
128
|
+
tornadoDetection: result.alert.info[0].parameter.find(p => p.valueName[0] == "tornadoDetection")?.value[0] || result.alert.info[0].parameter.find(p => p.valueName[0] == "waterspoutDetection")?.value[0] || "N/A",
|
|
129
|
+
maxHailSize: result.alert.info[0].parameter.find(p => p.valueName[0] == "maxHailSize")?.value[0] || "N/A",
|
|
130
|
+
maxWindGust: result.alert.info[0].parameter.find(p => p.valueName[0] == "maxWindGust")?.value[0] || "N/A",
|
|
131
|
+
thunderstormDamageThreat: [result.alert.info[0].parameter.find(p => p.valueName[0] == "thunderstormDamageThreat")?.value[0] || result.alert.info[0].parameter.find(p => p.valueName[0] == "tornadoDamageThreat")?.value[0] || "N/A"],
|
|
132
|
+
},
|
|
121
133
|
},
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
};
|
|
135
|
+
if (result.alert.info[0].area[0].polygon) {
|
|
136
|
+
alert.geometry = { type: "Polygon", coordinates: [result.alert.info[0].area[0].polygon[0].split(" ").map(coord => { let [lat, lon] = coord.split(",").map(parseFloat); return [lon, lat]; })] };
|
|
137
|
+
}
|
|
138
|
+
alerts.push(alert);
|
|
126
139
|
}
|
|
127
|
-
this.onFinished(
|
|
140
|
+
this.onFinished(alerts);
|
|
128
141
|
}
|
|
129
142
|
|
|
130
143
|
/**
|
|
@@ -150,6 +163,7 @@ class NoaaWeatherWireServiceEvents {
|
|
|
150
163
|
let getHail = loader.packages.mText.getString(msg, `MAX HAIL SIZE...`, [`IN`]) || loader.packages.mText.getString(msg, `HAIL...`, [`IN`]);
|
|
151
164
|
let getGusts = loader.packages.mText.getString(msg, `MAX WIND GUST...`) || loader.packages.mText.getString(msg, `WIND...`);
|
|
152
165
|
let getThreat = loader.packages.mText.getString(msg, `DAMAGE THREAT...`);
|
|
166
|
+
let getTempIssue = loader.packages.mText.getString(msg, `ISSUED TIME...`);
|
|
153
167
|
let senderOffice = loader.packages.mText.getOffice(msg) || vtec.tracking.split(`-`)[0];
|
|
154
168
|
let getCoordinates = loader.packages.mText.getPolygonCoordinates(msg);
|
|
155
169
|
let getDescription = loader.packages.mText.getCleanDescription(msg, vtec);
|
|
@@ -161,8 +175,8 @@ class NoaaWeatherWireServiceEvents {
|
|
|
161
175
|
history: [{description: getDescription, action: vtec.status, issued: new Date(vtec.issued)}],
|
|
162
176
|
properties: {
|
|
163
177
|
areaDesc: mUgc.locations.join(`; `) || `N/A`,
|
|
164
|
-
expires: new Date(vtec.expires) == `Invalid Date` ? new Date(
|
|
165
|
-
sent: new Date(vtec.issued),
|
|
178
|
+
expires: new Date(vtec.expires) == `Invalid Date` ? new Date(9999, 0, 1) : new Date(vtec.expires),
|
|
179
|
+
sent: new Date(vtec.issued) == `Invalid Date` ? getTempIssue ? new Date(getTempIssue) : new Date(vtec.issued) : new Date(vtec.issued),
|
|
166
180
|
messageType: vtec.status,
|
|
167
181
|
event: vtec.event || `Unknown Event`,
|
|
168
182
|
sender: senderOffice,
|
package/src/stanza.js
CHANGED
|
@@ -28,7 +28,7 @@ class NoaaWeatherWireServiceStanza {
|
|
|
28
28
|
if (isDebug != false) {
|
|
29
29
|
let message = isDebug.stanza
|
|
30
30
|
let attributes = isDebug.attrs;
|
|
31
|
-
let isCap = message.includes(`<?xml version="1.0"`)
|
|
31
|
+
let isCap = isDebug.isCap || message.includes(`<?xml version="1.0"`);
|
|
32
32
|
let hasCapArea = message.includes(`<areaDesc>`);
|
|
33
33
|
let hasVtec = message.match(loader.definitions.expressions.vtec) != null;
|
|
34
34
|
let getId = this.getAwipsType(attributes)
|
|
@@ -96,7 +96,7 @@ class NoaaWeatherWireServiceStanza {
|
|
|
96
96
|
|
|
97
97
|
saveCache = function(message, attributes, type, isCap, isVtec) {
|
|
98
98
|
if (!loader.settings.cacheSettings.cacheDir) return;
|
|
99
|
-
loader.packages.fs.appendFileSync(`${loader.settings.cacheSettings.cacheDir}/nwws-raw-category-${type}s-${isCap ? 'cap' : 'raw'}${isVtec ? '-vtec' : ''}.bin`, `=================================================\n${new Date().toISOString().replace(/[:.]/g, '-')}\n\n
|
|
99
|
+
loader.packages.fs.appendFileSync(`${loader.settings.cacheSettings.cacheDir}/nwws-raw-category-${type}s-${isCap ? 'cap' : 'raw'}${isVtec ? '-vtec' : ''}.bin`, `=================================================\n${new Date().toISOString().replace(/[:.]/g, '-')}\n=================================================\n\n${message}\nISSUED TIME...${new Date(attributes.issue).toISOString()}\n\n`, 'utf8');
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
package/src/vtec.js
CHANGED
|
@@ -35,7 +35,7 @@ class NoaaWeatherWireServiceVtec {
|
|
|
35
35
|
status: this.getEventStatus(splitVTEC),
|
|
36
36
|
wmo: message.match(new RegExp(loader.definitions.expressions.wmo, 'gimu')),
|
|
37
37
|
expires: this.getExpires(vtecDates),
|
|
38
|
-
issued: attributes.issue
|
|
38
|
+
issued: attributes.issue
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
41
|
return vtecs;
|
package/test.js
CHANGED
|
@@ -5,6 +5,7 @@ let Client = new AtmosXWireParser({
|
|
|
5
5
|
onlyCap: false, // Set to true to only receive CAP messages only
|
|
6
6
|
betterEvents: true, // Set to true to receive better event handling
|
|
7
7
|
ugcPolygons: false, // Set to true to receive UGC Polygons instead of reading from raw products.
|
|
8
|
+
expiryCheck: true, // Set to true to filter out expired alerts
|
|
8
9
|
filteredAlerts: [] // Alerts you want to only log, leave empty to receive all alerts (Ex. ["Tornado Warning", "Radar Indicated Tornado Warning"])
|
|
9
10
|
},
|
|
10
11
|
xmpp: {
|