kbberendsen commited on
Commit
84b4aa4
1 Parent(s): 485d878
Files changed (3) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. app.py +26 -9
  3. requirements.txt +1 -0
__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
@@ -9,6 +9,8 @@ from matplotlib.collections import LineCollection
9
  from matplotlib import cm
10
  import numpy as np
11
  from pathlib import Path
 
 
12
 
13
  # Create a Path object for the folder
14
  cache_path = os.getcwd() + "/cache"
@@ -18,16 +20,22 @@ ff1.Cache.offline_mode(enabled=True)
18
 
19
  print(f"Cache path: {cache_path}")
20
 
21
- app_ui = ui.page_fluid(
22
- ui.div(
23
- ui.input_select(
24
- "track", label="Track",
 
 
25
  choices=["Austria", "Hungary", "Spain", "Bahrain"],
26
- selected = "Austria"
27
  ),
28
- class_="d-flex gap-3"
 
 
 
 
 
29
  ),
30
- ui.output_plot("gear")
31
  )
32
 
33
  def server(input, output, session):
@@ -38,6 +46,7 @@ def server(input, output, session):
38
 
39
  lap = f1_session.laps.pick_fastest()
40
  tel = lap.get_telemetry()
 
41
 
42
  #converting data to numpy data tables
43
  x = np.array(tel['X'].values)
@@ -46,12 +55,12 @@ def server(input, output, session):
46
  points = np.array([x, y]).T.reshape(-1, 1, 2)
47
  segments = np.concatenate([points[:-1], points[1:]], axis=1)
48
  gear = tel['nGear'].to_numpy().astype(float)
49
- return segments, gear
50
 
51
  @output
52
  @render.plot
53
  def gear():
54
- segments, gear = get_data()
55
 
56
  cmap = cm.get_cmap('Paired')
57
  lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
@@ -73,5 +82,13 @@ def server(input, output, session):
73
 
74
  plt
75
 
 
 
 
 
 
 
 
 
76
 
77
  app = App(app_ui, server)
 
9
  from matplotlib import cm
10
  import numpy as np
11
  from pathlib import Path
12
+ import shiny.experimental as x
13
+ import shinyswatch
14
 
15
  # Create a Path object for the folder
16
  cache_path = os.getcwd() + "/cache"
 
20
 
21
  print(f"Cache path: {cache_path}")
22
 
23
+ app_ui = x.ui.page_fillable(
24
+ shinyswatch.theme.minty(),
25
+ x.ui.layout_sidebar(
26
+ x.ui.sidebar(
27
+ ui.input_select(
28
+ "track", label="Select track:",
29
  choices=["Austria", "Hungary", "Spain", "Bahrain"],
30
+ selected = "Austria"),
31
  ),
32
+ ui.h3("Gear usage in fastest lap"),
33
+ x.ui.output_plot("gear", fill = True),
34
+ ui.output_text("fastest_driver"),
35
+
36
+ fill=True,
37
+ fillable=True,
38
  ),
 
39
  )
40
 
41
  def server(input, output, session):
 
46
 
47
  lap = f1_session.laps.pick_fastest()
48
  tel = lap.get_telemetry()
49
+ driver = lap['Driver']
50
 
51
  #converting data to numpy data tables
52
  x = np.array(tel['X'].values)
 
55
  points = np.array([x, y]).T.reshape(-1, 1, 2)
56
  segments = np.concatenate([points[:-1], points[1:]], axis=1)
57
  gear = tel['nGear'].to_numpy().astype(float)
58
+ return segments, gear, driver
59
 
60
  @output
61
  @render.plot
62
  def gear():
63
+ segments, gear, driver = get_data()
64
 
65
  cmap = cm.get_cmap('Paired')
66
  lc_comp = LineCollection(segments, norm=plt.Normalize(1, cmap.N+1), cmap=cmap)
 
82
 
83
  plt
84
 
85
+ @output
86
+ @render.text
87
+ def fastest_driver():
88
+ segments, gear, driver = get_data()
89
+
90
+ print(driver)
91
+ return f"The driver of the fastest lap is: {driver}"
92
+
93
 
94
  app = App(app_ui, server)
requirements.txt CHANGED
@@ -38,3 +38,4 @@ websockets==11.0.2
38
  XStatic-bootswatch==3.3.7.0
39
  fastf1==3.0.7
40
  shinywidgets==0.2.1
 
 
38
  XStatic-bootswatch==3.3.7.0
39
  fastf1==3.0.7
40
  shinywidgets==0.2.1
41
+ shinyswatch=0.2.4