Skip to content

Commit

Permalink
Merge pull request #598 from akrherz/231127-2
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Nov 28, 2023
2 parents e137bb6 + dab6d74 commit 3ef93d3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 32 deletions.
75 changes: 49 additions & 26 deletions htdocs/DCP/site.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$OL = "7.2.2";
$OL = "8.1.0";
require_once "../../config/settings.inc.php";
define("IEM_APPID", 110);
require_once "../../include/mlib.php";
Expand All @@ -14,14 +14,15 @@ $day = get_int404("day", date("d"));
$month = get_int404("month", date("m"));
$year = get_int404("year", date("Y"));
$station = isset($_GET['station']) ? xssafe($_GET['station']) : null;
$shefvar = isset($_GET['shefvar']) ? xssafe($_GET['shefvar']) : null;
$network = get_str404("network", 'IA_DCP', 9);

$ts = mktime(1, 0, 0, $month, $day, $year);

$hads = iemdb("hads");
$mesosite = iemdb("mesosite");

if ($station != null) {
if (!is_null($station)) {
/* Make sure this site is not both a DCP and COOP site, this would cause
* the app to do a yearlong query, which is expensive.
*/
Expand All @@ -32,18 +33,34 @@ if ($station != null) {

if (preg_match('/_COOP/', $network) && $alone) {
$table = sprintf("raw%s", date("Y", $ts));
$rs = pg_prepare($hads, "QUERY", "SELECT * from $table WHERE
station = $1 ORDER by valid ASC");
$rs = pg_execute($hads, "QUERY", array($station));
if (is_null($shefvar)) {
$rs = pg_prepare($hads, "QUERY", "SELECT * from $table WHERE
station = $1 ORDER by valid ASC");
$rs = pg_execute($hads, "QUERY", array($station));
} else {
$rs = pg_prepare($hads, "QUERY", "SELECT * from $table WHERE
station = $1 and key = $2 ORDER by valid ASC");
$rs = pg_execute($hads, "QUERY", array($station, $shefvar));
}
} else {
$table = sprintf("raw%s_%s", date("Y", $ts), date("m", $ts));
$rs = pg_prepare($hads, "QUERY", "SELECT * from $table WHERE
if (is_null($shefvar)) {
$rs = pg_prepare($hads, "QUERY", "SELECT * from $table WHERE
station = $1 and valid BETWEEN $2 and $3 ORDER by valid ASC");
$rs = pg_execute(
$hads,
"QUERY",
array($station, date("Y-m-d", $ts), date("Y-m-d", $ts + 86400))
);
$rs = pg_execute(
$hads,
"QUERY",
array($station, date("Y-m-d", $ts), date("Y-m-d", $ts + 86400))
);
} else {
$rs = pg_prepare($hads, "QUERY", "SELECT * from $table WHERE
station = $1 and key = $2 and valid BETWEEN $3 and $4 ORDER by valid ASC");
$rs = pg_execute(
$hads,
"QUERY",
array($station, $shefvar, date("Y-m-d", $ts), date("Y-m-d", $ts + 86400))
);
}
}

$data = array();
Expand Down Expand Up @@ -102,11 +119,11 @@ $extra = "";
if (is_null($station)) {
$extra = <<<EOF
<style type="text/css">
#map {
width: 100%;
height: 400px;
border: 2px solid black;
}
#map {
width: 100%;
height: 400px;
border: 2px solid black;
}
</style>
<i>Click on the dot to select your site:</i><br />
<div id="map" data-network="{$network}"></div>
Expand All @@ -121,24 +138,30 @@ EOF;
}
$extra .= "<br /><br />
<table class=\"table table-striped table-bordered\" style=\"width: auto;\">";
$theader = "<thead><tr><th>Site:</th><th>Valid:</th>";
$theader = "<thead class=\"sticky\"><tr><th>Site:</th><th>Valid:</th>";
foreach ($mycols as $k => $v) {
$theader .= "<th>$v</th>";
$theader .= sprintf(
'<th><a href="site.phtml?station=%s&amp;network=%s&amp;year=%s' .
'&amp;month=%s&amp;day=%s&amp;shefvar=%s">%s</a></th>',
$station,
$network,
date("Y", $ts),
date("m", $ts),
date("d", $ts),
$v,
$v,
);
}
$theader .= "</tr></thead>";
$extra .= $theader;

$times = array_keys($data);
if (sizeof($times) == 0) {
$extra .= $theader;
$extra .= "<tr><td colspan=\"2\">No Data Found</td></tr>";
}
$colorme = True;
$cnt = 0;
foreach ($times as $k => $ts) {
if ($cnt % 30 == 0) {
$extra .= $theader;
}

$extra .= sprintf(
"<tr%s><td>%s</td><td><a href='cat.phtml?year=%s&month=%s&day=%s&hour=%s&minute=%s'>%s</a></td>",
($colorme) ? " style='background: #eee;'" : "",
Expand Down Expand Up @@ -171,9 +194,9 @@ $t->content = <<<EOM
<ul>
<li>Timestamps are presented in central standard or daylight time</li>
<li>The column headings are the
<a href="http://www.weather.gov/ohd/hrl/shef/indexshef.htm">SHEF</a> encoded
<a href="https://vlab.noaa.gov/web/mdl/shef-information">SHEF</a> encoded
variable names.</li>
<li>Archive begins on 1 Jan 2002 for Iowa, 9 Dec 2010 for other states.
<li>Archive begins on 1 Jan 2002 for Iowa, 9 Dec 2010 for other states.
The archive is not complete for all the sites listed.</li>
<li>The IEM classifies SHEF provided data into two classes on a state by
state basis. The COOP network sites are mostly official once-daily cooperative
Expand All @@ -196,7 +219,7 @@ $t->content = <<<EOM
</thead>
<tr>
<td>{$n2select}
<br /><a href="site.phtml?year={$year}&month={$month}&day={$day}">Select from map</a></td>
<br /><a href="site.phtml?year={$year}&month={$month}&day={$day}&network={$network}">Select from map</a></td>
<td>{$ys}</td>
<td>{$ms}</td>
<td>{$ds}</td>
Expand Down
6 changes: 2 additions & 4 deletions scripts/ingestors/other/parse0010.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def main():
iem = Observation("OT0010", "OT", valid)

iem.data["tmpf"] = float(tokens[4])
iem.data["max_tmpf"] = float(tokens[5])
iem.data["min_tmpf"] = float(tokens[6])
relh = int(tokens[7])
if 0 < relh <= 100:
iem.data["relh"] = int(tokens[7])
iem.data["relh"] = int(tokens[6])
iem.data["dwpf"] = (
dewpoint_from_relative_humidity(
units("degF") * iem.data["tmpf"],
Expand All @@ -59,7 +57,7 @@ def main():
float(tokens[9]), "mile / hour", "knot"
)
iem.data["alti"] = float(tokens[11])
iem.data["pday"] = float(tokens[13]) / 100.0
iem.data["pday"] = float(tokens[12]) / 100.0
iem.data["srad"] = float(tokens[17])

iem.save(cursor)
Expand Down
5 changes: 3 additions & 2 deletions scripts/other/ot2archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ def dowork(ts, ts2):
row["gust"],
row["c1tmpf"],
row["srad"],
row["relh"],
)
ocursor.execute(
"INSERT into alldata(station, valid, tmpf, dwpf, drct, sknt, "
"alti, pday, gust, c1tmpf, srad) values "
"(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
"alti, pday, gust, c1tmpf, srad, relh) values "
"(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
args,
)

Expand Down

0 comments on commit 3ef93d3

Please sign in to comment.