Skip to content

Commit

Permalink
Merge pull request #556 from akrherz/231018
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Oct 19, 2023
2 parents ca191f4 + d1f4e55 commit 9fd06c0
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 53 deletions.
15 changes: 5 additions & 10 deletions cgi-bin/request/asos1min.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pyiem.exceptions import IncompleteWebRequest
from pyiem.util import get_dbconnc
from pyiem.webutil import iemapp
from pyiem.webutil import ensure_list, iemapp

SAMPLING = {
"1min": 1,
Expand Down Expand Up @@ -74,23 +74,18 @@ def compute_prefixes(sio, form, delim, stations, tz) -> dict:
@iemapp()
def application(environ, start_response):
"""Handle mod_wsgi request."""
stations = environ.get("station", [])
stations = ensure_list(environ, "station")
if not stations: # legacy php
stations = environ.get("station[]", [])
# Ensure stations is a list
if isinstance(stations, str):
stations = [stations]
stations = ensure_list(environ, "station[]")
if not stations:
raise IncompleteWebRequest("No station= was specified in request.")
delim = DELIM[environ.get("delim", "comma")]
sample = SAMPLING[environ.get("sample", "1min")]
what = environ.get("what", "dl")
tz = environ.get("tz", "UTC")
varnames = environ.get("vars", [])
varnames = ensure_list(environ, "vars")
if not varnames: # legacy php
varnames = environ.get("vars[]", [])
if isinstance(varnames, str):
varnames = [varnames]
varnames = ensure_list(environ, "vars[]")
if not varnames:
raise IncompleteWebRequest("No vars= was specified in request.")
pgconn, cursor = get_dbconnc("asos1min")
Expand Down
14 changes: 4 additions & 10 deletions cgi-bin/request/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyiem.exceptions import IncompleteWebRequest
from pyiem.network import Table as NetworkTable
from pyiem.util import get_dbconn, get_sqlalchemy_conn
from pyiem.webutil import iemapp
from pyiem.webutil import ensure_list, iemapp
from sqlalchemy import text

EXL = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Expand Down Expand Up @@ -138,20 +138,14 @@ def application(environ, start_response):
return [b"ERROR: server over capacity, please try later"]

fmt = environ.get("format", "csv")
stations = environ.get("stations", [])
if isinstance(stations, str):
stations = [stations]
stations = ensure_list(environ, "stations")
if not stations:
stations = environ.get("station", [])
if isinstance(stations, str):
stations = [stations]
stations = ensure_list(environ, "station")
if not stations:
start_response("200 OK", [("Content-type", "text/plain")])
return [b"ERROR: No stations specified for request"]
network = environ.get("network")[:12]
cols = environ.get("var", [])
if isinstance(cols, str):
cols = [cols]
cols = ensure_list(environ, "var")
na = environ.get("na", "None")
if na not in ["M", "None", "blank"]:
start_response("200 OK", [("Content-type", "text/plain")])
Expand Down
10 changes: 3 additions & 7 deletions cgi-bin/request/gis/lsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shapefile
from pyiem.exceptions import IncompleteWebRequest
from pyiem.util import get_dbconn, get_sqlalchemy_conn, utc
from pyiem.webutil import iemapp
from pyiem.webutil import ensure_list, iemapp

fiona.supported_drivers["KML"] = "rw"
EXL = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Expand Down Expand Up @@ -114,17 +114,13 @@ def application(environ, start_response):
statelimiter = ""
for opt in ["state", "states", "states[]"]:
if opt in environ:
aStates = environ.get(opt, [])
if isinstance(aStates, str):
aStates = [aStates]
aStates = ensure_list(environ, opt)
aStates.append("XX")
if "_ALL" not in aStates:
statelimiter = f" and l.state in {tuple(aStates)} "
wfoLimiter = ""
if "wfo[]" in environ:
aWFO = environ.get("wfo[]", [])
if isinstance(aWFO, str):
aWFO = [aWFO]
aWFO = ensure_list(environ, "wfo[]")
aWFO.append("XXX") # Hack to make next section work
if "ALL" not in aWFO:
wfoLimiter = f" and l.wfo in {tuple(aWFO)} "
Expand Down
14 changes: 4 additions & 10 deletions cgi-bin/request/gis/watchwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pandas as pd
from pyiem.exceptions import IncompleteWebRequest
from pyiem.util import get_dbconnc, get_sqlalchemy_conn, utc
from pyiem.webutil import iemapp
from pyiem.webutil import ensure_list, iemapp
from shapely.geometry import mapping
from shapely.wkb import loads

Expand All @@ -34,17 +34,13 @@ def parse_wfo_location_group(form):
"""Parse wfoLimiter"""
limiter = ""
if "wfo[]" in form:
wfos = form.get("wfo[]", [])
if not isinstance(wfos, list):
wfos = [wfos]
wfos = ensure_list(form, "wfo[]")
wfos.append("XXX") # Hack to make next section work
if "ALL" not in wfos:
limiter = f" and w.wfo in {tuple(char3(wfos))} "

if "wfos[]" in form:
wfos = form.get("wfos[]", [])
if not isinstance(wfos, list):
wfos = [wfos]
wfos = ensure_list(form, "wfos[]")
wfos.append("XXX") # Hack to make next section work
if "ALL" not in wfos:
limiter = f" and w.wfo in {tuple(char3(wfos))} "
Expand All @@ -59,9 +55,7 @@ def build_sql(environ):
location_group = environ.get("location_group", "wfo")
if location_group == "states":
if "states[]" in environ:
arstates = environ.get("states[]", [])
if not isinstance(arstates, list):
arstates = [arstates]
arstates = ensure_list(environ, "states[]")
states = [x[:2].upper() for x in arstates]
states.append("XX") # Hack for 1 length
wfo_limiter = (
Expand Down
12 changes: 3 additions & 9 deletions cgi-bin/request/talltowers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,9 @@ def application(environ, start_response):
fmt = environ.get("format")
# Build out our variable list
tokens = []
zz = environ.get("z", [])
if isinstance(zz, str):
zz = [zz]
varnames = environ.get("var", [])
if isinstance(varnames, str):
varnames = [varnames]
aggs = environ.get("agg", [])
if isinstance(aggs, str):
aggs = [aggs]
zz = ensure_list(environ, "z")
varnames = ensure_list(environ, "var")
aggs = ensure_list(environ, "agg")
for z in zz:
for v in varnames:
v1 = v
Expand Down
2 changes: 1 addition & 1 deletion htdocs/plotting/auto/scripts100/p107.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def plotter(fdict):
doff = "year"
if ctx["eday"] < ctx["sday"]:
dtlimiter = "(sday >= :sday or sday <= :eday)"
doff = "case when sday < :eday then year - 1 else year end"
doff = "case when sday <= :eday then year - 1 else year end"
if stop is not None:
dtlimiter = "sday >= :sday"
doff = "year"
Expand Down
6 changes: 3 additions & 3 deletions htdocs/plotting/auto/scripts100/p140.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ def plotter(fdict):
doff = "extract(year from day)"
if ctx["eday"] < ctx["sday"]:
dtlimiter = (
"(to_char(day, 'mmdd') >= :eday or "
"to_char(day, 'mmdd') <= :sday)"
"(to_char(day, 'mmdd') >= :sday or "
"to_char(day, 'mmdd') <= :eday)"
)
doff = (
"case when to_char(day, 'mmdd') < :sday then "
"case when to_char(day, 'mmdd') <= :eday then "
"(extract(year from day)::int - 1) else extract(year from day) end"
)
threshold = ctx["thres"]
Expand Down
36 changes: 33 additions & 3 deletions include/generators.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,23 @@ function get_website_stats()
}
$bcolor = "success";
$rcolor = "success";
$ocolor = "success";
$acolor = "success";
$bandwidth = 0;
$req = 0;
$ok = 0;
$apirate = 0;
if ($val) {
$jobj = json_decode($val);

$ok = $jobj->stats->telemetry_ok;
if ($ok < 90) $ocolor = "warning";
if ($ok < 80) $ocolor = "danger";

$apirate = $jobj->stats->telemetry_rate;
if ($apirate < 10) $acolor = "warning";
if ($apirate < 5) $acolor = "danger";

$bandwidth = $jobj->stats->bandwidth / 1000000.0;
// grading of the bandwidth (MB/s)
if ($bandwidth > 35) $bcolor = "warning";
Expand All @@ -83,8 +95,12 @@ function get_website_stats()
}
$label = sprintf("%.1f MB/s", $bandwidth);
$bpercent = intval($bandwidth / 124.0 * 100.0);
$rlabel = number_format($req);
$rlabel = sprintf("%s req/s", number_format($req));
$rpercent = intval($req / 15000.0 * 100.0);
$olabel = sprintf("%.0f%%", $ok);
$opercent = intval($ok);
$alabel = sprintf("%.1f req/s", $apirate);
$apercent = intval($apirate / 100.0 * 100.0);

$s = <<<EOF
<div class="panel panel-default">
Expand All @@ -97,12 +113,26 @@ function get_website_stats()
</div>
</div>
<span>Requests/Second: {$rlabel}</span>
<span>Total Website: {$rlabel}</span>
<div class="progress">
<div class="progress-bar progress-bar-{$rcolor}" role="progressbar" aria-valuenow="{$rpercent}" aria-valuemin="0" aria-valuemax="100" style="width: {$rpercent}%;">
</div>
</div>
<span>API/Data Services: {$alabel}</span>
<div class="progress">
<div class="progress-bar progress-bar-{$acolor}" role="progressbar" aria-valuenow="{$apercent}" aria-valuemin="0" aria-valuemax="100" style="width: {$apercent}%;">
</div>
</div>
<span>API Success: {$olabel}</span>
<div class="progress">
<div class="progress-bar progress-bar-{$ocolor}" role="progressbar"
aria-valuenow="{$opercent}" aria-valuemin="0" aria-valuemax="100"
style="width: {$opercent}%;">
</div>
</div>
</div>
</div>
EOF;
Expand Down

0 comments on commit 9fd06c0

Please sign in to comment.