From 3b41eda7f491e742ea8c0d4823f90b51dbc43e01 Mon Sep 17 00:00:00 2001 From: akrherz Date: Wed, 31 Jul 2024 12:32:58 -0500 Subject: [PATCH] feat: store product_id and fake some AFOS ids --- CHANGELOG.md | 1 + src/pyiem/nws/products/pirep.py | 9 ++++++--- tests/nws/products/test_pirep.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 404c748b7..773033710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this library are documented in this file. - Cross check WCNs against watch database storage for PDS status (#925). - For `iemapp` if the `memcachekey=` callable returns `None`, the check of memcache is short circuited. +- Store `product_id` for PIREPs and do some faked AFOS assignments to help. - Support SPC afternoon Day 3 outlook (cycle assigned as 20) (#936). ### Bug Fixes diff --git a/src/pyiem/nws/products/pirep.py b/src/pyiem/nws/products/pirep.py index 5b2543d51..c9e912954 100644 --- a/src/pyiem/nws/products/pirep.py +++ b/src/pyiem/nws/products/pirep.py @@ -131,7 +131,7 @@ def _parse_lonlat(text): class Pirep(product.TextProduct): - """Class for parsing and representing Space Wx Products.""" + """Class for parsing and representing PIREPs found in NWS text products.""" def __init__( self, text, utcnow=None, ugc_provider=None, nwsli_provider=None @@ -144,6 +144,8 @@ def __init__( ugc_provider=ugc_provider, nwsli_provider=nwsli_provider, ) + if self.afos is None: + self.afos = "PIREP" self.reports = [] self.parse_reports() @@ -327,8 +329,8 @@ def sql(self, txn): txn.execute( f""" INSERT into pireps(valid, geom, is_urgent, aircraft_type, - report, artcc) VALUES (%s, - ST_GeographyFromText(%s), %s, %s, %s, {artcc}) + report, artcc, product_id) VALUES (%s, + ST_GeographyFromText(%s), %s, %s, %s, {artcc}, %s) """, ( report.valid, @@ -336,6 +338,7 @@ def sql(self, txn): report.priority == Priority.UUA, report.aircraft_type, report.text, + self.get_product_id(), ), ) diff --git a/tests/nws/products/test_pirep.py b/tests/nws/products/test_pirep.py index 843ab6e93..b64f6406f 100644 --- a/tests/nws/products/test_pirep.py +++ b/tests/nws/products/test_pirep.py @@ -5,6 +5,24 @@ from pyiem.util import get_test_file, utc +def test_fake_afos(): + """Test assignment of the fake AFOS identifier.""" + prod = pirepparser( + get_test_file("PIREPS/PRCUS.txt"), + utcnow=utc(2016, 10, 1, 1, 35), + ) + assert prod.afos == "PRCUS" + + +def test_fake_afos_pirep(): + """Test assignment of the fake AFOS identifier.""" + prod = pirepparser( + get_test_file("PIREPS/PIREP.txt"), + utcnow=utc(2015, 1, 9, 0, 0), + ) + assert prod.afos == "PIREP" + + def test_210121_int_latlon(): """Test successful parsing of an integer lat lon value, tricky.""" utcnow = utc(2020, 1, 21, 10, 22)