1616VSCALE = 20 # vertical plot scale
1717#-------------------------------------------
1818
19+ # pylint: disable=line-too-long
1920DATA_SOURCE = "https://tidesandcurrents.noaa.gov/api/datagetter?date=today&product=predictions&datum=mllw&format=json&units=metric&time_zone=lst_ldt&station=" + STATION_ID
2021DATA_LOCATION = ["predictions" ]
2122
5758
5859# Setup current time marker
5960time_marker_bitmap = displayio .Bitmap (MARK_SIZE , MARK_SIZE , 3 )
60- for i in range (MARK_SIZE * MARK_SIZE ):
61- time_marker_bitmap [i ] = 2
61+ for pixel in range (MARK_SIZE * MARK_SIZE ):
62+ time_marker_bitmap [pixel ] = 2
6263time_marker = displayio .TileGrid (time_marker_bitmap , pixel_shader = palette , x = - MARK_SIZE , y = - MARK_SIZE )
6364pyportal .splash .append (time_marker )
6465
@@ -69,20 +70,20 @@ def get_tide_data():
6970 raw_data = pyportal .fetch ()
7071
7172 # Results will be stored in a list that is display WIDTH long
72- tide_data = [None ]* WIDTH
73+ new_tide_data = [None ]* WIDTH
7374
7475 # Convert raw data to display coordinates
7576 for data in raw_data :
76- d , t = data ["t" ].split (" " ) # date and time
77+ _ , t = data ["t" ].split (" " ) # date and time
7778 h , m = t .split (":" ) # hours and minutes
7879 v = data ["v" ] # water level
7980 x = round ( (WIDTH - 1 ) * (60 * float (h ) + float (m )) / 1440 )
8081 y = (HEIGHT // 2 ) - round (VSCALE * float (v ))
8182 y = 0 if y < 0 else y
8283 y = HEIGHT - 1 if y >= HEIGHT else y
83- tide_data [x ] = y
84+ new_tide_data [x ] = y
8485
85- return tide_data
86+ return new_tide_data
8687
8788def draw_data_point (x , y , size = PLOT_SIZE , color = 1 ):
8889 """Draw data point on to the tide plot bitmap at (x,y)."""
@@ -96,10 +97,10 @@ def draw_data_point(x, y, size=PLOT_SIZE, color=1):
9697 except IndexError :
9798 pass
9899
99- def draw_time_marker (current_time ):
100+ def draw_time_marker (time_info ):
100101 """Draw a marker on the tide plot for the current time."""
101- h = current_time .tm_hour
102- m = current_time .tm_min
102+ h = time_info .tm_hour
103+ m = time_info .tm_min
103104 x = round ( (WIDTH - 1 ) * (60 * float (h ) + float (m )) / 1440 )
104105 y = tide_data [x ]
105106 if y is not None :
@@ -108,7 +109,7 @@ def draw_time_marker(current_time):
108109 time_marker .x = x
109110 time_marker .y = y
110111
111- def update_display (current_time , update_tides = False ):
112+ def update_display (time_info , update_tides = False ):
112113 """Update the display with current info."""
113114
114115 # Tide data plot
@@ -121,15 +122,15 @@ def update_display(current_time, update_tides=False):
121122 draw_data_point (x , tide_data [x ])
122123
123124 # Current location marker
124- draw_time_marker (current_time )
125+ draw_time_marker (time_info )
125126
126127 # Date and time
127- date_label .text = "{:04}-{:02}-{:02}" .format (current_time .tm_year ,
128- current_time .tm_mon ,
129- current_time .tm_mday )
130- time_label .text = "{:02}:{:02}:{:02}" .format (current_time .tm_hour ,
131- current_time .tm_min ,
132- current_time .tm_sec )
128+ date_label .text = "{:04}-{:02}-{:02}" .format (time_info .tm_year ,
129+ time_info .tm_mon ,
130+ time_info .tm_mday )
131+ time_label .text = "{:02}:{:02}:{:02}" .format (time_info .tm_hour ,
132+ time_info .tm_min ,
133+ time_info .tm_sec )
133134
134135 board .DISPLAY .refresh_soon ()
135136
@@ -149,4 +150,4 @@ def update_display(current_time, update_tides=False):
149150 new_tides = True
150151 current_yday = current_time .tm_yday
151152 update_display (current_time , new_tides )
152- time .sleep (0.5 )
153+ time .sleep (0.5 )
0 commit comments