summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-12-11 12:25:42 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2019-12-11 12:25:42 +0100
commite3d1b44aeaa2f274676ea21367a830838a063142 (patch)
treec5710b4f87b2a8e27900ec10724a665c44df60ff /lib
parent2f134105ee9ae414ac99bc69365658da7d4d8643 (diff)
oops
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py
index 2e635a7..a582d6b 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -14,6 +14,13 @@ def vprint(verbose, string):
print(string)
+def human_readable(value, unit):
+ for prefix, factor in (('p', 1e-12), ('n', 1e-9), (u'ยต', 1e-6), ('m', 1e-3), ('', 1), ('k', 1e3)):
+ if value < 1e3 * factor:
+ return '{:.2f} {}{}'.format(value * (1 / factor), prefix, unit)
+ return '{:.2f} {}'.format(value, unit)
+
+
def is_numeric(n):
"""Check if `n` is numeric (i.e., it can be converted to float)."""
if n is None: