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