Commit 35eb131f authored by Runar Borge's avatar Runar Borge
Browse files

fix #15 implement dynamic capacity to text

This commit implements a new capasity to human readable string function
that supports all kinds of speeds ranging from 1k to 1000Exabit++
parent 8dfafc58
......@@ -58,22 +58,28 @@ def edge_labels(edges, edgegroups=[], suppress_default=True):
def cap2str(capacity):
"""Capacity to Human Readable string convertion
Converts the given Capacity in Kbit to human readable representation,
It will return a one digit decimal precition and omitts the decimal
if its zero
"""
if capacity < 1000:
s, i = "K", float(capacity)
elif capacity < 1000000:
s, i = "M", round(float(capacity)/1000.0, 1)
elif capacity < 1000000000:
s, i = "G", round(float(capacity)/1000000.0, 1)
elif capacity < 1000000000000:
s, i = "T", round(float(capacity)/1000000000.0,1)
else:
s, i = "E", round(float(capacity)/1000000000000.0,1)
mapping = { 1984 : '2Mbit/s',
34000 : '34Mbit/s',
34010 : '34Mbit/s',
100000 : '100Mbit/s',
155000 : '155Mbit/s',
1000000 : '1Gbit/s',
2488000 : '2.5Gbit/s',
10000000 : '10Gbit/s',
100000000 : '100Gbit/s'
}
if type(capacity) != type(int):
capacity = int(capacity)
if not capacity in mapping: return "Unkown"
return mapping[capacity]
if i % 1 == 0:
return "{:0.0f}{}bit/s".format(i, s)
else:
return "{:0.1f}{}bit/s".format(i, s)
def read_linkloads(G, host, url):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment