kbberendsen commited on
Commit
b3cc530
1 Parent(s): ce9721c

add laptimes

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
@@ -82,12 +82,14 @@ app_ui = ui.page_fluid(
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
  ),
@@ -140,7 +142,8 @@ def server(input, output, session):
140
  points = np.array([x, y]).T.reshape(-1, 1, 2)
141
  segments = np.concatenate([points[:-1], points[1:]], axis=1)
142
  gear = tel['nGear'].to_numpy().astype(float)
143
- return segments, gear, driver
 
144
 
145
  except Exception:
146
  ui.notification_show("Data not available. Select another track or driver.", duration=10, type = 'error')
@@ -169,7 +172,8 @@ def server(input, output, session):
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')
@@ -177,22 +181,50 @@ def server(input, output, session):
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
193
  def gear_1():
194
  try:
195
- segments, gear, driver = get_data_1()
196
 
197
  cmap = cm.get_cmap('Paired')
198
  lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
@@ -216,7 +248,7 @@ def server(input, output, session):
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)
 
82
  ui.column(
83
  6,
84
  ui.output_plot("gear_1"),
85
+ ui.output_text("fastest_driver_1"),
86
+ ui.output_text("laptime_1")
87
  ),
88
  ui.column(
89
  6,
90
  ui.output_plot("gear_2"),
91
+ ui.output_text("fastest_driver_2"),
92
+ ui.output_text("laptime_2")
93
  )
94
  ),
95
  ),
 
142
  points = np.array([x, y]).T.reshape(-1, 1, 2)
143
  segments = np.concatenate([points[:-1], points[1:]], axis=1)
144
  gear = tel['nGear'].to_numpy().astype(float)
145
+ lap_time = lap['LapTime']
146
+ return segments, gear, driver, lap_time
147
 
148
  except Exception:
149
  ui.notification_show("Data not available. Select another track or driver.", duration=10, type = 'error')
 
172
  points = np.array([x, y]).T.reshape(-1, 1, 2)
173
  segments = np.concatenate([points[:-1], points[1:]], axis=1)
174
  gear = tel['nGear'].to_numpy().astype(float)
175
+ lap_time = lap['LapTime']
176
+ return segments, gear, driver, lap_time
177
 
178
  except Exception:
179
  ui.notification_show("Data not available. Select another track or driver.", duration=10, type = 'error')
 
181
  @output
182
  @render.text
183
  def fastest_driver_1():
184
+ segments, gear, driver, lap_time = get_data_1()
185
  #print(f"The driver of the fastest lap this session is: {driver}")
186
  return f"Graph shows the fastest lap of: {driver}"
187
 
188
  @output
189
  @render.text
190
  def fastest_driver_2():
191
+ segments, gear, driver, lap_time = get_data_2()
192
  #print(f"The driver of the fastest lap this session is: {driver}")
193
  return f"Graph shows the fastest lap of: {driver}"
194
+
195
+ @output
196
+ @render.text
197
+ def laptime_1():
198
+ segments, gear, driver, lap_time = get_data_1()
199
+ delta_str= str(lap_time)
200
+ # Split the time delta string to extract hours, minutes, and seconds
201
+ time_parts = delta_str.split(" ")[-1].split(":")
202
+ hours, minutes, seconds = map(float, time_parts)
203
+
204
+ # Convert the extracted values to the desired format
205
+ formatted_time = "{:02d}:{:06.3f}".format(int(hours * 60 + minutes), seconds)
206
+
207
+ return f"The lap time is: {formatted_time}"
208
+
209
+ @output
210
+ @render.text
211
+ def laptime_2():
212
+ segments, gear, driver, lap_time = get_data_2()
213
+ delta_str= str(lap_time)
214
+ # Split the time delta string to extract hours, minutes, and seconds
215
+ time_parts = delta_str.split(" ")[-1].split(":")
216
+ hours, minutes, seconds = map(float, time_parts)
217
+
218
+ # Convert the extracted values to the desired format
219
+ formatted_time = "{:02d}:{:06.3f}".format(int(hours * 60 + minutes), seconds)
220
+
221
+ return f"The lap time is: {formatted_time}"
222
 
223
  @output
224
  @render.plot
225
  def gear_1():
226
  try:
227
+ segments, gear, driver, lap_time = get_data_1()
228
 
229
  cmap = cm.get_cmap('Paired')
230
  lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
 
248
  @render.plot
249
  def gear_2():
250
  try:
251
+ segments, gear, driver, lap_time = get_data_2()
252
 
253
  cmap = cm.get_cmap('Paired')
254
  lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
cache/fastf1_http_cache.sqlite CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e42b17a02523d5d41be6dc5a492b5c5b4b0fec7cf167e2d1f2af55c975f1bfae
3
  size 287285248
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:558bbd011d53b4981749e5e03426fc7a107d27f757f2d43c9730b22fd0660360
3
  size 287285248
f1.py CHANGED
@@ -3,11 +3,12 @@ import matplotlib.pyplot as plt
3
  from matplotlib.collections import LineCollection
4
  from matplotlib import cm
5
  import numpy as np
 
6
 
7
 
8
  ff1.Cache.enable_cache('.\cache')
9
 
10
- session = ff1.get_session(2023, 'Hungary', 'R')
11
  session.load()
12
 
13
  lap = session.laps.pick_fastest()
@@ -40,4 +41,19 @@ cbar.set_ticks(np.arange(1.5, 9.5))
40
  cbar.set_ticklabels(np.arange(1, 9))
41
 
42
 
43
- plt.show()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from matplotlib.collections import LineCollection
4
  from matplotlib import cm
5
  import numpy as np
6
+ import pandas as pd
7
 
8
 
9
  ff1.Cache.enable_cache('.\cache')
10
 
11
+ session = ff1.get_session(2023, 'Austria', 'R')
12
  session.load()
13
 
14
  lap = session.laps.pick_fastest()
 
41
  cbar.set_ticklabels(np.arange(1, 9))
42
 
43
 
44
+ plt.show()
45
+
46
+ lap_time = lap['LapTime']
47
+
48
+ def format_timedelta(td):
49
+ delta_str= str(td)
50
+ # Split the time delta string to extract hours, minutes, and seconds
51
+ time_parts = delta_str.split(" ")[-1].split(":")
52
+ hours, minutes, seconds = map(float, time_parts)
53
+
54
+ # Convert the extracted values to the desired format
55
+ formatted_time = "{:02d}:{:06.3f}".format(int(hours * 60 + minutes), seconds)
56
+
57
+ return f"The lap time is: {formatted_time}"
58
+
59
+ print(format_timedelta(lap_time))