From 54764f7f43dbdc91d44a1f88668d4d2dec258823 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Thu, 12 Apr 2018 20:49:31 +0200 Subject: [PATCH] router.html: Show former neighbors in neighbor stats plot If a router is currently not connected as neighbor, we don't see its history. This patch shows all current and former neighbors. Signed-off-by: Adrian Schmutzler --- ffmap/web/api.py | 7 ++++++- ffmap/web/application.py | 16 +++++++++------ ffmap/web/static/js/graph.js | 36 ++++++++++++++++++--------------- ffmap/web/templates/router.html | 2 +- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/ffmap/web/api.py b/ffmap/web/api.py index bcf5fe5..4b1508f 100755 --- a/ffmap/web/api.py +++ b/ffmap/web/api.py @@ -48,10 +48,15 @@ def load_neighbor_stats(dbid): """,(dbid,)) mysql.close() + neighdata = {} + for ns in neighfetch: ns["time"] = {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)} + if not ns["mac"] in neighdata: + neighdata[ns["mac"]] = [] + neighdata[ns["mac"]].append(ns) - r = make_response(json.dumps(neighfetch)) + r = make_response(json.dumps(neighdata)) r.mimetype = 'application/json' return r diff --git a/ffmap/web/application.py b/ffmap/web/application.py index 7a489b6..025134c 100755 --- a/ffmap/web/application.py +++ b/ffmap/web/application.py @@ -223,22 +223,26 @@ def router_info(dbid): desc = "Ethernet Multi-Port" n["description"] = desc n["color"] = color - + ## Set color for neighbors AFTER json if clause for n in router["neighbours"]: n["color"] = neighbor_color(n["quality"],router["routing_protocol"]) - + router["stats"] = mysql.fetchall("""SELECT * FROM router_stats WHERE router = %s""",(dbid,)) for s in router["stats"]: s["time"] = mysql.utcawareint(s["time"]) - + threshold_neighstats = (utcnow() - datetime.timedelta(hours=24)).timestamp() neighfetch = mysql.fetchall(""" SELECT quality, mac, time FROM router_stats_neighbor WHERE router = %s AND time > %s """,(dbid,threshold_neighstats,)) - + + neighdata = {} for ns in neighfetch: - ns["time"] = mysql.utcawareint(ns["time"]) + ns["time"] = {"$date": int(mysql.utcawareint(ns["time"]).timestamp()*1000)} + if not ns["mac"] in neighdata: + neighdata[ns["mac"]] = [] + neighdata[ns["mac"]].append(ns) gwfetch = mysql.fetchall(""" SELECT quality, mac, time FROM router_stats_gw WHERE router = %s @@ -319,7 +323,7 @@ def router_info(dbid): router = router, mac = mac, tileurls = tileurls, - neighstats = neighfetch, + neighstats = neighdata, gwstats = gwfetch, authuser = is_authorized(router["user"], session), authadmin = session.get('admin') diff --git a/ffmap/web/static/js/graph.js b/ffmap/web/static/js/graph.js index 4bdb1c3..e169f10 100644 --- a/ffmap/web/static/js/graph.js +++ b/ffmap/web/static/js/graph.js @@ -102,25 +102,28 @@ function network_graph(netif) { function neighbour_graph(neighbours) { var meshstat = $("#meshstat"); var pdata = []; - for (j=0; j var router_stats = {{ router.stats|statbson2json|safe }}; var netif_stats = null; - var neigh_stats = {{ neighstats|statbson2json|safe }}; + var neigh_stats = {{ neighstats|safe }}; var gw_stats = {{ gwstats|statbson2json|safe }}; var neighbours = [ {%- for neighbour in router.neighbours %}