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
|
## Web server
|
||||||
```bash
|
```bash
|
||||||
git clone git@github.com:zielmicha/fc00.org.git
|
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
|
sudo apt-get install python-flask python-flup python-mysqldb python-pygraphviz
|
||||||
|
|
||||||
cd fc00.org/web
|
cd fc00.org/web
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import pygraphviz as pgv
|
import pygraphviz as pgv
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import collections
|
||||||
|
import math
|
||||||
|
import networkx as nx
|
||||||
|
from networkx.algorithms import centrality
|
||||||
|
|
||||||
def position_nodes(nodes, edges):
|
def position_nodes(nodes, edges):
|
||||||
G = pgv.AGraph(strict=True, directed=False, size='10!')
|
G = pgv.AGraph(strict=True, directed=False, size='10!')
|
||||||
@ -16,6 +19,26 @@ def position_nodes(nodes, edges):
|
|||||||
|
|
||||||
return G
|
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):
|
def get_graph_json(G):
|
||||||
max_neighbors = 1
|
max_neighbors = 1
|
||||||
@ -31,18 +54,27 @@ def get_graph_json(G):
|
|||||||
'edges': []
|
'edges': []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
centralities = compute_betweenness(G)
|
||||||
|
db = load_db()
|
||||||
|
|
||||||
for n in G.iternodes():
|
for n in G.iternodes():
|
||||||
neighbor_ratio = len(G.neighbors(n)) / float(max_neighbors)
|
neighbor_ratio = len(G.neighbors(n)) / float(max_neighbors)
|
||||||
pos = n.attr['pos'].split(',', 1)
|
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({
|
out_data['nodes'].append({
|
||||||
'id': n.name,
|
'id': n.name,
|
||||||
'label': n.attr['label'],
|
'label': name if name else n.attr['label'],
|
||||||
|
'name': name,
|
||||||
'version': n.attr['version'],
|
'version': n.attr['version'],
|
||||||
'x': float(pos[0]),
|
'x': float(pos[0]),
|
||||||
'y': float(pos[1]),
|
'y': float(pos[1]),
|
||||||
'color': _gradient_color(neighbor_ratio, [(100, 100, 100), (0, 0, 0)]),
|
'color': _gradient_color(neighbor_ratio, [(100, 100, 100), (0, 0, 0)]),
|
||||||
'size': neighbor_ratio
|
'size': size,
|
||||||
|
'centrality': '%.4f' % centrality
|
||||||
})
|
})
|
||||||
|
|
||||||
for e in G.iteredges():
|
for e in G.iteredges():
|
||||||
|
@ -175,7 +175,8 @@ function showNodeInfo(node) {
|
|||||||
'<span class="tt">' + node.id + '</span><br>' +
|
'<span class="tt">' + node.id + '</span><br>' +
|
||||||
'<br>' +
|
'<br>' +
|
||||||
'<strong>Version:</strong> ' + node.version + '<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>' +
|
'<table>' +
|
||||||
// '<tr><td></td><td><strong>Their peers #</strong></td></tr>' +
|
// '<tr><td></td><td><strong>Their peers #</strong></td></tr>' +
|
||||||
peers.map(function (n) {
|
peers.map(function (n) {
|
||||||
@ -210,7 +211,7 @@ $(document).ready(function() {
|
|||||||
var node = nodes[i];
|
var node = nodes[i];
|
||||||
node.x = node.x * 1.2;
|
node.x = node.x * 1.2;
|
||||||
node.y = node.y * 1.2;
|
node.y = node.y * 1.2;
|
||||||
node.radius = 4 + node.size * 10;
|
node.radius = node.size;
|
||||||
node.hover = false;
|
node.hover = false;
|
||||||
node.selected = false;
|
node.selected = false;
|
||||||
node.edges = [];
|
node.edges = [];
|
||||||
@ -399,7 +400,7 @@ $(document).ready(function() {
|
|||||||
// node.x *= ratio;
|
// node.x *= ratio;
|
||||||
// node.y *= ratio;
|
// node.y *= ratio;
|
||||||
// node.radius *= ratio;
|
// node.radius *= ratio;
|
||||||
node.radius = (4 + node.size * 8) * zoom;
|
node.radius = (node.size) * zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawNetwork();
|
drawNetwork();
|
||||||
@ -417,4 +418,4 @@ function nodeMouseIn(node) {
|
|||||||
function nodeMouseOut(node) {
|
function nodeMouseOut(node) {
|
||||||
node.hover = false;
|
node.hover = false;
|
||||||
$('body').css('cursor', 'auto');
|
$('body').css('cursor', 'auto');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user