Module: check_mk
Branch: master
Commit: 62eac04e551c7d908c2fb58aca753929924be1a1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=62eac04e551c7d…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Mar 24 14:29:42 2015 +0100
New function logb and frexpb in lib
---
web/htdocs/lib.py | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index cbb16e0..14ddbd8 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -474,14 +474,29 @@ def num_split(s):
first_word = regex("[0-9]").split(s)[0]
return ( first_word.lower(), ) + num_split(s[len(first_word):])
-def frexp10(x):
- exp = int(math.log10(x))
- mantissa = x / 10**exp
+ # exp = int(math.log10(x))
+ # mantissa = x / 10**exp
+ # if mantissa < 1:
+ # mantissa *= 10
+ # exp -= 1
+ # return mantissa, exp
+
+def logb(x, base):
+ return math.log(x) / math.log(base)
+
+def frexpb(x, base):
+ exp = int(logb(x, base))
+ mantissa = x / base**exp
if mantissa < 1:
- mantissa *= 10
+ mantissa *= base
exp -= 1
return mantissa, exp
+def frexp10(x):
+ return frexpb(x, 10)
+
+
+
# Render a physical value witha precision of p
# digits. Use K (kilo), M (mega), m (milli), µ (micro)
@@ -582,8 +597,12 @@ def age_human_readable(secs, min_only=False):
hours = mins / 60
if hours < 48:
return "%d %s" % (hours, _("hours"))
- days = hours / 24
- return "%d %s" % (days, _("days"))
+ days = hours / 24.0
+ if days < 6:
+ d = ("%.1f" % days).rstrip("0").rstrip(".")
+ return "%s %s" % (d, _("days"))
+ else:
+ return "%.0f %s" % (days, _("days"))
def bytes_human_readable(b, base=1024.0, bytefrac=True, unit="B"):