router.html: Don't load full neighbor stats, but only on demand
With this patch, only the neighbor stats for the last day are loaded by default. If you want more, a hyperlink is implemented for this purpose. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
c77efa2502
commit
62f3b1bb45
|
@ -19,6 +19,22 @@ import time
|
|||
|
||||
api = Blueprint("api", __name__)
|
||||
|
||||
# Load router neighbor statistics
|
||||
@api.route('/load_neighbor_stats/<dbid>')
|
||||
def load_neighbor_stats(dbid):
|
||||
mysql = FreifunkMySQL()
|
||||
neighfetch = mysql.fetchall("""
|
||||
SELECT quality, mac, time FROM router_stats_neighbor WHERE router = %s
|
||||
""",(dbid,))
|
||||
mysql.close()
|
||||
|
||||
for ns in neighfetch:
|
||||
ns["time"] = {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)}
|
||||
|
||||
r = make_response(json.dumps(neighfetch))
|
||||
r.mimetype = 'application/json'
|
||||
return r
|
||||
|
||||
# map ajax
|
||||
@api.route('/get_nearest_router')
|
||||
def get_nearest_router():
|
||||
|
|
|
@ -276,9 +276,10 @@ def router_info(dbid):
|
|||
writelog(CONFIG["debug_dir"] + "/routerperf.txt", "%s - %s - %.3f" % (router["hostname"],"statsnetif",time.time() - start_time))
|
||||
|
||||
start_time = time.time()
|
||||
threshold_neighstats = (utcnow() - datetime.timedelta(hours=24)).timestamp()
|
||||
neighfetch = mysql.fetchall("""
|
||||
SELECT quality, mac, time FROM router_stats_neighbor WHERE router = %s
|
||||
""",(dbid,))
|
||||
SELECT quality, mac, time FROM router_stats_neighbor WHERE router = %s AND time > %s
|
||||
""",(dbid,threshold_neighstats,))
|
||||
|
||||
for ns in neighfetch:
|
||||
ns["time"] = mysql.utcawareint(ns["time"])
|
||||
|
|
|
@ -84,6 +84,7 @@
|
|||
<script type="text/javascript">
|
||||
var url_get_nearest_router = "{{ url_for('api.get_nearest_router') }}";
|
||||
var url_router_info = "{{ url_for('router_info', dbid='') }}";
|
||||
var url_load_neigh_stats = "{{ url_for('api.load_neighbor_stats', dbid='%s' % router.id) }}";
|
||||
var tileurls = {{ tileurls|tojson|safe }};
|
||||
</script>
|
||||
<script src="{{ url_for('static', filename='js/map.js') }}"></script>
|
||||
|
@ -224,7 +225,7 @@
|
|||
{%- if router.neighbours|length > 0 %}
|
||||
<div class="col-xs-12 col-md-6" style="display: flex; flex-flow: column;">
|
||||
<div class="panel panel-default" style="flex: 1 1 auto;">
|
||||
<div class="panel-heading">Neighbours</div>
|
||||
<div class="panel-heading">Neighbours <span id="loadneighstats">(<a href="#" onclick="load_neigh_stats();return false;">Load full stats</a>)</span></div>
|
||||
<div class="panel-body" style="height: 100%;">
|
||||
<div class="table-responsive">
|
||||
<table class="neighbours" style="width: 100%; margin-bottom: 6px;">
|
||||
|
@ -450,6 +451,17 @@
|
|||
});
|
||||
network_graph("br-mesh");
|
||||
});
|
||||
{%- if router.neighbours|length > 0 %}
|
||||
function load_neigh_stats() {
|
||||
$("#loadneighstats").hide();
|
||||
var starttimeneigh = performance.now();
|
||||
ajax_get_request(url_load_neigh_stats, function(neighstats) {
|
||||
neigh_stats = neighstats;
|
||||
neighbour_graph(neighbours);
|
||||
console.debug("Loaded full neighbor stats in "+((performance.now() - starttimeneigh)/1000).toFixed(3)+" seconds.");
|
||||
});
|
||||
}
|
||||
{%- endif %}
|
||||
</script>
|
||||
|
||||
{%- if session.admin %}
|
||||
|
|
Loading…
Reference in New Issue