diff --git a/dashboard.py b/dashboard.py
index 816e375..6fea2f2 100644
--- a/dashboard.py
+++ b/dashboard.py
@@ -74,26 +74,27 @@ class Widget:
self.lastvalue = self.lts.data[-1][1]
return Markup(render_template("widget.html", widget=self))
- @property
- def criticalcolor(self):
+ def criticalcolor(self, value=None):
+ if value == None:
+ value = self.lastvalue
log.debug("stops = %s", self.stops)
brightness = 30
if self.stops[0] < self.stops[2]:
- if self.lastvalue < self.stops[0]:
+ if value < self.stops[0]:
log.debug("definitely ok")
return f"hsl(120, 100%, {brightness}%)"
- elif self.lastvalue < self.stops[1]:
+ elif value < self.stops[1]:
log.debug("mostly ok")
hue = 120 - round(
- (self.lastvalue - self.stops[0])
+ (value - self.stops[0])
/ (self.stops[1] - self.stops[0])
* 60
)
return f"hsl({hue}, 100%, {brightness}%)"
- elif self.lastvalue < self.stops[2]:
+ elif value < self.stops[2]:
log.debug("maybe fail")
hue = 60 - round(
- (self.lastvalue - self.stops[1])
+ (value - self.stops[1])
/ (self.stops[2] - self.stops[1])
* 60
)
@@ -103,21 +104,21 @@ class Widget:
return f"hsl(0, 100%, {brightness}%)"
else:
log.debug("the other side")
- if self.lastvalue > self.stops[0]:
+ if value > self.stops[0]:
log.debug("definitely ok")
return f"hsl(120, 100%, {brightness}%)"
- elif self.lastvalue > self.stops[1]:
+ elif value > self.stops[1]:
log.debug("mostly ok")
hue = 120 - round(
- (self.lastvalue - self.stops[0])
+ (value - self.stops[0])
/ (self.stops[1] - self.stops[0])
* 60
)
return f"hsl({hue}, 100%, {brightness}%)"
- elif self.lastvalue > self.stops[2]:
+ elif value > self.stops[2]:
log.debug("maybe fail")
hue = 60 - round(
- (self.lastvalue - self.stops[1])
+ (value - self.stops[1])
/ (self.stops[2] - self.stops[1])
* 60
)
@@ -162,7 +163,14 @@ class TimeSeries(Widget):
x = t2x(t)
t_h = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t))
#print(t, t_h, x)
- v_data.append({"t": t, "v": data[i][1], "x": x, "y": (1 - data[i][1]/max_value) * 200})
+ v_data.append(
+ {
+ "t": t,
+ "v": data[i][1],
+ "x": x,
+ "y": (1 - data[i][1]/max_value) * 200,
+ "color": self.criticalcolor(data[i][1]),
+ })
tickmarks = []
t = v_data[-1]["t"]
@@ -317,7 +325,7 @@ class TimeSeries(Widget):
html += f"
Unknown widget type {{ widget.type }}.
Last value: - {{ widget.lastvalue}} + {{ widget.lastvalue}}