kbberendsen commited on
Commit
44864e0
1 Parent(s): 217dd35

second graph

Browse files
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
app.py CHANGED
@@ -81,12 +81,13 @@ app_ui = ui.page_fluid(
81
  ui.row(
82
  ui.column(
83
  6,
84
- ui.output_plot("gear"),
85
- ui.output_text("fastest_driver")
86
  ),
87
  ui.column(
88
  6,
89
- ui.output_text("column_2")
 
90
  )
91
  ),
92
  ),
@@ -115,7 +116,7 @@ def server(input, output, session):
115
  selected=input.driver2_select()
116
  )
117
 
118
- # Get required data for both drivers based on selection
119
  @reactive.Calc
120
  def get_data_1():
121
  try:
@@ -144,12 +145,48 @@ def server(input, output, session):
144
  except Exception:
145
  ui.notification_show("Data not available. Select another track or driver.", duration=10, type = 'error')
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  @output
148
  @render.text
149
  def fastest_driver_1():
150
  segments, gear, driver = get_data_1()
151
  #print(f"The driver of the fastest lap this session is: {driver}")
152
  return f"Graph shows the fastest lap of: {driver}"
 
 
 
 
 
 
 
153
 
154
  @output
155
  @render.plot
@@ -175,4 +212,28 @@ def server(input, output, session):
175
  except Exception:
176
  pass
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  app = App(app_ui, server)
 
81
  ui.row(
82
  ui.column(
83
  6,
84
+ ui.output_plot("gear_1"),
85
+ ui.output_text("fastest_driver_1")
86
  ),
87
  ui.column(
88
  6,
89
+ ui.output_plot("gear_2"),
90
+ ui.output_text("fastest_driver_2")
91
  )
92
  ),
93
  ),
 
116
  selected=input.driver2_select()
117
  )
118
 
119
+ # Get required data for driver 2 based on selection
120
  @reactive.Calc
121
  def get_data_1():
122
  try:
 
145
  except Exception:
146
  ui.notification_show("Data not available. Select another track or driver.", duration=10, type = 'error')
147
 
148
+ # Get required data for driver 2 based on selection
149
+ @reactive.Calc
150
+ def get_data_2():
151
+ try:
152
+ f1_session = ff1.get_session(int(input.year()), input.track_select(), input.session_type())
153
+ f1_session.load()
154
+
155
+ # Check if user input == fastest driver
156
+ if input.driver2_select() == "Fastest driver":
157
+ lap = f1_session.laps.pick_fastest()
158
+ else:
159
+ laps_driver = f1_session.laps.pick_driver(input.driver2_select())
160
+ lap = laps_driver.pick_fastest()
161
+
162
+ tel = lap.get_telemetry()
163
+ driver = lap['Driver']
164
+
165
+ #converting data to numpy data tables
166
+ x = np.array(tel['X'].values)
167
+ y = np.array(tel['Y'].values)
168
+
169
+ points = np.array([x, y]).T.reshape(-1, 1, 2)
170
+ segments = np.concatenate([points[:-1], points[1:]], axis=1)
171
+ gear = tel['nGear'].to_numpy().astype(float)
172
+ return segments, gear, driver
173
+
174
+ except Exception:
175
+ ui.notification_show("Data not available. Select another track or driver.", duration=10, type = 'error')
176
+
177
  @output
178
  @render.text
179
  def fastest_driver_1():
180
  segments, gear, driver = get_data_1()
181
  #print(f"The driver of the fastest lap this session is: {driver}")
182
  return f"Graph shows the fastest lap of: {driver}"
183
+
184
+ @output
185
+ @render.text
186
+ def fastest_driver_2():
187
+ segments, gear, driver = get_data_2()
188
+ #print(f"The driver of the fastest lap this session is: {driver}")
189
+ return f"Graph shows the fastest lap of: {driver}"
190
 
191
  @output
192
  @render.plot
 
212
  except Exception:
213
  pass
214
 
215
+ @output
216
+ @render.plot
217
+ def gear_2():
218
+ try:
219
+ segments, gear, driver = get_data_2()
220
+
221
+ cmap = cm.get_cmap('Paired')
222
+ lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
223
+ lc_comp.set_array(gear)
224
+ lc_comp.set_linewidth(4)
225
+
226
+ plt.gca().add_collection(lc_comp)
227
+ plt.axis('equal')
228
+ plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
229
+
230
+ cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
231
+ cbar.set_ticks(np.arange(1.5, 9.5))
232
+ cbar.set_ticklabels(np.arange(1, 9))
233
+
234
+ plt
235
+
236
+ except Exception:
237
+ pass
238
+
239
  app = App(app_ui, server)
cache/fastf1_http_cache.sqlite CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1b369a473451488571ed3c82190ba1cd424e0bea56d0af4b02b2a31088a3c945
3
  size 287285248
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e42b17a02523d5d41be6dc5a492b5c5b4b0fec7cf167e2d1f2af55c975f1bfae
3
  size 287285248