Spaces:
Runtime error
Runtime error
kbberendsen
commited on
Merge branch 'main' of https://huggingface.co/spaces/kbberendsen/formula1
Browse files
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
colorTo: indigo
|
6 |
sdk: docker
|
|
|
1 |
---
|
2 |
+
title: Formula 1
|
3 |
+
emoji: ๐๏ธ
|
4 |
colorFrom: yellow
|
5 |
colorTo: indigo
|
6 |
sdk: docker
|
app.py
CHANGED
@@ -5,27 +5,45 @@ 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 |
-
|
18 |
)
|
19 |
|
20 |
def server(input, output, session):
|
21 |
@reactive.Calc
|
22 |
def get_data():
|
23 |
-
ff1.
|
24 |
-
|
25 |
-
session_f1 = ff1.get_session(2023, input.track, 'R')
|
26 |
-
session_f1.load()
|
27 |
|
28 |
-
lap =
|
29 |
tel = lap.get_telemetry()
|
30 |
|
31 |
#converting data to numpy data tables
|
@@ -35,11 +53,16 @@ def server(input, output, session):
|
|
35 |
points = np.array([x, y]).T.reshape(-1, 1, 2)
|
36 |
segments = np.concatenate([points[:-1], points[1:]], axis=1)
|
37 |
gear = tel['nGear'].to_numpy().astype(float)
|
38 |
-
return
|
39 |
|
40 |
@output
|
41 |
-
@
|
42 |
-
def
|
|
|
|
|
|
|
|
|
|
|
43 |
cmap = cm.get_cmap('Paired')
|
44 |
lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
|
45 |
lc_comp.set_array(gear)
|
@@ -49,10 +72,10 @@ def server(input, output, session):
|
|
49 |
plt.axis('equal')
|
50 |
plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
|
51 |
|
52 |
-
title = plt.suptitle(
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
|
58 |
cbar.set_ticks(np.arange(1.5, 9.5))
|
|
|
5 |
from matplotlib.collections import LineCollection
|
6 |
from matplotlib import cm
|
7 |
import numpy as np
|
8 |
+
import os
|
9 |
+
from pathlib import Path
|
10 |
+
|
11 |
+
# Get the current directory
|
12 |
+
current_directory = Path.cwd()
|
13 |
+
|
14 |
+
# Specify the folder name you want to open (change 'folder_name' to your desired folder)
|
15 |
+
folder_name = 'cache'
|
16 |
+
|
17 |
+
# Create a Path object for the folder
|
18 |
+
folder_path = current_directory / folder_name
|
19 |
+
|
20 |
+
# Check if the cache folder exists
|
21 |
+
if folder_path.exists() and folder_path.is_dir():
|
22 |
+
print(f"The folder '{folder_name}' exists.")
|
23 |
+
else:
|
24 |
+
print(f"The folder '{folder_name}' does not exist.")
|
25 |
+
|
26 |
+
ff1.Cache.enable_cache(folder_path)
|
27 |
|
28 |
app_ui = ui.page_fluid(
|
29 |
ui.div(
|
30 |
ui.input_select(
|
31 |
"track", label="Track",
|
32 |
+
choices=["Austria", "Hungary", "Spanish Grand Prix"],
|
33 |
+
selected = "Austria"
|
34 |
),
|
35 |
class_="d-flex gap-3"
|
36 |
),
|
37 |
+
ui.output_plot("gear")
|
38 |
)
|
39 |
|
40 |
def server(input, output, session):
|
41 |
@reactive.Calc
|
42 |
def get_data():
|
43 |
+
f1_session = ff1.get_session(2023, input.track(), 'R')
|
44 |
+
f1_session.load()
|
|
|
|
|
45 |
|
46 |
+
lap = f1_session.laps.pick_fastest()
|
47 |
tel = lap.get_telemetry()
|
48 |
|
49 |
#converting data to numpy data tables
|
|
|
53 |
points = np.array([x, y]).T.reshape(-1, 1, 2)
|
54 |
segments = np.concatenate([points[:-1], points[1:]], axis=1)
|
55 |
gear = tel['nGear'].to_numpy().astype(float)
|
56 |
+
return points, segments, gear
|
57 |
|
58 |
@output
|
59 |
+
@render.plot
|
60 |
+
def gear():
|
61 |
+
points = get_data().points
|
62 |
+
segments = get_data().segments
|
63 |
+
gear = get_data().gear
|
64 |
+
|
65 |
+
|
66 |
cmap = cm.get_cmap('Paired')
|
67 |
lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
|
68 |
lc_comp.set_array(gear)
|
|
|
72 |
plt.axis('equal')
|
73 |
plt.tick_params(labelleft=False, left=False, labelbottom=False, bottom=False)
|
74 |
|
75 |
+
##title = plt.suptitle(
|
76 |
+
## f"Fastest Lap Gear Shift Visualization\n"
|
77 |
+
## f"{lap['Driver']} - {f1_session.event['EventName']} {f1_session.event.year}"
|
78 |
+
## )
|
79 |
|
80 |
cbar = plt.colorbar(mappable=lc_comp, label="Gear", boundaries=np.arange(1, 10))
|
81 |
cbar.set_ticks(np.arange(1.5, 9.5))
|