Skip to content

Commit

Permalink
Merge pull request #568 from akrherz/231030
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Oct 31, 2023
2 parents 9685ab3 + 49b824e commit 7516840
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion cgi-bin/request/gis/wpc_mpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
88 changes: 63 additions & 25 deletions htdocs/nws/coop-cnts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -55,9 +89,12 @@
for ($i = 0; $row = pg_fetch_assoc($data); $i++) {
if ($by == "station") {
$table .= sprintf(
"<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" .
"<tr><td><a href=\"/sites/site.php?station=%s&amp;network=%s\">%s</a></td>" .
"<td>%s</td><td>%s</td><td>%s</td><td>%s</td>" .
"<td>%s</td><td>%s</td></tr>",
$row["id"],
$row["network"],
$row["id"],
$row["name"],
$row["total"],
$row["pobs"],
Expand Down Expand Up @@ -98,14 +135,15 @@
<tr>
<td><strong>Select WFO:</strong> {$wselect} </td>
<td><strong>Aggregate By:</strong> {$bselect} </td>
<td><strong>By Month or Year:</strong> {$tselect} </td>
<td><strong>Select Year:</strong>{$ys}</td>
<td><strong>Select Month:</strong>{$ms}</td>
</tr>
</table>
<input type="submit" value="View Report" />
</form>
<h3>COOP Report for wfo: {$wfo}, month: {$month}, year: {$year}</h3>
<h3>COOP Report for wfo: {$wfo}, {$tlabel}</h3>
<table class="table table-striped table-condensed table-bordered">
<thead class="sticky">
Expand Down
1 change: 1 addition & 0 deletions htdocs/plotting/auto/scripts200/p242.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7516840

Please sign in to comment.