mirror of
https://github.com/cwinfo/yggdrasil-map
synced 2024-11-09 16:00:27 +00:00
size nodes by their betweenness, use nodedb for giving hosts names
This commit is contained in:
parent
e0f1c67c1b
commit
f4fc407f8e
@ -16,6 +16,7 @@ chmod +x sendGraph.py
|
||||
## Web server
|
||||
```bash
|
||||
git clone git@github.com:zielmicha/fc00.org.git
|
||||
git clone git@github.com:zielmicha/nodedb.git web/nodedb
|
||||
sudo apt-get install python-flask python-flup python-mysqldb python-pygraphviz
|
||||
|
||||
cd fc00.org/web
|
||||
|
@ -1,7 +1,10 @@
|
||||
import pygraphviz as pgv
|
||||
import time
|
||||
import json
|
||||
|
||||
import collections
|
||||
import math
|
||||
import networkx as nx
|
||||
from networkx.algorithms import centrality
|
||||
|
||||
def position_nodes(nodes, edges):
|
||||
G = pgv.AGraph(strict=True, directed=False, size='10!')
|
||||
@ -16,6 +19,26 @@ def position_nodes(nodes, edges):
|
||||
|
||||
return G
|
||||
|
||||
def compute_betweenness(G):
|
||||
ng = nx.Graph()
|
||||
for start in G.iternodes():
|
||||
others = G.neighbors(start)
|
||||
for other in others:
|
||||
ng.add_edge(start, other)
|
||||
|
||||
c = centrality.betweenness_centrality(ng)
|
||||
|
||||
for k, v in c.items():
|
||||
c[k] = v
|
||||
|
||||
return c
|
||||
|
||||
def canonalize_ip(ip):
|
||||
return ':'.join( i.rjust(4, '0') for i in ip.split(':') )
|
||||
|
||||
def load_db():
|
||||
with open('nodedb/nodes') as f:
|
||||
return dict([ (canonalize_ip(v[0]), v[1]) for v in [ l.split(None)[:2] for l in f.readlines() ] if len(v) > 1 ])
|
||||
|
||||
def get_graph_json(G):
|
||||
max_neighbors = 1
|
||||
@ -31,18 +54,27 @@ def get_graph_json(G):
|
||||
'edges': []
|
||||
}
|
||||
|
||||
centralities = compute_betweenness(G)
|
||||
db = load_db()
|
||||
|
||||
for n in G.iternodes():
|
||||
neighbor_ratio = len(G.neighbors(n)) / float(max_neighbors)
|
||||
pos = n.attr['pos'].split(',', 1)
|
||||
centrality = centralities.get(n.name, 0)
|
||||
pcentrality = (centrality + 0.0001) * 500
|
||||
size = (pcentrality ** 0.3 / 500) * 1000 + 1
|
||||
name = db.get(n.name)
|
||||
|
||||
out_data['nodes'].append({
|
||||
'id': n.name,
|
||||
'label': n.attr['label'],
|
||||
'label': name if name else n.attr['label'],
|
||||
'name': name,
|
||||
'version': n.attr['version'],
|
||||
'x': float(pos[0]),
|
||||
'y': float(pos[1]),
|
||||
'color': _gradient_color(neighbor_ratio, [(100, 100, 100), (0, 0, 0)]),
|
||||
'size': neighbor_ratio
|
||||
'size': size,
|
||||
'centrality': '%.4f' % centrality
|
||||
})
|
||||
|
||||
for e in G.iteredges():
|
||||
|
@ -175,7 +175,8 @@ function showNodeInfo(node) {
|
||||
'<span class="tt">' + node.id + '</span><br>' +
|
||||
'<br>' +
|
||||
'<strong>Version:</strong> ' + node.version + '<br>' +
|
||||
'<strong>Peers:</strong> ' + node.peers.length + '<br>' +
|
||||
'<strong>Peers:</strong> ' + node.peers.length + '<br>' +
|
||||
'<strong>Centrality:</strong> ' + node.centrality + '<br>' +
|
||||
'<table>' +
|
||||
// '<tr><td></td><td><strong>Their peers #</strong></td></tr>' +
|
||||
peers.map(function (n) {
|
||||
@ -210,7 +211,7 @@ $(document).ready(function() {
|
||||
var node = nodes[i];
|
||||
node.x = node.x * 1.2;
|
||||
node.y = node.y * 1.2;
|
||||
node.radius = 4 + node.size * 10;
|
||||
node.radius = node.size;
|
||||
node.hover = false;
|
||||
node.selected = false;
|
||||
node.edges = [];
|
||||
@ -399,7 +400,7 @@ $(document).ready(function() {
|
||||
// node.x *= ratio;
|
||||
// node.y *= ratio;
|
||||
// node.radius *= ratio;
|
||||
node.radius = (4 + node.size * 8) * zoom;
|
||||
node.radius = (node.size) * zoom;
|
||||
}
|
||||
|
||||
drawNetwork();
|
||||
|
Loading…
Reference in New Issue
Block a user