kbberendsen commited on
Commit
b543474
1 Parent(s): baf5897

import packages in module

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. modules/plot.py +44 -0
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
modules/plot.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from shiny import module, ui, render, reactive, event, App
2
+ import fastf1 as ff1
3
+ import numpy as np
4
+
5
+ # UI
6
+ @module.ui
7
+ def plot1_ui():
8
+ return ui.ouput_plot("gear_1")
9
+
10
+
11
+ # Server
12
+ @module.server
13
+ def plot1_server():
14
+ @reactive.Calc
15
+ # Get required data for driver 1 based on selection
16
+ def get_data_1():
17
+ try:
18
+ ui.notification_show("Data takes a couple seconds to load.", duration=3, type = 'default')
19
+
20
+ f1_session = ff1.get_session(int(input.year()), input.track_select(), input.session_type())
21
+ f1_session.load()
22
+
23
+ # Check if user input == fastest driver
24
+ if input.driver1_select() == "Fastest driver":
25
+ lap = f1_session.laps.pick_fastest()
26
+ else:
27
+ laps_driver = f1_session.laps.pick_driver(input.driver1_select())
28
+ lap = laps_driver.pick_fastest()
29
+
30
+ tel = lap.get_telemetry()
31
+ driver = lap['Driver']
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
+ lap_time = lap['LapTime']
41
+ return segments, gear, driver, lap_time
42
+
43
+ except Exception:
44
+ ui.notification_show("Data not available. Select another track or driver.", duration=10, type = 'error')