-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (53 loc) · 2.28 KB
/
main.py
File metadata and controls
65 lines (53 loc) · 2.28 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
56
57
58
59
60
61
62
63
64
65
import fastf1
import fastf1.events
from ui.menu import menu_screen
from ui.replay import run_replay
def main():
print("\n=== F1 RACE VISION (2025 REPLAY MODE) ===\n")
# Enable FastF1 cache
# Use a consistent cache path across the application
fastf1.Cache.enable_cache("f1_cache")
# --- Step 1: Get available races and show menu ---
races_by_year = {}
# Start with the desired year, but be ready to fall back
year_to_try = 2025
try:
print(f"[INFO] Fetching event schedule for {year_to_try}...")
schedule = fastf1.get_event_schedule(year_to_try, include_testing=False)
races_by_year[year_to_try] = [
(row['RoundNumber'], row['EventName'])
for _, row in schedule.iterrows()
if row['EventFormat'] != 'testing'
]
except Exception as e:
print(f"[WARNING] Could not fetch {year_to_try} schedule from FastF1: {e}")
print("[INFO] Attempting to fall back to previous year's schedule...")
year_to_try = 2024 # Fallback year
try:
print(f"[INFO] Fetching event schedule for {year_to_try}...")
schedule = fastf1.get_event_schedule(year_to_try, include_testing=False)
races_by_year[year_to_try] = [
(row['RoundNumber'], row['EventName'])
for _, row in schedule.iterrows()
if row['EventFormat'] != 'testing'
]
except Exception as e2:
print(f"[ERROR] Failed to fetch fallback schedule for {year_to_try}: {e2}")
print("[ERROR] Please check your internet connection or try again later. Exiting.")
return
year, round_number, gp_name = menu_screen(races_by_year, default_year=year_to_try)
if not (year and round_number):
print("No race selected. Exiting.")
return
# --- Step 2: Get circuit name ---
try:
event = fastf1.get_event(year, round_number)
circuit_name = event['Location']
except Exception as e:
print(f"[WARNING] Could not fetch circuit name: {e}")
circuit_name = ""
# --- Step 3: Start replay UI ---
run_replay(year, round_number, gp_name, circuit_name)
print("\nReplay ended successfully. Thank you for using F1 RaceVision!\n")
if __name__ == "__main__":
main()