Spaces:
Runtime error
Runtime error
kbberendsen
commited on
Commit
•
bb00581
1
Parent(s):
c46cec1
updating app.py and try to show gear graph
Browse files- app.py +42 -34
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,54 +1,62 @@
|
|
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 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
|
15 |
-
tel = lap.get_telemetry()
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
y = np.array(tel['Y'].values)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
gear = tel['nGear'].to_numpy().astype(float)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
lc_comp.set_linewidth(4)
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
plt.
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
app_ui = ui.page_fluid(
|
47 |
-
ui.input_slider("n", "Choose a number n:", 0, 100, 40),
|
48 |
-
ui.output_text_verbatim("txt")
|
49 |
-
)
|
50 |
-
|
51 |
-
def server(input, output, session):
|
52 |
-
...
|
53 |
|
54 |
app = App(app_ui, server)
|
|
|
1 |
from shiny import App, ui
|
2 |
+
from shinywidgets import output_widget, render_widget
|
3 |
import fastf1 as ff1
|
4 |
import matplotlib.pyplot as plt
|
5 |
from matplotlib.collections import LineCollection
|
6 |
from matplotlib import cm
|
7 |
import numpy as np
|
8 |
|
9 |
+
app_ui = ui.page_fluid(
|
10 |
+
ui.div(
|
11 |
+
ui.input_select(
|
12 |
+
"Track", label="Track",
|
13 |
+
choices=["Austria", "Hungary"]
|
14 |
+
),
|
15 |
+
class_="d-flex gap-3"
|
16 |
+
),
|
17 |
+
output_widget("my_widget")
|
18 |
+
)
|
19 |
|
20 |
+
def server(input, output, session):
|
21 |
+
@output
|
22 |
+
@render_widget
|
23 |
+
def my_widget():
|
24 |
|
25 |
+
ff1.Cache.enable_cache('.\cache')
|
|
|
26 |
|
27 |
+
session = ff1.get_session(2023, 'Austria', 'R')
|
28 |
+
session.load()
|
|
|
29 |
|
30 |
+
lap = session.laps.pick_fastest()
|
31 |
+
tel = lap.get_telemetry()
|
|
|
32 |
|
33 |
+
#converting data to numpy data tables
|
34 |
+
x = np.array(tel['X'].values)
|
35 |
+
y = np.array(tel['Y'].values)
|
|
|
36 |
|
37 |
+
points = np.array([x, y]).T.reshape(-1, 1, 2)
|
38 |
+
segments = np.concatenate([points[:-1], points[1:]], axis=1)
|
39 |
+
gear = tel['nGear'].to_numpy().astype(float)
|
40 |
|
41 |
+
cmap = cm.get_cmap('Paired')
|
42 |
+
lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
|
43 |
+
lc_comp.set_array(gear)
|
44 |
+
lc_comp.set_linewidth(4)
|
45 |
|
46 |
+
plt.gca().add_collection(lc_comp)
|
47 |
+
plt.axis('equal')
|
48 |
+
plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
|
49 |
|
50 |
+
title = plt.suptitle(
|
51 |
+
f"Fastest Lap Gear Shift Visualization\n"
|
52 |
+
f"{lap['Driver']} - {session.event['EventName']} {session.event.year}"
|
53 |
+
)
|
54 |
|
55 |
+
cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
|
56 |
+
cbar.set_ticks(np.arange(1.5, 9.5))
|
57 |
+
cbar.set_ticklabels(np.arange(1, 9))
|
58 |
+
|
59 |
+
return plt
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
app = App(app_ui, server)
|
requirements.txt
CHANGED
@@ -37,3 +37,4 @@ uvicorn==0.21.1
|
|
37 |
websockets==11.0.2
|
38 |
XStatic-bootswatch==3.3.7.0
|
39 |
fastf1=3.0.7
|
|
|
|
37 |
websockets==11.0.2
|
38 |
XStatic-bootswatch==3.3.7.0
|
39 |
fastf1=3.0.7
|
40 |
+
shinywidgets=0.2.1
|