Merge branch 'master' of git.hjp.at:hjp/ltsdb

This commit is contained in:
Peter J. Holzer 2024-08-24 22:51:43 +02:00
commit 1a798be52d
1 changed files with 33 additions and 3 deletions

View File

@ -395,6 +395,9 @@ 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)
if unit == "s":
self.extra["min"] = "%g" % min_value + " (" + self.format_time(min_value) + ")"
else:
self.extra["min"] = "%g" % min_value self.extra["min"] = "%g" % min_value
except ValueError: except ValueError:
# no non-negative values # no non-negative values
@ -409,6 +412,10 @@ 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)
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["max"] = "%g" % max_value
self.extra["last"] = "%g" % data[-1][1] self.extra["last"] = "%g" % data[-1][1]
log.debug("collecting data") log.debug("collecting data")
@ -464,6 +471,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)
@ -505,3 +534,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