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): ...@@ -58,22 +58,28 @@ def edge_labels(edges, edgegroups=[], suppress_default=True):
def cap2str(capacity): def cap2str(capacity):
"""Capacity to Human Readable string convertion
mapping = { 1984 : '2Mbit/s',
34000 : '34Mbit/s', Converts the given Capacity in Kbit to human readable representation,
34010 : '34Mbit/s', It will return a one digit decimal precition and omitts the decimal
100000 : '100Mbit/s', if its zero
155000 : '155Mbit/s', """
1000000 : '1Gbit/s', if capacity < 1000:
2488000 : '2.5Gbit/s', s, i = "K", float(capacity)
10000000 : '10Gbit/s', elif capacity < 1000000:
100000000 : '100Gbit/s' s, i = "M", round(float(capacity)/1000.0, 1)
} elif capacity < 1000000000:
s, i = "G", round(float(capacity)/1000000.0, 1)
if type(capacity) != type(int): elif capacity < 1000000000000:
capacity = int(capacity) s, i = "T", round(float(capacity)/1000000000.0,1)
if not capacity in mapping: return "Unkown" else:
return mapping[capacity] s, i = "E", round(float(capacity)/1000000000000.0,1)
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): 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