kbberendsen commited on
Commit
c46cec1
1 Parent(s): 0d0ff81

copy f1 code to app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py CHANGED
@@ -1,4 +1,47 @@
1
  from shiny import App, ui
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  app_ui = ui.page_fluid(
4
  ui.input_slider("n", "Choose a number n:", 0, 100, 40),
 
1
  from shiny import App, ui
2
+ import fastf1 as ff1
3
+ import matplotlib.pyplot as plt
4
+ from matplotlib.collections import LineCollection
5
+ from matplotlib import cm
6
+ import numpy as np
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()
15
+ tel = lap.get_telemetry()
16
+
17
+ #converting data to numpy data tables
18
+ x = np.array(tel['X'].values)
19
+ y = np.array(tel['Y'].values)
20
+
21
+ points = np.array([x, y]).T.reshape(-1, 1, 2)
22
+ segments = np.concatenate([points[:-1], points[1:]], axis=1)
23
+ gear = tel['nGear'].to_numpy().astype(float)
24
+
25
+ cmap = cm.get_cmap('Paired')
26
+ lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
27
+ lc_comp.set_array(gear)
28
+ lc_comp.set_linewidth(4)
29
+
30
+ plt.gca().add_collection(lc_comp)
31
+ plt.axis('equal')
32
+ plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
33
+
34
+ title = plt.suptitle(
35
+ f"Fastest Lap Gear Shift Visualization\n"
36
+ f"{lap['Driver']} - {session.event['EventName']} {session.event.year}"
37
+ )
38
+
39
+ cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
40
+ cbar.set_ticks(np.arange(1.5, 9.5))
41
+ cbar.set_ticklabels(np.arange(1, 9))
42
+
43
+
44
+ plt.show()
45
 
46
  app_ui = ui.page_fluid(
47
  ui.input_slider("n", "Choose a number n:", 0, 100, 40),