Skip to content

Commit

Permalink
Merge pull request #942 from akrherz/pirep_product_id
Browse files Browse the repository at this point in the history
feat: store product_id and fake some AFOS ids
  • Loading branch information
akrherz authored Jul 31, 2024
2 parents ac3d305 + 3b41eda commit e38e7f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/pyiem/nws/products/pirep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -327,15 +329,16 @@ 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,
geom,
report.priority == Priority.UUA,
report.aircraft_type,
report.text,
self.get_product_id(),
),
)

Expand Down
18 changes: 18 additions & 0 deletions tests/nws/products/test_pirep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e38e7f8

Please sign in to comment.