Skip to content

Commit

Permalink
Merge pull request #609 from akrherz/231208
Browse files Browse the repository at this point in the history
feat: add ARTCC filter to PIREP download
  • Loading branch information
akrherz authored Dec 9, 2023
2 parents 0475dfa + bd59ed8 commit 8062f63
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cgi-bin/request/gis/pireps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import shapefile
from pyiem.exceptions import IncompleteWebRequest
from pyiem.util import get_dbconn
from pyiem.webutil import iemapp
from pyiem.webutil import ensure_list, iemapp


def get_context(environ):
Expand All @@ -15,12 +15,15 @@ def get_context(environ):
form["fmt"] = environ.get("fmt", "shp")
form["sts"] = environ["sts"]
form["ets"] = environ["ets"]

form["artcc"] = ensure_list(environ, "artcc")
if "_ALL" in form["artcc"]:
form["artcc"] = []
return form


def run(ctx, start_response):
"""Go run!"""
artcc_sql = "" if not ctx["artcc"] else " artcc = ANY(%s) and "
pgconn = get_dbconn("postgis")
cursor = pgconn.cursor()

Expand All @@ -46,17 +49,20 @@ def run(ctx, start_response):
substr(trim(substring(replace(report, ',', ' '),
'/TB([^/]*)/')), 0, 255) as turb,
artcc, ST_y(geom::geometry) as lat, ST_x(geom::geometry) as lon
from pireps WHERE {spatialsql}
from pireps WHERE {spatialsql} {artcc_sql}
valid >= %s and valid < %s ORDER by valid ASC
"""
args = (
args = [
ctx["sts"],
ctx["ets"],
)
]
if ctx["artcc"]:
args.insert(0, ctx["artcc"])

cursor.execute(sql, args)
if cursor.rowcount == 0:
start_response("200 OK", [("Content-type", "text/plain")])
pgconn.close()
return b"ERROR: no results found for your query"

fn = f"pireps_{ctx['sts']:%Y%m%d%H%M}_{ctx['ets']:%Y%m%d%H%M}"
Expand All @@ -73,6 +79,7 @@ def run(ctx, start_response):
)
for row in cursor:
sio.write(",".join([str(s) for s in row]) + "\n")
pgconn.close()
return sio.getvalue().encode("ascii", "ignore")

shpio = BytesIO()
Expand Down Expand Up @@ -108,6 +115,7 @@ def run(ctx, start_response):
("Content-type", "application/octet-stream"),
("Content-Disposition", f"attachment; filename={fn}.zip"),
]
pgconn.close()
start_response("200 OK", headers)
return zio.getvalue()

Expand Down
30 changes: 30 additions & 0 deletions htdocs/request/gis/pireps.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@

$t = new MyView();
$t->title = "Download PIREPs";
$artcc = Array(
"ZAB"=> "[ZAB] ALBUQUERQUE",
"ZAN"=> "[ZAN] ANCHORAGE",
"ZAU"=> "[ZAU] CHICAGO",
"ZBW"=> "[ZBW] BOSTON ",
"ZDC"=> "[ZDC] WASHINGTON",
"ZDV"=> "[ZDV] DENVER",
"ZFW"=> "[ZFW] FORT WORTH",
"ZHU"=> "[ZHU] HOUSTON",
"ZID"=> "[ZID] INDIANAPOLIS",
"ZJX"=> "[ZJX] JACKSONVILLE",
"ZKC"=> "[ZKC] KANSAS CITY",
"ZLA"=> "[ZLA] LOS ANGELES",
"ZLC"=> "[ZLC] SALT LAKE CITY",
"ZMA"=> "[ZMA] MIAMI",
"ZME"=> "[ZME] MEMPHIS",
"ZMP"=> "[ZMP] MINNEAPOLIS",
"ZNY"=> "[ZNY] NEW YORK",
"ZOA"=> "[ZOA] OAKLAND",
"ZOB"=> "[ZOB] CLEVELAND ",
"ZSE"=> "[ZSE] SEATTLE",
"ZTL"=> "[ZTL] ATLANTA",
"_ALL" => "No ARTCC Filter",
);
$artccSelect = make_select("artcc", "_ALL", $artcc);

$content = <<<EOF
<p>
<ul class="breadcrumb">
Expand Down Expand Up @@ -50,6 +76,7 @@
<th colspan="6">Time Interval</th>
<th>Format</th>
<th>Spatial Filter (Optional)</th>
<th>ARTCC Filter (Optional)</th>
</tr>
</thead>
<tr>
Expand All @@ -73,6 +100,9 @@
<input type="text" name="lat" size="10" value="41.99"> North
</div>
</td>
<td rowspan="3">
{$artccSelect}
</td>
</tr>
<tr>
Expand Down

0 comments on commit 8062f63

Please sign in to comment.