diff options
author | EUcancER <root@euer.krebsco.de> | 2011-10-26 21:01:31 +0200 |
---|---|---|
committer | EUcancER <root@euer.krebsco.de> | 2011-10-26 21:01:31 +0200 |
commit | 208c4e50751d3fef90b52628302548299674774e (patch) | |
tree | 5eebdeb6cce5150fdbf03b9d565a08870f13306f /retiolum | |
parent | 88d66c8db7fcb0fa7ecb7924439ededb883b8a66 (diff) |
//retiolum/adv_graphgen: archive file parsed once, not n times
the archive file used to calculate the node availability is now parsed only once, not [num nodes] times.
this saves quite some time
Diffstat (limited to 'retiolum')
-rwxr-xr-x | retiolum/scripts/adv_graphgen/parse.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/retiolum/scripts/adv_graphgen/parse.py b/retiolum/scripts/adv_graphgen/parse.py index 715a228a..0e878bd8 100755 --- a/retiolum/scripts/adv_graphgen/parse.py +++ b/retiolum/scripts/adv_graphgen/parse.py @@ -50,25 +50,26 @@ def generate_stats(nodes): """ Generates some statistics of the network and nodes """ f = open(DUMP_FILE,'r') - flines = f.readlines() + jlines = [] + for line in f: + jlines.append(json.loads(line)) f.close() for k,v in nodes.iteritems(): v['num_conns'] = len(v.get('to',[])) - v['availability'] = get_node_availability(k,flines) + v['availability'] = get_node_availability(k,jlines) sys.stderr.write( "%s -> %f\n" %(k ,v['availability'])) -def get_node_availability(name,flines): +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 parms: name - node name - f - archival dump line array + jlines - list of already parsed dictionaries node archive """ begin = last = current = 0 uptime = 0 #sys.stderr.write ( "Getting Node availability of %s\n" % name) - for line in flines: - stat = json.loads(line) + for stat in jlines: ts = stat['timestamp'] if not begin: begin = last = ts @@ -114,7 +115,7 @@ def write_node(k,v): node = " "+k+"[label=\"" node += k+"\\l" - node += "availability: %.2f%%\\l" % (v['availability'] * 100) + node += "availability: %f\\l" % v['availability'] if v.has_key('num_conns'): node += "Num Connects:"+str(v['num_conns'])+"\\l" node += "external:"+v['external-ip']+":"+v['external-port']+"\\l" |