Merge branch 'master' of git.hjp.at:hjp/ltsdb
This commit is contained in:
commit
1a798be52d
30
dashboard.py
30
dashboard.py
|
@ -395,6 +395,9 @@ class TimeSeries(Widget):
|
|||
if self.yscale == "log":
|
||||
try:
|
||||
min_value = min(d[1] for d in self.lts.data if d[1] > 0)
|
||||
if unit == "s":
|
||||
self.extra["min"] = "%g" % min_value + " (" + self.format_time(min_value) + ")"
|
||||
else:
|
||||
self.extra["min"] = "%g" % min_value
|
||||
except ValueError:
|
||||
# no non-negative values
|
||||
|
@ -409,6 +412,10 @@ class TimeSeries(Widget):
|
|||
# Make sure min_value is less than max_value
|
||||
min_value /= 2
|
||||
log.debug("min_value = %s, max_value = %s", min_value, max_value)
|
||||
if unit == "s":
|
||||
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")
|
||||
|
@ -464,6 +471,28 @@ class TimeSeries(Widget):
|
|||
log.debug("in as_html")
|
||||
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):
|
||||
def __init__(self, d):
|
||||
super().__init__(d)
|
||||
|
@ -505,3 +534,4 @@ class Gauge(Widget):
|
|||
self.lastvalue_formatted = Markup(f"<span class='value'>{value:.2f}</span><span class='unit'>{unit}</unit>")
|
||||
return Markup(render_template("gauge.html", widget=self))
|
||||
|
||||
# vim: sw=4
|
||||
|
|
Loading…
Reference in New Issue