From e3d1b44aeaa2f274676ea21367a830838a063142 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 11 Dec 2019 12:25:42 +0100 Subject: oops --- lib/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') 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: -- cgit v1.2.3