예제 #1
0
def generate_availability_stats(nodes):
  """ generates stats of from availability
  """
  jlines = []
  try:
    f = BackwardsReader(DUMP_FILE)
    lines_to_use = 1000
    while True:
      if lines_to_use == 0: break
      line = f.readline()
      if not line: break
      jline = json.loads(line)
      if not jline['nodes']: continue

      jlines.append(jline)
      lines_to_use -=1
  except Exception,e: sys.stderr.write(str(e))

  for k,v in nodes.iteritems():
    v['availability'] = get_node_availability(k,jlines)
    sys.stderr.write( "%s -> %f\n" %(k ,v['availability']))
예제 #2
0
파일: Graph.py 프로젝트: juliusf/painload
            if lines_to_use == 0:
                break
            line = f.readline()
            if not line:
                break
            jline = json.loads(line)
            if not jline["nodes"]:
                continue

            jlines.append(jline)
            lines_to_use -= 1
    except Exception, e:
        sys.stderr.write(str(e))

    for k, v in nodes.iteritems():
        v["availability"] = get_node_availability(k, jlines)
        sys.stderr.write("%s -> %f\n" % (k, v["availability"]))


def generate_stats(nodes):
    """ Generates some statistics of the network and nodes
  """
    for k, v in nodes.iteritems():
        conns = v.get("to", [])
        for c in conns:  # sanitize weights
            if float(c["weight"]) > 9000:
                c["weight"] = str(9001)
            elif float(c["weight"]) < 0:
                c["weight"] = str(0)
        v["num_conns"] = len(conns)
        v["avg_weight"] = get_node_avg_weight(conns)