Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnibus #1087

Merged
merged 2 commits into from
Jan 29, 2025
Merged

Omnibus #1087

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 78 additions & 98 deletions htdocs/cocorahs/current.phtml
Original file line number Diff line number Diff line change
@@ -1,59 +1,38 @@
<?php
<?php
require_once "../../config/settings.inc.php";
require_once "../../include/myview.php";
require_once "../../include/network.php";
require_once "../../include/forms.php";
require_once "../../include/imagemaps.php";
require_once "../../include/database.inc.php";
require_once "../../include/mlib.php";
$t = new MyView();

define("IEM_APPID", 56);
$network = isset($_GET['network']) ? xssafe($_GET['network']): 'IA_COCORAHS';
$sortcol = isset($_GET['sortcol']) ? xssafe($_GET['sortcol']): 'ts';
$network = isset($_GET['network']) ? xssafe($_GET['network']) : 'IA_COCORAHS';
$sortcol = isset($_GET['sortcol']) ? xssafe($_GET['sortcol']) : 'ts';

$nselect = '<select name="network">';
$mesosite = iemdb("mesosite");
$rs = pg_query(
$mesosite,
"SELECT id, name from networks where id ~* '_COCORAHS' ORDER by name ASC");
for ($i = 0; $row = pg_fetch_assoc($rs); $i++) {
$sel = '';
if ($network == $row["id"]) {
$sel = " selected='SELECTED'";
}
$nselect .= sprintf(
"<option value='%s'%s>%s</option>\n",
$row["id"],
$sel,
$row["name"]
);
function ffmt($val){
if (is_null($val)) return "M";
if ($val > 0 and $val < 0.005) return "T";
return sprintf("%.2f", $val);
}
$nselect .= "</select>";

$nselect = selectNetworkType("COCORAHS", $network);

$t->title = "CoCoRaHS Last Observation";
$t->headextra = <<<EOF
<script language="JavaScript" type="text/javascript">
<!--//BEGIN Script
function new_window(url) {
link = window.open(url,"_new","toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600");
}
//END Script-->
</script>
EOF;
$t->current_network = "CoCoRaHS";

$nt = new NetworkTable($network);

$dbconn = iemdb("coop");
$year = date("Y");
$sql = <<<EOM
with today as (
select t.id, c.*, t.tzname
select t.id, c.*, t.tzname, t.name, t.county
from cocorahs_$year c JOIN stations t on (c.iemid = t.iemid)
WHERE day = 'TODAY' and t.network = $1),
month as (
SELECT iemid,
sum(precip) as pmonth, count(*) as count from
sum(case when precip is not null then 1 else 0 end) as count,
sum(precip) as pmonth from
cocorahs_$year s WHERE day >= $2 GROUP by iemid)

select t.*, m.pmonth, m.count,
Expand All @@ -62,38 +41,45 @@ from today t JOIN month m on (t.iemid = m.iemid)
ORDER by t.id asc
EOM;
$day1 = new DateTime();
;
$days_this_month = intval($day1->format("d"));
$rs = pg_prepare($dbconn, "CS", $sql);
$rs = pg_execute($dbconn, "CS", array($network, $day1->format("Y-m") .'-01'));
$monthDict = Array();
$db = Array();
for( $i=0; $row = pg_fetch_array($rs); $i++){
$site = $row["id"];
$db[$site] = Array(
'pmonth' => $row["pmonth"],
'count' => $row["count"],
'snow'=> "", 'snowd'=>"", 'ratio'=>"", 'pday'=>"", 'pmonth'=>"", 'pmiss' => "");
$db[$site]['ts'] = strtotime($row["local_valid"]);
$db[$site]['sid'] = $site;
$db[$site]['name'] = $nt->table[$site]["name"];
$db[$site]['county'] = $nt->table[$site]["county"];
$db[$site]['pday'] = $row["precip"];
$db[$site]['snow'] = ($row["snow"] >= 0) ? $row["snow"] : " ";
$db[$site]['snowd'] = ($row["snowd"] >= 0) ? $row["snowd"] : " ";
$db[$site]["ratio"] = -1;
if ($db[$site]["snow"] > 0.0001 && $db[$site]["pday"] > 0.0001)
{
$db[$site]["ratio"] = intval( $db[$site]["snow"] / $db[$site]["pday"] );
}
$rs = pg_execute($dbconn, "CS", array($network, $day1->format("Y-m") . '-01'));
$db = array();
for ($i = 0; $row = pg_fetch_array($rs); $i++) {
$site = $row["id"];
$db[$site] = array(
'sid' => $site,
'ts' => strtotime($row["local_valid"]),
'name' => $row["name"],
'county' => $row["county"],
'pmonth' => $row["pmonth"],
'count' => $row["count"],
'snow' => ($row["snow"] >= 0) ? $row["snow"] : " ",
'snowd' => ($row["snowd"] >= 0) ? $row["snowd"] : " ",
'ratio' => -1,
'pday' => $row["precip"],
'pmonth' => $row["pmonth"],
'pmiss' => $days_this_month - $row["count"],
);
if ($db[$site]["snow"] > 0.0001 && $db[$site]["pday"] > 0.0001) {
$db[$site]["ratio"] = intval($db[$site]["snow"] / $db[$site]["pday"]);
}
}
$db = aSortBySecondIndex($db, $sortcol, "desc");

$cols = Array("ts" => "Valid", "county" => "County",
"sid" => "Site ID", "name" => "Station Name",
"tmpf" => "Ob Temperature", "max_tmpf" => "24 hour High",
"min_tmpf" => "24 hour Low", "snow" => "24 hour Snowfall",
"snowd" => "Snowfall Depth", "pday" => "24 hour rainfall",
"pmonth" => "Precipitation for Month");
$cols = array(
"ts" => "Valid",
"county" => "County",
"sid" => "Site ID",
"name" => "Station Name",
"tmpf" => "Ob Temperature",
"max_tmpf" => "24 hour High",
"min_tmpf" => "24 hour Low",
"snow" => "24 hour Snowfall",
"snowd" => "Snowfall Depth",
"pday" => "24 hour rainfall",
"pmonth" => "Precipitation for Month"
);

$baseurl2 = "current.phtml?sortcol=";
$content = <<<EOM
Expand All @@ -109,7 +95,7 @@ Option 1: <strong>View by State:</strong> {$nselect}

<form name="st" action="/my/current.phtml" method="GET">
<table class="table table-striped table-condensed table-bordered">
<thead>
<thead class="sticky">
<tr>
<th rowspan="2">Add:</th>
<th rowspan="2"><a href="{$baseurl2}sid">SiteID:</a></th>
Expand All @@ -127,50 +113,44 @@ Option 1: <strong>View by State:</strong> {$nselect}
</tr></thead>
<tbody>
EOM;
$oddrow = true;
$now = time();
foreach($db as $site => $value){
$tdiff = $now - $value["ts"];
if ( intval( date("Y", $value["ts"]) ) < 2003 ) continue;
$oddrow = ! $oddrow;

$content .= "<tr ";
if ($oddrow) $content .= "bgcolor=\"#EEEEEE\"";
$content .= <<<EOM
><th><input type="checkbox" name="st[]"
value="{$site}"></th><td><a href="/sites/site.php?station={$site}&network={$network}">$site</a></td>
<td>{$value["name"]}</td>
<td>{$value["county"]}</td>
$oddrow = true;
$now = time();
foreach ($db as $site => $value) {
$tdiff = $now - $value["ts"];
$obslink = sprintf("obs.phtml?station=%s&network=%s", $site, $network);
$content .= <<<EOM
<tr>
<th><input type="checkbox" name="st[]" value="{$site}"></th>
<td>
<a href="{$obslink}" alt="View Obs"><i class="fa fa-list"></i></a>
<a href="/sites/site.php?station={$site}&network={$network}">$site</a></td>
<td>{$value["name"]}</td>
<td>{$value["county"]}</td>
EOM;
$content .= "<td ";
if ($tdiff > (24*3600) || date("Ymd") != date("Ymd", $value["ts"]) ){
$content .= 'bgcolor="red">'. date("d M Y h:i A", $value["ts"]) .'</td>';
} else {
$content .= ">". date("h:i A", $value["ts"]) ."</td>";
}
$content .= "<td>" . date("h:i A", $value["ts"]) . "</td>";

if ($value["pday"] == 0.0001) $value["pday"] = "T";
if ($value["pmonth"] == 0.0001) $value["pmonth"] = "T";
if ($value["pday"] < 0) $value["pday"] = "M";
if ($value["snow"] == 0.0001) $value["snow"] = "T";
if ($value["snowd"] == 0.0001) $value["snowd"] = "T";
if ($value["snow"] < 0) $value["snow"] = "M";
if ($value["pday"] == 0.0001) $value["pday"] = "T";
if ($value["pmonth"] == 0.0001) $value["pmonth"] = "T";
if ($value["pday"] < 0) $value["pday"] = "M";
if ($value["snow"] == 0.0001) $value["snow"] = "T";
if ($value["snowd"] == 0.0001) $value["snowd"] = "T";
if ($value["snow"] < 0) $value["snow"] = "M";

$content .= "<td>". $value["pday"] ."</td>";
$content .= "<td>". $value["pmonth"];
if ($value["pmiss"] > 0) $content .= " (". $value["pmiss"] .")";
$content .= "<td>" . $value["pday"] . "</td>";
$content .= "<td>" . ffmt($value["pmonth"]);
if ($value["pmiss"] > 0) $content .= " (" . $value["pmiss"] . ")";
$content .= "</td>";
$content .= "<td>". $value["snow"] ."</td>";
if ($value["ratio"] > 0) $content .= "<td>". $value["ratio"] ."</td>";
$content .= "<td>" . $value["snow"] . "</td>";
if ($value["ratio"] > 0) $content .= "<td>" . $value["ratio"] . "</td>";
else $content .= "<td></td>";
$content .= "<td>". $value["snowd"] ."</td>";
$content .= "</tr>";
}
$content .= "<td>" . $value["snowd"] . "</td>";
$content .= "</tr>";
}
$content .= <<<EOM
</tbody>
</table>
<input type="submit" value="Add to Favorites">
</form>
</form>
EOM;
$t->content = $content;
$t->render('sortables.phtml');
17 changes: 5 additions & 12 deletions htdocs/cocorahs/obs.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require_once "../../include/database.inc.php";
$access = iemdb("coop");
require_once "../../include/myview.php";
require_once "../../include/forms.php";
require_once "../../include/network.php";

$t = new MyView();
$t->title = "CoCoRaHS Observations";
Expand All @@ -23,21 +22,19 @@ if (
$sortdir = "DESC";
}

$nt = new NetworkTable($network);

$ys = yearSelect(2007, $year, "year");

if (strlen($station) > 0) {
$rs = pg_prepare(
$access, "SELECTOR",
"SELECT s.*, t.id as station from cocorahs_$year s JOIN stations t
"SELECT s.*, t.id as station, t.name, t.county from cocorahs_$year s JOIN stations t
ON (t.iemid = s.iemid) WHERE t.id = $1
ORDER by $sortvar $sortdir");
$rs = pg_execute($access, "SELECTOR", array($station));
} else {
$rs = pg_prepare($access, "SELECTOR",

"SELECT s.*, t.id as station
"SELECT s.*, t.id as station, t.name, t.county
from cocorahs_$year s JOIN stations t
ON (t.iemid = s.iemid) WHERE day = $1 and
network = $2 ORDER by $sortvar $sortdir");
Expand Down Expand Up @@ -70,16 +67,12 @@ for ($i = 0; $row = pg_fetch_assoc($rs); $i++) {
if (strlen($station) > 0) {
$table .= $nwsli;
} else {
$table .= "<a href=\"obs.phtml?station=" . $nwsli . "&network=" . $network . "\">" . $nwsli . "</a>";
$table .= "<a href=\"obs.phtml?station={$nwsli}&network={$network}\">{$nwsli}</a>";
}

$table .= "</td><td>" . $nt->table[$nwsli]["name"] . "</td><td>" . $nt->table[$nwsli]["county"] . "</td><td>";
$table .= "</td><td>" . $row["name"] . "</td><td>" . $row["county"] . "</td><td>";

if (strlen($date) > 0) {
$table .= $row["day"];
} else {
$table .= "<a href=\"obs.phtml?date=" . $row["day"] . "&network=" . $network . "\">" . $row["day"] . "</a>";
}
$table .= "<a href=\"obs.phtml?date=" . $row["day"] . "&network=" . $network . "\">" . $row["day"] . "</a>";

$table .= "</td><td>" . $rain . "</td><td>" . $snow . "</td><td>" . $snowd . "</td></tr>\n";
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/request/download.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $network = isset($_GET['network']) ? xssafe($_GET['network']): "IA_ASOS";
$station = "";
$t->title = "Download ASOS/AWOS/METAR Data";

$netselect = selectAzosNetwork($network);
$netselect = selectNetworkType("ASOS", $network);

$y1select = yearSelect2(1928, date("Y"), "year1");
$y2select = yearSelect2(1928, date("Y"), "year2");
Expand Down
4 changes: 3 additions & 1 deletion htdocs/sites/networks.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ function pretty_date($val, $fmt = "M d, Y")
}

if ($network == '_ALL_') {
// Too much memory at the moment
$rs = pg_query(
$pgconn,
"SELECT id, name, elevation, archive_begin, archive_end, network, " .
"ST_x(geom) as lon, ST_y(geom) as lat, null as attributes, state, " .
"synop, country from stations WHERE online = 'y' ORDER by name"
"synop, country from stations WHERE online = 't' and ".
"network !~* '_COCORAHS' ORDER by name"
);
$cities = array();
for ($i = 0; $row = pg_fetch_array($rs); $i++) {
Expand Down
21 changes: 16 additions & 5 deletions include/imagemaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,32 @@ function ugcStateSelect($state, $selected)
}


function selectAzosNetwork($network)
/**
* Select a network type
* @param nettype the network type
* @param selected the selected network id
* @return the select box
*/
function selectNetworkType($nettype, $selected)
{
$network = strtoupper($network);
include_once dirname(__FILE__) . "/database.inc.php";
$selected = strtoupper($selected);
require_once dirname(__FILE__) . "/database.inc.php";
$dbconn = iemdb('mesosite');
$rs = pg_exec($dbconn, "SELECT * from networks WHERE id ~* 'ASOS' ORDER by name ASC");
$rs = pg_prepare(
$dbconn,
"SELECT_NETWORK_BY_TYPE",
"SELECT * from networks WHERE id ~* $1 ORDER by name ASC");
$rs = pg_execute($dbconn, "SELECT_NETWORK_BY_TYPE", array($nettype));
$s = "<select name=\"network\">\n";
for ($i = 0; $row = pg_fetch_array($rs); $i++) {
$s .= "<option value=\"" . $row["id"] . "\" ";
if ($row["id"] == $network) {
if ($row["id"] == $selected) {
$s .= "SELECTED";
}
$s .= ">" . $row["name"] . "</option>\n";
}
$s .= "</select>\n";
pg_close($dbconn);
return $s;
}

Expand Down
2 changes: 1 addition & 1 deletion pylib/iemweb/autoplot/scripts/p85.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def plotter(ctx: dict):
if ctx["scale"] == "100":
ax.set_xlim(0, 100)
ax.set_xticks([0, 5, 25, 50, 75, 95, 100])
ax.set_xlabel(f"Frequency [%s] (Hour Timezone: {tzname})")
ax.set_xlabel(f"Frequency [%] (Hour Timezone: {tzname})")
ax.set_ylim(-0.5, 23.5)

return fig, df
Loading