nmlorg / metabot

Modularized, multi-account bot.
https://metabot.readthedocs.io/
5 stars 0 forks source link

Allow admins to control if/which weather advisories are sent to their groups #85

Open nmlorg opened 4 years ago

nmlorg commented 4 years ago

Right now (see #80), anything that shows up in the US NWS' API for a given zone is displayed. https://api.weather.gov/alerts/active?zone=WAZ558, for example, currently lists:

{
    "@context": [
        "https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
        {
            "wx": "https://api.weather.gov/ontology#",
            "@vocab": "https://api.weather.gov/ontology#"
        }
    ],
    "type": "FeatureCollection",
    "features": [
        {
            "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3968032",
            "type": "Feature",
            "geometry": null,
            "properties": {
                "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3968032",
                "@type": "wx:Alert",
                "id": "NWS-IDP-PROD-3968032",
                "areaDesc": "Seattle and Vicinity; Everett and Vicinity; West Slopes North Central Cascades and Passes; Southwest Interior; Olympics; Central Coast; Bremerton and Vicinity; West Slopes North Cascades and Passes; North Coast; Lower Chehalis Valley Area; West Slopes South Central Cascades and Passes; Tacoma Area; Bellevue and Vicinity; East Puget Sound Lowlands; Hood Canal Area",
                "geocode": {
                    "UGC": [
                        "WAZ558",
                        "WAZ507",
                        "WAZ568",
                        "WAZ504",
                        "WAZ513",
                        "WAZ517",
                        "WAZ559",
                        "WAZ567",
                        "WAZ516",
                        "WAZ512",
                        "WAZ569",
                        "WAZ509",
                        "WAZ556",
                        "WAZ555",
                        "WAZ511"
                    ],
                    "SAME": [
                        "053033",
                        "053035",
                        "053061",
                        "053041",
                        "053067",
                        "053009",
                        "053027",
                        "053031",
                        "053045",
                        "053057",
                        "053073",
                        "053053"
                    ]
                },
                "affectedZones": [
                    "https://api.weather.gov/zones/forecast/WAZ558",
                    "https://api.weather.gov/zones/forecast/WAZ507",
                    "https://api.weather.gov/zones/forecast/WAZ568",
                    "https://api.weather.gov/zones/forecast/WAZ504",
                    "https://api.weather.gov/zones/forecast/WAZ513",
                    "https://api.weather.gov/zones/forecast/WAZ517",
                    "https://api.weather.gov/zones/forecast/WAZ559",
                    "https://api.weather.gov/zones/forecast/WAZ567",
                    "https://api.weather.gov/zones/forecast/WAZ516",
                    "https://api.weather.gov/zones/forecast/WAZ512",
                    "https://api.weather.gov/zones/forecast/WAZ569",
                    "https://api.weather.gov/zones/forecast/WAZ509",
                    "https://api.weather.gov/zones/forecast/WAZ556",
                    "https://api.weather.gov/zones/forecast/WAZ555",
                    "https://api.weather.gov/zones/forecast/WAZ511"
                ],
                "references": [],
                "sent": "2019-12-22T14:50:00-08:00",
                "effective": "2019-12-22T14:50:00-08:00",
                "onset": "2019-12-22T14:50:00-08:00",
                "expires": "2019-12-23T03:00:00-08:00",
                "ends": null,
                "status": "Actual",
                "messageType": "Alert",
                "category": "Met",
                "severity": "Moderate",
                "certainty": "Observed",
                "urgency": "Expected",
                "event": "Special Weather Statement",
                "sender": "w-nws.webmaster@noaa.gov",
                "senderName": "NWS Seattle WA",
                "headline": "Special Weather Statement issued December 22 at 2:50PM PST by NWS Seattle WA",
                "description": "Soil moisture will remain at high levels across western Washington\nin response to prolonged rainfall since Thursday. Although widespread\nrainfall has ended across western Washington, the landslide threat\nwill be elevated through early this week.\n\nFor more information about current conditions, visit\nwww.weather.gov/seattle, select Hydrology, and then scroll down\nfor the links to the landslide information pages.\n\nFor more information on landslides, visit the website for the\nWashington State Department of Natural Resources landslide\ngeologic hazards at: http://bit.ly/2mtA3wn",
                "instruction": null,
                "response": "Execute",
                "parameters": {
                    "NWSheadline": [
                        "INCREASED THREAT OF LANDSLIDES IN WESTERN WASHINGTON INTO EARLY THIS WEEK"
                    ],
                    "EAS-ORG": [
                        "WXR"
                    ],
                    "PIL": [
                        "SEWSPSSEW"
                    ],
                    "BLOCKCHANNEL": [
                        "CMAS",
                        "EAS",
                        "NWEM"
                    ]
                }
            }
        }
    ],
    "title": "current watches, warnings, and advisories for Seattle and Vicinity (WAZ558) WA",
    "updated": "2019-12-22T22:50:42+00:00"
}

which is not super urgent (or useful).

Each alert (or "feature") includes a messageType, category, severity, certainty, urgency, and response. These seem to correlate with the similarly named fields in Common Alerting Protocol Version 1.2:

It might make sense to do something like:  If a message has urgency=Immediate or Expected, post immediately; if urgency=Future, maybe only post as part of the daily announcement. However, it would be simpler to keep the posting behavior uniform but allow admins to filter events based on severity (maybe the default could be changed to exclude Minor or even Moderate, since the current landslide warning is set at that).

In addition/alternatively, it might make sense to simply ignore features that don't include an <instruction> string (as the landslide warning does not):

It might even make sense to prioritize/only show the instruction in the text posted to the group. (Currently, the bot posts the first 250 characters of the combined description, instruction, and areaDesc.)

nmlorg commented 4 years ago

Since #80 went live, 49 alerts have been processed by the bot. Unfortunately, api.weather.gov (and alerts-v2.weather.gov) seem to expire records pretty aggressively, so only the following 14 are still viewable (all had status=Actual and category=Met):

id messageType severity certainty urgency event response instruction
3960241-3364815 Update Moderate Likely Expected Winter Weather Advisory Execute ...
3960620-3365123 Update Moderate Likely Expected Winter Weather Advisory Execute ...
3961136 Alert Moderate Observed Expected Special Weather Statement Execute None
3961794 Alert Unknown Possible Future Hydrologic Outlook Monitor None
3963421-3367361 Alert Severe Possible Future Flood Watch Prepare ...
3964821-3368352 Update Severe Possible Future Flood Watch Prepare ...
3965155-3368578 Update Severe Possible Future Flood Watch Prepare ...
3965324-3368680 Update Severe Possible Future Flood Watch Prepare ...
3965613 Alert Moderate Observed Expected Special Weather Statement Execute None
3965873-3369046 Update Severe Possible Future Flood Watch Prepare ...
3966591 Alert Moderate Observed Expected Special Weather Statement Execute None
3967196 Alert Moderate Observed Expected Special Weather Statement Execute None
3968032 Alert Moderate Observed Expected Special Weather Statement Execute None
3968722 Alert Moderate Observed Expected Special Weather Statement Execute None

 

It's hard to determine exactly what the bot should be doing based on this data. For example, I would argue that NWS-IDP-PROD-3965613 should have definitely been posted, but all of the followups for WAZ558 (NWS-IDP-PROD-3966591, which was briefly live concurrently with 5613; NWS-IDP-PROD-3967196; NWS-IDP-PROD-3968032; and NWS-IDP-PROD-3968722) should have been suppressed. However, their primary features are identical:

id messageType severity certainty urgency event response instruction
3965613 Alert Moderate Observed Expected Special Weather Statement Execute None
3966591 Alert Moderate Observed Expected Special Weather Statement Execute None
3967196 Alert Moderate Observed Expected Special Weather Statement Execute None
3968032 Alert Moderate Observed Expected Special Weather Statement Execute None
3968722 Alert Moderate Observed Expected Special Weather Statement Execute None

and none of them include a references list (which is consistent with them all being labeled messageType=Alert), so it becomes something more like keeping track of advisories and preventing posts that overlap an active (or reopen a recently active) one. (3966591 was posted while 3965613 was still active, while 3967196 was posted within an hour of 3966591 expiring, 3968722 was posted within an hour of 3968032 expiring, and 3968032 was posted more than an hour after 3967196 had expired.)

Going back to filtering alerts, it appears this label of "Special Weather Statement" is an alternative form of "Significant Weather Advisory", and this text is actually structured. It might make sense to actually just extract the last word of event and only post when it matches "Warning" (possibly after canonicalization). (Though it might be the case that a label of "Watch" necessarily means urgency=Future, "Advisory" (or "Outlook", or "Special Weather Statement") means severity<=Moderate, etc.—again, I wish I had more data.)

nmlorg commented 4 years ago

More alerts:

id messageType severity certainty urgency event instruction
3969721 Alert Moderate Observed Expected Special Weather Statement None
3969740-3371513 Alert Moderate Likely Expected Dense Fog Advisory If drivin…
3969972-3371675 Update Moderate Likely Expected Dense Fog Advisory If drivin…
3970041-3371724 Alert Moderate Likely Expected Dense Fog Advisory If drivin…
3970132-3371798 Update Moderate Likely Expected Dense Fog Advisory If drivin…
3970277-3371882 Update Moderate Likely Expected Dense Fog Advisory If drivin…
3970377-3371943 Alert Moderate Likely Expected Beach Hazards Statement A Beach H…
3970415-3371975 Alert Moderate Likely Expected Dense Fog Advisory If drivin…