Commit 1c73121c authored by Jerome Touvier's avatar Jerome Touvier

Merge branch 'update' into 'master'

Update

See merge request !11
parents 1396d088 4bca529a
Pipeline #49170 passed with stage
in 37 seconds
......@@ -32,10 +32,6 @@ def is_like_or_equal(params, key):
return " OR ".join(subquery)
def get_table():
return "sent_data_summary_weekly"
def sql_common_string(params, begin=""):
s = begin
# network, station, location, channel parameters
......@@ -72,13 +68,18 @@ def sql_request(params):
s = f"""{s} AND ({is_like_or_equal(params, "year")})"""
s = f"""{s} ORDER BY {columns}, date DESC"""
return s.replace("?", "_").replace("*", "%")
else:
table = "sent_data_summary_weekly"
if params["request"] == "country":
s = f"SELECT country, sum(requests)::INTEGER FROM {get_table()}"
if "all" in params["country"]:
s = f"SELECT sum(requests)::INTEGER, sum(hll_cardinality(clients))::INTEGER FROM {table}"
else:
s = f"SELECT country, sum(requests)::INTEGER, sum(hll_cardinality(clients))::INTEGER FROM {table}"
elif params["request"] == "send":
s = f"SELECT sum(bytes) FROM {get_table()}"
s = f"SELECT sum(bytes)::INTEGER FROM {table}"
elif params["request"] == "timeseries":
s = f"SELECT date, country, sum(bytes), sum(hll_cardinality(clients))::INTEGER FROM {get_table()}"
s = f"SELECT date, country, sum(bytes)::INTEGER, sum(hll_cardinality(clients))::INTEGER FROM {table}"
s = sql_common_string(params, s)
if "all" not in params["country"]:
......@@ -91,7 +92,7 @@ def sql_request(params):
elif "dataselect" in params["media"]:
s = f"{s} AND protocol = 'dataselect'"
if params["request"] == "country":
if params["request"] == "country" and "all" not in params["country"]:
s = f"""{s} GROUP BY country"""
elif params["request"] == "timeseries":
if "seedlink" in params["media"] and "dataselect" in params["media"]:
......@@ -116,35 +117,20 @@ def collect_data(params):
return curs.fetchall()
def sum_results(params, data):
""" Adds the results from the different media tables. """
newdata = list()
def format_results(params, data):
data = list(map(list, data))
if params["request"] == "country":
result = dict()
for row in data:
if row[1]:
if row[0] in result: # Is this country already there ?
result[row[0]] = result[row[0]] + int(row[1])
else:
result[row[0]] = int(row[1])
if "all" in params["country"]:
result = {"all": sum([int(val) for val in result.values()])}
for key, val in result.items():
newdata.append([key, "{:_}".format(val)])
data = [["all", data[0][0], data[0][1]]]
for row in data:
row[:] = [row[0], "{:_}".format(row[1]), "{:_}".format(row[2])]
elif params["request"] == "send":
result = 0
for row in data:
if row[0]:
result = result + int(row[0])
newdata.append(
["{:_}".format(result) + f" bytes ({human_readable_size(result)})"]
)
result = data[0][0]
data = [["{:_}".format(result) + f" bytes ({human_readable_size(result)})"]]
return newdata
return data
def get_header(params):
......@@ -152,7 +138,7 @@ def get_header(params):
header = ["size", "year", "network", "station", "channel", "quality", "type"]
header.append("lastupdated")
elif params["request"] == "country":
header = ["country", "requests"]
header = ["country", "requests", "clients"]
elif params["request"] == "send":
if len(params["media"]) == 1 and "all" not in params["media"]:
if "seedlink" in params["media"]:
......@@ -222,15 +208,12 @@ def get_output(params):
if data is None:
return data
if params["request"] in ("send", "country"):
data = sum_results(params, data)
if not data:
code = params["nodata"]
return error_request(msg=f"HTTP._{code}_", details=Error.NODATA, code=code)
logging.info(f"Number of collected rows: {len(data)}")
data = [[str(val) for val in row] for row in data]
data = format_results(params, data)
return get_response(params, data)
except Exception as ex:
logging.exception(str(ex))
......
# Webservice FDSN ws-statistics
# Webservice ws-statistics
This service provides access to the RESIF-DC statistics.
......
# Webservice FDSN ws-statistics
# Webservice ws-statistics
Ce service donne accès aux statistiques de RESIF-DC.
......
......@@ -5,18 +5,20 @@
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>RESIF: RESIFWS: Statistics Docs: v1</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<link rel="stylesheet" href="./static/resifws.css"/>
<a href="./local=en"> <img src="./static/images/en.png" alt="Français - Anglais"> </a>
</head>
<body>
<p style="text-align:center;"> <img src="./static/images/logoresif.png" alt="logoresif" width="341" height="95"></p>
<h1 id="webservice-fdsn-ws-statistics">Webservice FDSN ws-statistics</h1>
<h1 id="webservice-ws-statistics">Webservice ws-statistics</h1>
<p>Ce service donne accès aux statistiques de RESIF-DC.</p>
<h2 id="utilisation-de-la-requête">Utilisation de la requête</h2>
<pre><code>/query? (request-options) [channel-options] [date-options] [storage-options] [send-options] [output-options]
......
......@@ -5,18 +5,20 @@
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>RESIF: RESIFWS: Statistics Docs: v1</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<link rel="stylesheet" href="./static/resifws.css"/>
<a href="./local=fr"> <img src="./static/images/fr.png" alt="Anglais - Français"> </a>
</head>
<body>
<p style="text-align:center;"> <img src="./static/images/logoresif.png" alt="logoresif" width="341" height="95"></p>
<h1 id="webservice-fdsn-ws-statistics">Webservice FDSN ws-statistics</h1>
<h1 id="webservice-ws-statistics">Webservice ws-statistics</h1>
<p>This service provides access to the RESIF-DC statistics.</p>
<h2 id="query-usage">Query usage</h2>
<pre><code>/query? (request-options) [channel-options] [date-options] [storage-options] [send-options] [output-options]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment