statistics.html: Consolidate code
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
f12a3f5a3e
commit
0af1c76254
|
@ -325,62 +325,38 @@ def user_info(nickname):
|
|||
@app.route('/statistics')
|
||||
def global_statistics():
|
||||
mysql = FreifunkMySQL()
|
||||
hoods = stattools.hoods(mysql)
|
||||
|
||||
stats = mysql.fetchall("SELECT * FROM stats_global")
|
||||
stats = mysql.utcawaretupleint(stats,"time")
|
||||
|
||||
numnew = len(hoods)-18
|
||||
if numnew < 1:
|
||||
numnew = 1
|
||||
|
||||
newest_routers = mysql.fetchall("""
|
||||
SELECT id, hostname, hood, created
|
||||
FROM router
|
||||
WHERE hardware <> 'Legacy'
|
||||
ORDER BY created DESC
|
||||
LIMIT %s
|
||||
""",(numnew,))
|
||||
newest_routers = mysql.utcawaretuple(newest_routers,"created")
|
||||
|
||||
clients = stattools.total_clients(mysql)
|
||||
router_status = stattools.router_status(mysql)
|
||||
router_models = stattools.router_models(mysql)
|
||||
router_firmwares = stattools.router_firmwares(mysql)
|
||||
hoods_sum = stattools.hoods_sum(mysql)
|
||||
mysql.close()
|
||||
|
||||
return render_template("statistics.html",
|
||||
selecthood = "All Hoods",
|
||||
stats = stats,
|
||||
clients = clients,
|
||||
router_status = router_status,
|
||||
router_models = router_models,
|
||||
router_firmwares = router_firmwares,
|
||||
hoods = hoods,
|
||||
hoods_sum = hoods_sum,
|
||||
newest_routers = newest_routers
|
||||
)
|
||||
return helper_statistics(mysql,stats,None)
|
||||
|
||||
@app.route('/hoodstatistics/<selecthood>')
|
||||
def global_hoodstatistics(selecthood):
|
||||
mysql = FreifunkMySQL()
|
||||
stats = mysql.fetchall("SELECT * FROM stats_hood WHERE hood = %s",(selecthood,))
|
||||
return helper_statistics(mysql,stats,selecthood)
|
||||
|
||||
def helper_statistics(mysql,stats,selecthood):
|
||||
hoods = stattools.hoods(mysql)
|
||||
|
||||
stats = mysql.fetchall("SELECT * FROM stats_hood WHERE hood = %s",(selecthood,))
|
||||
stats = mysql.utcawaretupleint(stats,"time")
|
||||
|
||||
numnew = len(hoods)-18
|
||||
if numnew < 1:
|
||||
numnew = 1
|
||||
|
||||
if selecthood:
|
||||
where = " AND hood = %s"
|
||||
tup = (selecthood,numnew,)
|
||||
else:
|
||||
where = ""
|
||||
tup = (numnew,)
|
||||
|
||||
newest_routers = mysql.fetchall("""
|
||||
SELECT id, hostname, hood, created
|
||||
FROM router
|
||||
WHERE hardware <> 'Legacy' AND hood = %s
|
||||
WHERE hardware <> 'Legacy' {}
|
||||
ORDER BY created DESC
|
||||
LIMIT %s
|
||||
""",(selecthood,numnew,))
|
||||
""".format(where),tup)
|
||||
newest_routers = mysql.utcawaretuple(newest_routers,"created")
|
||||
|
||||
clients = stattools.total_clients(mysql)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "bootstrap.html" %}
|
||||
{% block title %}{{super()}} :: Statistics for {{ selecthood }}{% endblock %}
|
||||
{% block title %}{{super()}} :: Statistics{%- if selecthood %} for {{ selecthood }}{%- endif -%}{% endblock %}
|
||||
{% block head %}{{super()}}
|
||||
<script src="{{ url_for('static', filename='js/graph/date.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/graph/jquery.flot.js') }}"></script>
|
||||
|
@ -87,7 +87,7 @@
|
|||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Routers @ {{ selecthood }}</div>
|
||||
<div class="panel-heading">Routers{%- if selecthood %} @ {{ selecthood }}{%- endif -%}</div>
|
||||
<div class="panel-body">
|
||||
<div id="globrouterstat" class="graph"></div>
|
||||
</div>
|
||||
|
@ -95,7 +95,7 @@
|
|||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Clients @ {{ selecthood }}</div>
|
||||
<div class="panel-heading">Clients{%- if selecthood %} @ {{ selecthood }}{%- endif -%}</div>
|
||||
<div class="panel-body">
|
||||
<div id="globclientstat" class="graph"></div>
|
||||
</div>
|
||||
|
@ -103,7 +103,7 @@
|
|||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Newest Routers @ {{ selecthood }}</div>
|
||||
<div class="panel-heading">Newest Routers{%- if selecthood %} @ {{ selecthood }}{%- endif -%}</div>
|
||||
<div class="panel-body" style="padding-bottom:34px">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-condensed">
|
||||
|
@ -128,7 +128,7 @@
|
|||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Router Firmwares @ {{ selecthood }}</div>
|
||||
<div class="panel-heading">Router Firmwares{%- if selecthood %} @ {{ selecthood }}{%- endif -%}</div>
|
||||
<div class="panel-body">
|
||||
<div id="globrouterfwstat" class="graph-pie"></div>
|
||||
</div>
|
||||
|
@ -136,7 +136,7 @@
|
|||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Router Models @ {{ selecthood }}</div>
|
||||
<div class="panel-heading">Router Models{%- if selecthood %} @ {{ selecthood }}{%- endif -%}</div>
|
||||
<div class="panel-body">
|
||||
<div id="globroutermodelsstat" class="graph-pie"></div>
|
||||
</div>
|
||||
|
@ -148,11 +148,12 @@
|
|||
var router_firmwares = {{ router_firmwares|tojson }};
|
||||
var router_models = {{ router_models|tojson }};
|
||||
var routers_page_url = "{{ url_for('router_list') }}";
|
||||
{%- if selecthood %}
|
||||
var hood = "{{selecthood}}";
|
||||
var hoodstr = "hood:^" + hood.replace(/ /g, '_') + "$";
|
||||
{%- else %}
|
||||
var hoodstr = "";
|
||||
if (hood != "All Hoods") {
|
||||
hoodstr = "hood:^" + hood.replace(/ /g, '_') + "$";
|
||||
}
|
||||
{%- endif -%}
|
||||
$(document).ready(function() {
|
||||
global_client_graph();
|
||||
global_router_graph();
|
||||
|
|
Loading…
Reference in New Issue