diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d726eef53f..5b60f54d22 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.1.2" + rev: "v0.1.3" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/cgi-bin/request/gis/wpc_mpd.py b/cgi-bin/request/gis/wpc_mpd.py index dd80a697b7..3973aac5c2 100644 --- a/cgi-bin/request/gis/wpc_mpd.py +++ b/cgi-bin/request/gis/wpc_mpd.py @@ -49,7 +49,7 @@ def application(environ, start_response): ) if df.empty: start_response("200 OK", [("Content-type", "text/plain")]) - return b"ERROR: no results found for your query" + return [b"ERROR: no results found for your query"] df.columns = [s.upper() if s != "geom" else "geom" for s in df.columns] fn = f"mpd_{environ['sts']:%Y%m%d%H%M}_{environ['ets']:%Y%m%d%H%M}" diff --git a/htdocs/nws/coop-cnts.php b/htdocs/nws/coop-cnts.php index 57c7a173ea..9badbe023b 100644 --- a/htdocs/nws/coop-cnts.php +++ b/htdocs/nws/coop-cnts.php @@ -12,37 +12,71 @@ $wfo = isset($_REQUEST['wfo']) ? xssafe($_REQUEST['wfo']) : 'DMX'; $by = isset($_REQUEST['by']) ? xssafe($_REQUEST['by']) : 'station'; +$tby = isset($_REQUEST['tby']) ? xssafe($_REQUEST['tby']) : 'month'; $year = get_int404("year", date("Y")); $month = get_int404("month", date("m")); -if ($by == "station") { - $rs = pg_prepare($dbconn, "MYSELECT", "select id, name, - count(*) as total, - sum(case when pday >= 0 then 1 else 0 end) as pobs, - sum(case when snow >= 0 then 1 else 0 end) as sobs, - sum(case when snowd >= 0 then 1 else 0 end) as sdobs, - sum(case when max_tmpf > -60 then 1 else 0 end) as tobs - from summary_$year s JOIN stations t on (t.iemid = s.iemid) - WHERE day >= $1 and day < ($1::date + '1 month'::interval) - and day < 'TOMORROW'::date - and t.wfo = $2 and t.network ~* 'COOP' GROUP by id, name ORDER by id ASC"); +$tlabel = "month: {$month}, year: {$year}"; + +$tstring = sprintf("%s-%02d-01", $year, intval($month)); +// sigh +if ($tby == "month") { + if ($by == "station") { + $rs = pg_prepare($dbconn, "MYSELECT", "select id, network, name, + count(*) as total, + sum(case when pday >= 0 then 1 else 0 end) as pobs, + sum(case when snow >= 0 then 1 else 0 end) as sobs, + sum(case when snowd >= 0 then 1 else 0 end) as sdobs, + sum(case when max_tmpf > -60 then 1 else 0 end) as tobs + from summary_$year s JOIN stations t on (t.iemid = s.iemid) + WHERE day >= $1 and day < ($1::date + '1 month'::interval) + and day < 'TOMORROW'::date + and t.wfo = $2 and t.network ~* 'COOP' GROUP by id, network, name + ORDER by id ASC"); + } else { + $rs = pg_prepare($dbconn, "MYSELECT", "select day, + count(*) as total, + sum(case when pday >= 0 then 1 else 0 end) as pobs, + sum(case when snow >= 0 then 1 else 0 end) as sobs, + sum(case when snowd >= 0 then 1 else 0 end) as sdobs, + sum(case when max_tmpf > -60 then 1 else 0 end) as tobs + from summary_$year s JOIN stations t on (t.iemid = s.iemid) + WHERE day >= $1 and day < ($1::date + '1 month'::interval) + and day < 'TOMORROW'::date + and t.wfo = $2 and t.network ~* 'COOP' GROUP by day ORDER by day ASC"); + } + $args = array($tstring, $wfo); } else { - $rs = pg_prepare($dbconn, "MYSELECT", "select day, - count(*) as total, - sum(case when pday >= 0 then 1 else 0 end) as pobs, - sum(case when snow >= 0 then 1 else 0 end) as sobs, - sum(case when snowd >= 0 then 1 else 0 end) as sdobs, - sum(case when max_tmpf > -60 then 1 else 0 end) as tobs - from summary_$year s JOIN stations t on (t.iemid = s.iemid) - WHERE day >= $1 and day < ($1::date + '1 month'::interval) - and day < 'TOMORROW'::date - and t.wfo = $2 and t.network ~* 'COOP' GROUP by day ORDER by day ASC"); + $tlabel = "year: {$year}"; + if ($by == "station") { + $rs = pg_prepare($dbconn, "MYSELECT", "select id, network, name, + count(*) as total, + sum(case when pday >= 0 then 1 else 0 end) as pobs, + sum(case when snow >= 0 then 1 else 0 end) as sobs, + sum(case when snowd >= 0 then 1 else 0 end) as sdobs, + sum(case when max_tmpf > -60 then 1 else 0 end) as tobs + from summary_$year s JOIN stations t on (t.iemid = s.iemid) + WHERE day < 'TOMORROW'::date + and t.wfo = $1 and t.network ~* 'COOP' GROUP by id, network, name + ORDER by id ASC"); + } else { + $rs = pg_prepare($dbconn, "MYSELECT", "select day, + count(*) as total, + sum(case when pday >= 0 then 1 else 0 end) as pobs, + sum(case when snow >= 0 then 1 else 0 end) as sobs, + sum(case when snowd >= 0 then 1 else 0 end) as sdobs, + sum(case when max_tmpf > -60 then 1 else 0 end) as tobs + from summary_$year s JOIN stations t on (t.iemid = s.iemid) + WHERE day < 'TOMORROW'::date + and t.wfo = $1 and t.network ~* 'COOP' GROUP by day ORDER by day ASC"); + } + $args = array($wfo); } $bselect = make_select("by", $by, array("station" => "Station", "day" => "Day")); +$tselect = make_select("tby", $tby, array("month" => "Month", "year" => "Year")); -$tstring = sprintf("%s-%02d-01", $year, intval($month)); -$data = pg_execute($dbconn, "MYSELECT", array($tstring, $wfo)); +$data = pg_execute($dbconn, "MYSELECT", $args); $t->title = "NWS COOP Obs per month per WFO"; @@ -55,9 +89,12 @@ for ($i = 0; $row = pg_fetch_assoc($data); $i++) { if ($by == "station") { $table .= sprintf( - "%s%s%s%s%s" . + "%s" . + "%s%s%s%s" . "%s%s", $row["id"], + $row["network"], + $row["id"], $row["name"], $row["total"], $row["pobs"], @@ -98,6 +135,7 @@ Select WFO: {$wselect} Aggregate By: {$bselect} +By Month or Year: {$tselect} Select Year:{$ys} Select Month:{$ms} @@ -105,7 +143,7 @@ -

COOP Report for wfo: {$wfo}, month: {$month}, year: {$year}

+

COOP Report for wfo: {$wfo}, {$tlabel}

diff --git a/htdocs/plotting/auto/scripts200/p242.py b/htdocs/plotting/auto/scripts200/p242.py index 5546508c32..736aaefd56 100644 --- a/htdocs/plotting/auto/scripts200/p242.py +++ b/htdocs/plotting/auto/scripts200/p242.py @@ -117,6 +117,7 @@ def overlay_info(fig, df): remark = "" if row["remark"] is not None: remark = "\n".join(wrap(row["remark"].strip(), width=50)) + remark = remark.replace("$", "--") msg = ( f"Valid: {row['utc_valid']:%Y-%m-%d %H:%M} UTC\n" f"Local Valid: {row['local_valid']:%Y-%m-%d %-I:%M %p}\n"