router.html/map: Treat quality differently based on routing protocol
Adds display support for BATMAN_V data. This is step 1 of 2. It does change the background colors for neighbors, but does NOT change the link colors in the map. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
f6f699c8c7
commit
c208663f70
|
@ -15,3 +15,36 @@ def writelog(path, content):
|
|||
def writefulllog(content):
|
||||
with open(CONFIG["debug_dir"] + "/fulllog.log", "a") as csv:
|
||||
csv.write(time.strftime('{%Y-%m-%d %H:%M:%S}') + " - " + content + "\n")
|
||||
|
||||
def neighbor_color(quality,rt_protocol):
|
||||
if rt_protocol=="BATMAN_V":
|
||||
color = "#04ff0a"
|
||||
if quality < 0:
|
||||
color = "#06a4f4"
|
||||
elif quality < 10:
|
||||
color = "#ff1e1e"
|
||||
elif quality < 20:
|
||||
color = "#ff4949"
|
||||
elif quality < 40:
|
||||
color = "#ff6a6a"
|
||||
elif quality < 80:
|
||||
color = "#ffac53"
|
||||
elif quality < 1000:
|
||||
color = "#ffeb79"
|
||||
else:
|
||||
color = "#04ff0a"
|
||||
if quality < 0:
|
||||
color = "#06a4f4"
|
||||
elif quality < 105:
|
||||
color = "#ff1e1e"
|
||||
elif quality < 130:
|
||||
color = "#ff4949"
|
||||
elif quality < 155:
|
||||
color = "#ff6a6a"
|
||||
elif quality < 180:
|
||||
color = "#ffac53"
|
||||
elif quality < 205:
|
||||
color = "#ffeb79"
|
||||
elif quality < 230:
|
||||
color = "#79ff7c"
|
||||
return color
|
||||
|
|
|
@ -6,7 +6,7 @@ from ffmap.maptools import *
|
|||
from ffmap.mysqltools import FreifunkMySQL
|
||||
from ffmap.stattools import record_global_stats, record_hood_stats
|
||||
from ffmap.config import CONFIG
|
||||
from ffmap.misc import writelog, writefulllog
|
||||
from ffmap.misc import writelog, writefulllog, neighbor_color
|
||||
|
||||
from flask import Blueprint, request, make_response, redirect, url_for, jsonify, Response
|
||||
from bson.json_util import dumps as bson2json
|
||||
|
@ -37,8 +37,8 @@ def get_nearest_router():
|
|||
where = " AND h.id IS NULL "
|
||||
|
||||
mysql = FreifunkMySQL()
|
||||
res_router = mysql.findone("""
|
||||
SELECT r.id, r.hostname, r.lat, r.lng, r.description,
|
||||
router = mysql.findone("""
|
||||
SELECT r.id, r.hostname, r.lat, r.lng, r.description, r.routing_protocol,
|
||||
( acos( cos( radians(%s) )
|
||||
* cos( radians( r.lat ) )
|
||||
* cos( radians( r.lng ) - radians(%s) )
|
||||
|
@ -54,17 +54,19 @@ def get_nearest_router():
|
|||
LIMIT 1
|
||||
""",(lat,lng,lat,))
|
||||
|
||||
res_router["neighbours"] = mysql.fetchall("""
|
||||
router["neighbours"] = mysql.fetchall("""
|
||||
SELECT nb.mac, nb.netif, nb.quality, r.hostname, r.id
|
||||
FROM router_neighbor AS nb
|
||||
INNER JOIN (
|
||||
SELECT router, mac FROM router_netif GROUP BY mac, router
|
||||
) AS net ON nb.mac = net.mac
|
||||
INNER JOIN router as r ON net.router = r.id
|
||||
WHERE nb.router = %s""",(res_router["id"],))
|
||||
WHERE nb.router = %s""",(router["id"],))
|
||||
mysql.close()
|
||||
for n in router["neighbours"]:
|
||||
n["color"] = neighbor_color(n["quality"],router["routing_protocol"])
|
||||
|
||||
r = make_response(bson2json(res_router))
|
||||
r = make_response(bson2json(router))
|
||||
r.mimetype = 'application/json'
|
||||
return r
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from ffmap.routertools import delete_router, ban_router
|
|||
from ffmap.gwtools import gw_name, gw_bat
|
||||
from ffmap.web.helpers import *
|
||||
from ffmap.config import CONFIG
|
||||
from ffmap.misc import writelog, writefulllog
|
||||
from ffmap.misc import writelog, writefulllog, neighbor_color
|
||||
|
||||
from flask import Flask, render_template, request, Response, redirect, url_for, flash, session
|
||||
import bson
|
||||
|
@ -223,6 +223,10 @@ def router_info(dbid):
|
|||
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"])
|
||||
|
|
|
@ -15,25 +15,6 @@ from ffmap.misc import *
|
|||
|
||||
filters = Blueprint("filters", __name__)
|
||||
|
||||
@filters.app_template_filter('neighbour_color')
|
||||
def neighbour_color(quality):
|
||||
color = "#04ff0a"
|
||||
if quality < 0:
|
||||
color = "#06a4f4"
|
||||
elif quality < 105:
|
||||
color = "#ff1e1e"
|
||||
elif quality < 130:
|
||||
color = "#ff4949"
|
||||
elif quality < 155:
|
||||
color = "#ff6a6a"
|
||||
elif quality < 180:
|
||||
color = "#ffac53"
|
||||
elif quality < 205:
|
||||
color = "#ffeb79"
|
||||
elif quality < 230:
|
||||
color = "#79ff7c"
|
||||
return color
|
||||
|
||||
@filters.app_template_filter('sumdict')
|
||||
def sumdict(d):
|
||||
return sum(d.values())
|
||||
|
|
|
@ -144,15 +144,7 @@ map.on('click', function(pos) {
|
|||
neighbour = router.neighbours[i];
|
||||
// skip unknown neighbours
|
||||
if ('id' in neighbour) {
|
||||
var tr_color = "#04ff0a";
|
||||
if (neighbour.quality < 0) { tr_color = "#06a4f4"; }
|
||||
else if (neighbour.quality < 105) { tr_color = "#ff1e1e"; }
|
||||
else if (neighbour.quality < 130) { tr_color = "#ff4949"; }
|
||||
else if (neighbour.quality < 155) { tr_color = "#ff6a6a"; }
|
||||
else if (neighbour.quality < 180) { tr_color = "#ffac53"; }
|
||||
else if (neighbour.quality < 205) { tr_color = "#ffeb79"; }
|
||||
else if (neighbour.quality < 230) { tr_color = "#79ff7c"; }
|
||||
popup_html += "<tr style=\"background-color: "+tr_color+";\">";
|
||||
popup_html += "<tr style=\"background-color: "+neighbour.color+";\">";
|
||||
popup_html += '<td><a href="'+url_router_info+neighbour.id+'" title="'+escapeHTML(neighbour.mac)+'">'+escapeHTML(neighbour.hostname)+'</a></td>';
|
||||
popup_html += "<td>"+neighbour.quality+"</td>";
|
||||
popup_html += "<td>"+escapeHTML(neighbour.netif)+"</td>";
|
||||
|
|
|
@ -233,7 +233,7 @@
|
|||
<th>Interface</th>
|
||||
</tr>
|
||||
{%- for neighbour in router.neighbours %}
|
||||
<tr style="background-color: {{ neighbour.quality|neighbour_color }};">
|
||||
<tr style="background-color: {{ neighbour.color }};">
|
||||
|
||||
<td>{%- if neighbour.hostname -%}<a href="{{ url_for('router_info', dbid=neighbour.id) }}">{{ neighbour.hostname }}</a>{%- else -%}---{%- endif -%}</td>
|
||||
<td>{{ neighbour.mac }}</td>
|
||||
|
|
Loading…
Reference in New Issue