Skip to content

Commit 89a4846

Browse files
Fix formatting and linting issues in pawcast.star
1 parent 37de48a commit 89a4846

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

apps/pawcast/pawcast.star

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
11
# Pawcast - safe dog-walk time from temp + humidity
22

3-
load("render.star", "render")
43
load("math.star", "math")
4+
load("render.star", "render")
55

66
def clamp(x, lo, hi):
7-
if x < lo: return lo
8-
if x > hi: return hi
7+
if x < lo:
8+
return lo
9+
if x > hi:
10+
return hi
911
return x
1012

1113
def heat_index_f(temp_f, rh):
1214
T = float(temp_f)
1315
R = float(rh)
14-
HI = (-42.379
15-
+ 2.04901523*T + 10.14333127*R
16-
- 0.22475541*T*R - 0.00683783*T*T - 0.05481717*R*R
17-
+ 0.00122874*T*T*R + 0.00085282*T*R*R - 0.00000199*T*T*R*R)
16+
HI = (-42.379 +
17+
2.04901523 * T + 10.14333127 * R -
18+
0.22475541 * T * R - 0.00683783 * T * T - 0.05481717 * R * R +
19+
0.00122874 * T * T * R + 0.00085282 * T * R * R - 0.00000199 * T * T * R * R)
1820
return clamp(HI, -40, 140)
1921

2022
def risk_and_minutes(hi_f):
21-
if hi_f < 80: return ("Low Risk", "45-60 min")
22-
if hi_f < 90: return ("Med Risk", "30-45 min")
23-
if hi_f < 100: return ("High Risk", "15-20 min")
24-
if hi_f < 110: return ("Very High Risk", "5-10 min")
23+
if hi_f < 80:
24+
return ("Low Risk", "45-60 min")
25+
if hi_f < 90:
26+
return ("Med Risk", "30-45 min")
27+
if hi_f < 100:
28+
return ("High Risk", "15-20 min")
29+
if hi_f < 110:
30+
return ("Very High Risk", "5-10 min")
2531
return ("Dangerous", "Skip")
2632

2733
def risk_color(risk):
28-
if risk == "Low Risk": return "#61e827ff" # green
29-
if risk == "Med Risk": return "#ffd900ff" # yellow
30-
if risk == "High Risk": return "#ffa600ff" # orange
31-
if risk == "Very High Risk": return "#fe0000ff" # red
32-
return "#000000ff" # black
34+
if risk == "Low Risk":
35+
return "#61e827ff" # green
36+
if risk == "Med Risk":
37+
return "#ffd900ff" # yellow
38+
if risk == "High Risk":
39+
return "#ffa600ff" # orange
40+
if risk == "Very High Risk":
41+
return "#fe0000ff" # red
42+
return "#000000ff" # black
3343

3444
def fmt_int(x):
3545
return str(int(math.round(float(x))))
3646

3747
# White text with 1px black outline (layered copies)
38-
def outlined_text(content, font=None, fill="#FFFFFF", stroke="#000000"):
48+
def outlined_text(content, font = None, fill = "#FFFFFF", stroke = "#000000"):
3949
base_args = {"content": content, "color": stroke}
4050
if font != None:
4151
base_args["font"] = font
@@ -44,23 +54,21 @@ def outlined_text(content, font=None, fill="#FFFFFF", stroke="#000000"):
4454
fill_args["font"] = font
4555

4656
return render.Stack(children = [
47-
render.Padding(pad=(1,0,0,0), child=render.Text(**base_args)), # down 1
48-
render.Padding(pad=(0,1,0,0), child=render.Text(**base_args)), # left 1
49-
render.Padding(pad=(0,0,1,0), child=render.Text(**base_args)), # up 1
50-
render.Padding(pad=(0,0,0,1), child=render.Text(**base_args)), # right 1
51-
render.Text(**fill_args), # center (white)
57+
render.Padding(pad = (1, 0, 0, 0), child = render.Text(**base_args)), # down 1
58+
render.Padding(pad = (0, 1, 0, 0), child = render.Text(**base_args)), # left 1
59+
render.Padding(pad = (0, 0, 1, 0), child = render.Text(**base_args)), # up 1
60+
render.Padding(pad = (0, 0, 0, 1), child = render.Text(**base_args)), # right 1
61+
render.Text(**fill_args), # center (white)
5262
])
5363

54-
55-
5664
def main(config):
5765
# Inputs & defaults
5866
if "temp_f" in config:
5967
temp_f = float(config.get("temp_f"))
6068
elif "temp_c" in config:
61-
temp_f = float(config.get("temp_c")) * 9.0/5.0 + 32.0
69+
temp_f = float(config.get("temp_c")) * 9.0 / 5.0 + 32.0
6270
else:
63-
temp_f =50.0
71+
temp_f = 50.0
6472
rh = float(config.get("humidity", 20))
6573

6674
hi = heat_index_f(temp_f, rh)
@@ -71,13 +79,15 @@ def main(config):
7179

7280
return render.Root(
7381
child = render.Box(
74-
width = 64, height = 32, color = bg, # background = risk color
82+
width = 64,
83+
height = 32,
84+
color = bg, # background = risk color
7585
child = render.Padding(
7686
pad = (1, 1, 1, 1),
7787
child = render.Column(
7888
children = [
7989
# Top line: length of walk (only)
80-
outlined_text(minutes, font="6x13"),
90+
outlined_text(minutes, font = "6x13"),
8191
# Middle line: temp + humidity
8292
outlined_text(raw),
8393
# Bottom line: risk description
@@ -87,7 +97,5 @@ def main(config):
8797
cross_align = "start",
8898
),
8999
),
90-
)
100+
),
91101
)
92-
93-

0 commit comments

Comments
 (0)