From 74c6a1930245b25a314cc6321357b19ce9222c5a Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Tue, 27 Dec 2022 10:54:19 +0100 Subject: [PATCH] Implement descending criticality thresholds --- dashboard.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dashboard.py b/dashboard.py index 968c684..f4167e7 100644 --- a/dashboard.py +++ b/dashboard.py @@ -77,7 +77,29 @@ class Widget: return f"hsl(0, 100%, {brightness}%)" else: log.debug("the other side") - return "#CCC" + if self.lastvalue > self.stops[0]: + log.debug("definitely ok") + return f"hsl(120, 100%, {brightness}%)" + elif self.lastvalue > self.stops[1]: + log.debug("mostly ok") + hue = 120 - round( + (self.lastvalue - self.stops[0]) + / (self.stops[1] - self.stops[0]) + * 60 + ) + return f"hsl({hue}, 100%, {brightness}%)" + elif self.lastvalue > self.stops[2]: + log.debug("maybe fail") + hue = 60 - round( + (self.lastvalue - self.stops[1]) + / (self.stops[2] - self.stops[1]) + * 60 + ) + return f"hsl({hue}, 100%, {brightness}%)" + else: + log.debug("definitely fail") + return f"hsl(0, 100%, {brightness}%)" + class TimeSeries(Widget): def __init__(self, d): @@ -94,6 +116,7 @@ class Gauge(Widget): @property def gaugepos(self): max_value = max([d[1] for d in self.lts.data]) + max_value = max(max_value, 1) # ensure positive log.debug("max_value = %s", max_value) return self.lastvalue / max_value * self.gaugesize