Small code clean up

This commit is contained in:
Admar Schoonen 2023-05-26 23:12:35 +02:00
parent 7e20a13bc6
commit 82f4be8309
1 changed files with 22 additions and 43 deletions

View File

@ -269,17 +269,17 @@ class MyClockWidget(FloatLayout):
is_arm = is_arm()
aqi_colors = [
[0.0, 0.0, 0.0], # x < 1.0 black (good)
[0.0, 0.0, 255.0/255.0], # 1.0 <= x < 2.0 blue (good)
[0.0, 160.0/255.0, 160.0/255.0], # 2.0 <= x < 3.0 cyan (good)
[1.0, 1.0, 1.0], # 3.0 <= x < 4.0 white (mediocre)
[255.0/255.0, 255.0/255.0, 150.0/255.0], # 4.0 <= < x 5.0 light yellow (mediocre)
[200.0/255.0, 200.0/255.0, 0.0], # 5.0 <= x < 6.0 yellow (mediocre)
[1.0, 175.0/255.0, 0.0], # 6.0 <= x < 7.0 orange (inadequate)
[1.0, 120.0/255.0, 0.0], # 7.0 <= x < 8.0 red orange (inadequate)
[200.0/255.0, 0.0, 0.0], # 8.0 <= x < 9.0 red (bad)
[200.0/255.0, 0.0, 200.0/255.0], # 9.0 <= x < 10.0 magenta (bad)
[70.0/255.0, 0.0, 255.0/255.0], # 10.0 <= x purple (terrible)
[0.0, 0.0, 0.0], # x < 1.0 black (good)
[0.0, 0.0, 255.0/255.0], # 1.0 <= x < 2.0 blue (good)
[0.0, 160.0/255.0, 160.0/255.0], # 2.0 <= x < 3.0 cyan (good)
[1.0, 1.0, 1.0], # 3.0 <= x < 4.0 white (mediocre)
[1.0, 1.0, 150.0/255.0], # 4.0 <= < x 5.0 light yellow (mediocre)
[200.0/255.0, 200.0/255.0, 0.0], # 5.0 <= x < 6.0 yellow (mediocre)
[1.0, 175.0/255.0, 0.0], # 6.0 <= x < 7.0 orange (inadequate)
[1.0, 120.0/255.0, 0.0], # 7.0 <= x < 8.0 red orange (inadequate)
[200.0/255.0, 0.0, 0.0], # 8.0 <= x < 9.0 red (bad)
[200.0/255.0, 0.0, 200.0/255.0], # 9.0 <= x < 10.0 magenta (bad)
[70.0/255.0, 0.0, 255.0/255.0], # 10.0 <= x purple (terrible)
]
rain = []
@ -591,16 +591,16 @@ class MyClockWidget(FloatLayout):
))
self.ids["face"].add_widget(self.face_numbers[i - 1])
def draw_rain_expectation(self):
if len(self.rain) == 0:
def draw_rain_aqi_expectation(self, x, x_thresholds, location):
if len(x) == 0:
return
face_plate = self.ids["face_plate"]
with face_plate.canvas:
for i in range(0, 12):
idx = 0
for l in self.rain_thresholds:
if l > self.rain[i]:
for l in x_thresholds:
if l > x[i]:
break
idx = idx + 1
@ -612,38 +612,17 @@ class MyClockWidget(FloatLayout):
self.draw_list_curr_frame.append(["Color", face_plate.canvas, color[0], color[1], color[2]])
R = face_plate.size[0] / 2
r = R / 10
x = 0.5 + 0.45*math.sin(2 * math.pi * i/12)
y = 0.5 + 0.45*math.cos(2 * math.pi * i/12)
p = [face_plate.pos[0] + 2 * R * x - r, face_plate.pos[1] + 2 * R * y - r]
coord_x = 0.5 + location*math.sin(2 * math.pi * i/12)
coord_y = 0.5 + location*math.cos(2 * math.pi * i/12)
p = [face_plate.pos[0] + 2 * R * coord_x - r, face_plate.pos[1] + 2 * R * coord_y - r]
#self.draw_list_curr_frame.append(["Circle", face_plate.canvas, p, r / 10])
self.draw_list_curr_frame.append(["Ellipse", face_plate.canvas, [2 * r, 2 * r], p])
def draw_rain_expectation(self):
self.draw_rain_aqi_expectation(self.rain, self.rain_thresholds, 0.45)
def draw_aqi_expectation(self):
if len(self.paqi) == 0:
return
face_plate = self.ids["face_plate"]
with face_plate.canvas:
for i in range(0, 12):
idx = 0
for l in self.paqi_thresholds:
if l > self.paqi[i]:
break
idx = idx + 1
if idx >= len(self.aqi_colors):
idx = len(self.aqi_colors) - 1
color = self.aqi_colors[idx]
if color != [0.0, 0.0, 0.0]:
self.draw_list_curr_frame.append(["Color", face_plate.canvas, color[0], color[1], color[2]])
R = face_plate.size[0] / 2
r = R / 10
x = 0.5 + 0.30*math.sin(2 * math.pi * i/12)
y = 0.5 + 0.30*math.cos(2 * math.pi * i/12)
p = [face_plate.pos[0] + 2 * R * x - r, face_plate.pos[1] + 2 * R * y - r]
#self.draw_list_curr_frame.append(["Circle", face_plate.canvas, p, r / 10])
self.draw_list_curr_frame.append(["Ellipse", face_plate.canvas, [2 * r, 2 * r], p])
self.draw_rain_aqi_expectation(self.paqi, self.paqi_thresholds, 0.35)
def draw_face(self):
self.draw_numbers()