diff options
author | EUcancER <root@euer.krebsco.de> | 2011-10-27 15:33:25 +0200 |
---|---|---|
committer | EUcancER <root@euer.krebsco.de> | 2011-10-27 15:33:25 +0200 |
commit | cf61e00b669842700f7031f1f46add3eecb936f9 (patch) | |
tree | 514bcd00cb3eb2f6c54e2e81f65ba477fb18b6ef | |
parent | 208c4e50751d3fef90b52628302548299674774e (diff) |
//retiolum/adv_graphgen: add avg weight to nodes
-rwxr-xr-x | retiolum/scripts/adv_graphgen/parse.py | 13 |
1 files changed, 11 insertions, 2 deletions
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" |