From cf61e00b669842700f7031f1f46add3eecb936f9 Mon Sep 17 00:00:00 2001 From: EUcancER Date: Thu, 27 Oct 2011 15:33:25 +0200 Subject: //retiolum/adv_graphgen: add avg weight to nodes --- retiolum/scripts/adv_graphgen/parse.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'retiolum') diff --git a/retiolum/scripts/adv_graphgen/parse.py b/retiolum/scripts/adv_graphgen/parse.py index 0e878bd8..e99a5573 100755 --- a/retiolum/scripts/adv_graphgen/parse.py +++ b/retiolum/scripts/adv_graphgen/parse.py @@ -55,10 +55,18 @@ def generate_stats(nodes): jlines.append(json.loads(line)) f.close() for k,v in nodes.iteritems(): - v['num_conns'] = len(v.get('to',[])) + conns = v.get('to',[]) + v['num_conns'] = len(conns) + v['avg_weight'] = get_node_avg_weight(conns) v['availability'] = get_node_availability(k,jlines) sys.stderr.write( "%s -> %f\n" %(k ,v['availability'])) - +def get_node_avg_weight(conns): + """ calculates the average weight for the given connections """ + if not conns: + sys.syderr.write("get_node_avg_weight: connection parameter empty") + return 9001 + else: + return sum([float(c['weight']) for c in conns])/len(conns) def get_node_availability(name,jlines): """ calculates the node availability by reading the generated dump file adding together the uptime of the node and returning the time @@ -116,6 +124,7 @@ def write_node(k,v): node = " "+k+"[label=\"" node += k+"\\l" node += "availability: %f\\l" % v['availability'] + node += "avg weight: %.2f\\l" % v['avg_weight'] if v.has_key('num_conns'): node += "Num Connects:"+str(v['num_conns'])+"\\l" node += "external:"+v['external-ip']+":"+v['external-port']+"\\l" -- cgit v1.2.3