From 523384d64c15e8096562d7f5705ae7e4c33f9070 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Thu, 7 Jun 2012 22:21:50 +0200 Subject: [PATCH] remove group foo and replace it with flags --- aliases.json_sample | 3 +-- d3mapbuilder.py | 7 ++++--- geomapbuilder.py | 2 +- html/force-big.css | 6 +++--- html/force-light.css | 6 +++--- html/force.js | 27 ++++++++++++++++----------- node.py | 13 ++++++------- nodedb.py | 15 +++++++-------- 8 files changed, 41 insertions(+), 38 deletions(-) diff --git a/aliases.json_sample b/aliases.json_sample index 0cadfc3..d779767 100644 --- a/aliases.json_sample +++ b/aliases.json_sample @@ -3,7 +3,6 @@ "name" : "Meute-AP" }, "8e:3d:c2:10:10:28" : { - "name" : "holstentor", - "group" : 2 + "name" : "holstentor" } } diff --git a/d3mapbuilder.py b/d3mapbuilder.py index fe354b4..3993710 100644 --- a/d3mapbuilder.py +++ b/d3mapbuilder.py @@ -9,10 +9,11 @@ class D3MapBuilder: nodes = self._db.get_nodes() - output['nodes'] = [{'group': x.group, 'name': x.name, 'id': x.id, + output['nodes'] = [{'name': x.name, 'id': x.id, 'macs': ', '.join(x.macs), - 'geo': x.gps.split(" ") if x.gps else None - } for x in nodes if x.online] + 'geo': x.gps.split(" ") if x.gps else None, + 'flags': x.flags + } for x in nodes if x.flags['online']] output['links'] = [{'source': x.pair[0], 'target': x.pair[1], 'distance': x.distance, 'strength': x.strength, diff --git a/geomapbuilder.py b/geomapbuilder.py index 5ac8fea..0d5a085 100644 --- a/geomapbuilder.py +++ b/geomapbuilder.py @@ -85,7 +85,7 @@ class GeoNode: raise name = self._node.name - status = "up" if self._node.online else "down" + status = "up" if self._node.flags['online'] else "down" gps = gps_format(self._node.gps) text = " ".join(self._node.macs) diff --git a/html/force-big.css b/html/force-big.css index bdd365f..a555f35 100644 --- a/html/force-big.css +++ b/html/force-big.css @@ -17,16 +17,16 @@ stroke-width: 5px !important; } -.node ellipse.group-0 { +.node ellipse { fill: #fff; stroke: #04f; } -.node ellipse.group-2 { +.node ellipse.gateway { stroke: #FF7F0E; } -.node ellipse.group-3 { +.node ellipse.client { stroke: #ff0; fill: #ff0; stroke-width: 5px; diff --git a/html/force-light.css b/html/force-light.css index 9063816..540b7a2 100644 --- a/html/force-light.css +++ b/html/force-light.css @@ -17,15 +17,15 @@ stroke-opacity: 1; } -.node ellipse.group-0 { +.node ellipse { stroke: #AEC7E8; } -.node ellipse.group-2 { +.node ellipse.gateway { stroke: #FF7F0E; } -.node ellipse.group-3 { +.node ellipse.client { stroke: #1F77B4; fill: #1F77B4; } diff --git a/html/force.js b/html/force.js index 21a5f0c..8d67a65 100644 --- a/html/force.js +++ b/html/force.js @@ -251,12 +251,12 @@ function reload() { json.links.forEach(function(d) { var node, other - if (d.source.group == 2) { + if (d.source.flags.vpn) { node = d.target; other = d.source; } - if (d.target.group == 2) { + if (d.target.flags.vpn) { node = d.source; other = d.target; } @@ -280,10 +280,10 @@ function reload() { function update() { var links = data.links .filter(function (d) { - if (!visible.clients && (d.source.group == 3 || d.target.group == 3)) + if (!visible.clients && (d.source.flags.client || d.target.flags.client)) return false - if (!visible.vpn && (d.source.group == 2 || d.target.group == 2)) + if (!visible.vpn && (d.source.flags.vpn || d.target.flags.vpn)) return false return true @@ -324,13 +324,13 @@ function update() { link.exit().remove() var nodes = data.nodes.filter(function (d) { - if (!visible.vpn && d.group == 2) + if (!visible.vpn && d.flags.vpn) return false - if (!visible.vpn && d.group == 3 && d.uplinks) + if (!visible.vpn && d.flags.client && d.uplinks) return false - if (!visible.clients && d.group == 3) + if (!visible.clients && d.flags.client) return false return true @@ -353,21 +353,26 @@ function update() { nodeEnter.append("ellipse") .attr("class", function(d) { - return "group-" + d.group + var s = [] + for (var key in d.flags) + if (d.flags.hasOwnProperty(key) && d.flags[key]) + s.push(key) + + return s.join(" ") }) node.selectAll("ellipse") .attr("rx", function(d) { - if (d.group == 3) return 4 + if (d.flags.client) return 4 else return Math.max(10, d.name.length * 5) }) .attr("ry", function(d) { - if (d.group == 3) return 4 + if (d.flags.client) return 4 else return 10 }) nodeEnter.filter(function(d) { - return d.group != 3 + return !d.flags.client }) .append("text") .attr("class", "name") diff --git a/node.py b/node.py index 57c7f88..7ff03bb 100644 --- a/node.py +++ b/node.py @@ -3,14 +3,13 @@ class Node(): self.name = "" self.id = "" self.macs = set() - self.group = 0 - self.online = False + self.flags = dict({ + "online": False, + "vpn": False, + "gateway": False, + "client": False + }) self.gps = None - # groups: - # 0 normal node - # 1 aftermath - # 2 gateways - # 3 TT def add_mac(self, mac): mac = mac.lower() diff --git a/nodedb.py b/nodedb.py index a37fe5f..7ae8f7b 100644 --- a/nodedb.py +++ b/nodedb.py @@ -47,7 +47,7 @@ class NodeDB: node = self.maybe_node_by_mac((x['of'], x['secondary'])) except: node = Node() - node.online = True + node.flags['online'] = True self._nodes.append(node) node.add_mac(x['of']) @@ -61,7 +61,7 @@ class NodeDB: node = self.maybe_node_by_mac((x['router'], )) except: node = Node() - node.online = True + node.flags['online'] = True node.add_mac(x['router']) self._nodes.append(node) @@ -97,9 +97,9 @@ class NodeDB: node = self.maybe_node_by_mac((x['neighbor'], )) except: node = Node() - node.online = True + node.flags['online'] = True if x['label'] == 'TT': - node.group = 3 + node.flags['client'] = True node.add_mac(x['neighbor']) self._nodes.append(node) @@ -142,8 +142,6 @@ class NodeDB: continue node.name = alias['name'] - if 'group' in alias: - node.group = alias['group'] # list of macs # if options['gateway']: @@ -155,12 +153,13 @@ class NodeDB: except: continue - node.group = 2 + node.flags['gateway'] = True + node.flags['vpn'] = True def map_link(self, pair): distance = 80 strength = 0.2 - if any(filter(lambda x: self._nodes[x].group == 3, pair[0])): + if any(filter(lambda x: self._nodes[x].flags['client'], pair[0])): distance = 10 strength = 1