From 4380210c343ffc96ea8d00d9440a20d754368802 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 31 Dec 2022 17:55:25 +0100 Subject: [PATCH] Display min, max and last value in description --- dashboard.py | 9 +++++++++ templates/dashboard.html | 3 +++ 2 files changed, 12 insertions(+) diff --git a/dashboard.py b/dashboard.py index e3f30c5..1f69bcf 100644 --- a/dashboard.py +++ b/dashboard.py @@ -67,6 +67,7 @@ class Widget: self.type = d["type"] self.stops = d["stops"] self.yscale = d.get("yscale", "linear") + self.extra = {} log.debug("data = %s", d["data"]) self.lts = LTS(id=d["data"][0]) # by default we handle only one data source pass @@ -137,6 +138,11 @@ class Widget: s += render_template_string( "{{d}}:{{v}}", d=d, v=v) + for d, v in self.extra.items(): + if v: + s += render_template_string( + "{{d}}:{{v}}", + d=d, v=v) s += "" return Markup(s) @@ -362,6 +368,7 @@ class TimeSeries(Widget): if self.yscale == "log": try: min_value = min(d[1] for d in self.lts.data if d[1] > 0) + self.extra["min"] = "%g" % min_value except ValueError: # no non-negative values min_value = max_value / 2 @@ -375,6 +382,8 @@ 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) + self.extra["max"] = "%g" % max_value + self.extra["last"] = "%g" % data[-1][1] log.debug("collecting data") v_data = [] for i in range(n): diff --git a/templates/dashboard.html b/templates/dashboard.html index ebc3bc5..20e3ac3 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -53,6 +53,9 @@ border: 1px solid #CCC; padding: 0.5rem; } + .extra { + font-style: italic; + }