-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.py
More file actions
55 lines (43 loc) · 1.57 KB
/
cache.py
File metadata and controls
55 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# caching script
# run with or without cli args
# ex:
# load light quali + race data for current season (excludes laps, telem, weather, and messages data)
# python cache.py
# load all quali + race data for given season
# python cache.py 2020 True
import fastf1
import sys
import pandas as pd
fastf1.Cache.enable_cache('cache/')
now = pd.Timestamp.now()
n = len(sys.argv) - 1
allData = False
numRaces = 0
schedule = None
errorString = ''
if (n == 0):
schedule = fastf1.get_event_schedule(now.year, include_testing=False)
year = now.year
if n == 2:
year = int(sys.argv[1])
schedule = fastf1.get_event_schedule(year, include_testing=False)
if sys.argv[2].lower() == 'true':
allData = True
numRaces = len(schedule)+1
for i in range(1,numRaces):
try:
try:
race = fastf1.get_session(year, i, 'Q')
race.load(laps=allData,telemetry=allData,weather=allData,messages=allData)
except fastf1.core.DataNotLoadedError:
racename = schedule.loc[i,'EventName']
errorString +=(f"quali data not loaded for {racename}(session probably hasn't happened yet)\n")
try:
race = fastf1.get_session(year, i, 'R')
race.load(laps=allData,telemetry=allData,weather=allData,messages=allData)
except fastf1.core.DataNotLoadedError:
racename = schedule.loc[i,'EventName']
errorString +=(f"race data not loaded for {racename}(session probably hasn't happened yet)\n")
except Exception as e:
errorString += e+"\n"
print(errorString)