arre99 commited on
Commit
3b19a8f
·
1 Parent(s): 81c6a41

utils for parsing dataframes to string and constants

Browse files
Files changed (2) hide show
  1. utils/constants.py +11 -0
  2. utils/parser_utils.py +18 -0
utils/constants.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ AVAILABLE_SESSION_TYPES = [
3
+ "fp1", "fp2", "fp3", "q", "s", "ss", "sq", "r",
4
+ "practice 1", "practice 2", "practice 3", "sprint",
5
+ "sprint shootout", "sprint qualifying", "qualifying", "race"
6
+ ]
7
+
8
+ DROPDOWN_SESSION_TYPES = [
9
+ "practice 1", "practice 2", "practice 3", "sprint",
10
+ "sprint shootout", "sprint qualifying", "qualifying", "race"
11
+ ]
utils/parser_utils.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastf1.events import EventSchedule, Event
2
+
3
+ def skip_key(key: str) -> bool:
4
+ return True if (key == "F1ApiSupport" or key.endswith("Date")) else False
5
+
6
+ def parse_event_info(event: Event) -> str:
7
+ return "Event info:\n"+"\n".join(f"{k}: {v}" for (k, v) in event.items() if not skip_key(k))
8
+
9
+ def parse_season_calendar(schedule: EventSchedule) -> str:
10
+
11
+ events = []
12
+ for idx in range(len(schedule)):
13
+ e = schedule.iloc[idx]
14
+ data_interval = f"{e['Session1DateUtc'].date()} - {e['Session5DateUtc'].date()}"
15
+ event_string = f"Round {e['RoundNumber']} : {e['EventName']} - {e['Location']}, {e['Country']} ({data_interval})"
16
+ events.append(event_string)
17
+
18
+ return "Season calendar:\n"+"\n".join(events)