Format time velues in graph descriptions
This commit is contained in:
parent
9a84e191be
commit
e921031e64
36
dashboard.py
36
dashboard.py
|
@ -391,7 +391,10 @@ class TimeSeries(Widget):
|
||||||
if self.yscale == "log":
|
if self.yscale == "log":
|
||||||
try:
|
try:
|
||||||
min_value = min(d[1] for d in self.lts.data if d[1] > 0)
|
min_value = min(d[1] for d in self.lts.data if d[1] > 0)
|
||||||
self.extra["min"] = "%g" % min_value
|
if unit == "s":
|
||||||
|
self.extra["min"] = "%g" % min_value + " (" + self.format_time(min_value) + ")"
|
||||||
|
else:
|
||||||
|
self.extra["min"] = "%g" % min_value
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# no non-negative values
|
# no non-negative values
|
||||||
min_value = max_value / 2
|
min_value = max_value / 2
|
||||||
|
@ -405,8 +408,12 @@ class TimeSeries(Widget):
|
||||||
# Make sure min_value is less than max_value
|
# Make sure min_value is less than max_value
|
||||||
min_value /= 2
|
min_value /= 2
|
||||||
log.debug("min_value = %s, max_value = %s", min_value, max_value)
|
log.debug("min_value = %s, max_value = %s", min_value, max_value)
|
||||||
self.extra["max"] = "%g" % max_value
|
if unit == "s":
|
||||||
self.extra["last"] = "%g" % data[-1][1]
|
self.extra["max"] = "%g" % max_value + " (" + self.format_time(max_value) + ")"
|
||||||
|
self.extra["last"] = "%g" % data[-1][1] + " (" + self.format_time(data[-1][1]) + ")"
|
||||||
|
else:
|
||||||
|
self.extra["max"] = "%g" % max_value
|
||||||
|
self.extra["last"] = "%g" % data[-1][1]
|
||||||
log.debug("collecting data")
|
log.debug("collecting data")
|
||||||
v_data = []
|
v_data = []
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
|
@ -460,6 +467,28 @@ class TimeSeries(Widget):
|
||||||
log.debug("in as_html")
|
log.debug("in as_html")
|
||||||
return Markup(render_template("timeseries.html", widget=self))
|
return Markup(render_template("timeseries.html", widget=self))
|
||||||
|
|
||||||
|
def format_time(seconds):
|
||||||
|
unit = "s"
|
||||||
|
if value >= 365.25 * 86400:
|
||||||
|
value /= 365.25 * 86400
|
||||||
|
unit = "years"
|
||||||
|
elif value >= 86400:
|
||||||
|
value /= 86400
|
||||||
|
unit = "days"
|
||||||
|
elif value >= 3600:
|
||||||
|
value /= 3600
|
||||||
|
unit = "h"
|
||||||
|
elif value >= 60:
|
||||||
|
value /= 60
|
||||||
|
unit = "m"
|
||||||
|
elif value >= 1:
|
||||||
|
pass
|
||||||
|
elif value >= 0.001:
|
||||||
|
value *= 1000
|
||||||
|
unit = "ms"
|
||||||
|
return f"{value:.2f} {unit}"
|
||||||
|
|
||||||
|
|
||||||
class Gauge(Widget):
|
class Gauge(Widget):
|
||||||
def __init__(self, d):
|
def __init__(self, d):
|
||||||
super().__init__(d)
|
super().__init__(d)
|
||||||
|
@ -501,3 +530,4 @@ class Gauge(Widget):
|
||||||
self.lastvalue_formatted = Markup(f"<span class='value'>{value:.2f}</span><span class='unit'>{unit}</unit>")
|
self.lastvalue_formatted = Markup(f"<span class='value'>{value:.2f}</span><span class='unit'>{unit}</unit>")
|
||||||
return Markup(render_template("gauge.html", widget=self))
|
return Markup(render_template("gauge.html", widget=self))
|
||||||
|
|
||||||
|
# vim: sw=4
|
||||||
|
|
Loading…
Reference in New Issue