Implement descending criticality thresholds

This commit is contained in:
Peter J. Holzer 2022-12-27 10:54:19 +01:00 committed by Peter J. Holzer
parent eeb7db96b8
commit 74c6a19302
1 changed files with 24 additions and 1 deletions

View File

@ -77,7 +77,29 @@ class Widget:
return f"hsl(0, 100%, {brightness}%)" return f"hsl(0, 100%, {brightness}%)"
else: else:
log.debug("the other side") 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): class TimeSeries(Widget):
def __init__(self, d): def __init__(self, d):
@ -94,6 +116,7 @@ class Gauge(Widget):
@property @property
def gaugepos(self): def gaugepos(self):
max_value = max([d[1] for d in self.lts.data]) 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) log.debug("max_value = %s", max_value)
return self.lastvalue / max_value * self.gaugesize return self.lastvalue / max_value * self.gaugesize