Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
125 lines (110 loc) · 3.76 KB
/
Copy pathutils.py
File metadata and controls
125 lines (110 loc) · 3.76 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from datetime import datetime, timedelta
driver_to_team = {
1: 'red-bull-racing',
11: 'red-bull-racing',
44: 'mercedes',
63: 'mercedes',
16: 'ferrari',
55: 'ferrari',
4: 'mclaren',
81: 'mclaren',
14: 'aston-martin',
18: 'aston-martin',
31: 'alpine',
10: 'alpine',
23: 'williams',
2: 'williams',
3: 'alpha-tauri',
22: 'alpha-tauri',
77: 'alfa-romeo',
24: 'alfa-romeo',
20: 'haas',
27: 'haas',
21: 'alpha-tauri',
40: 'alpha-tauri',
}
driver_to_name = {
1: 'Max Verstappen',
11: 'Sergio Perez',
44: 'Lewis Hamilton',
63: 'George Russell',
16: 'Charles Leclerc',
55: 'Carlos Sainz',
4: 'Lando Norris',
81: 'Oscar Piastri',
14: 'Fernando Alonso',
18: 'Lance Stroll',
31: 'Esteban Ocon',
10: 'Pierre Gasly',
23: 'Alexander Albon',
2: 'Logan Sargeant',
3: 'Daniel Ricciardo',
22: 'Yuki Tsunoda',
77: 'Valtteri Bottas',
24: 'Guanyu Zhou',
20: 'Kevin Magnussen',
27: 'Nico Hulkenberg',
21: 'Nyck De Vries',
40: 'Liam Lawson',
}
def degrees_to_direction(degrees):
"""
Converts degrees (0-360) to a compass direction (N, NNE, NE, ENE, etc.).
Args:
degrees (float): The angle in degrees, where 0 is North.
Returns:
str: The compass direction.
Raises:
ValueError: If the input degrees are not within the range 0-360.
"""
if not 0 <= degrees <= 360:
raise ValueError("Degrees must be between 0 and 360 (inclusive).")
# Define the compass directions
directions = [
"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N" #repeat North to complete the circle
]
# Calculate the index
index = int((degrees + 11.25) % 360 / 22.5) #add 11.25 to start from N/2, so 0 becomes N
return directions[index]
def subtract_gmt_offset(start_date_str, gmt_offset_str):
"""
Subtracts the GMT offset from the start date.
Args:
start_date_str: The start date string in "YYYY-MM-DDTHH:MM:SS" format.
gmt_offset_str: The GMT offset string, either "HH:MM:SS" or "-1 day, HH:MM:SS" format.
Returns:
A datetime object representing the start date with the GMT offset subtracted.
Returns None on error.
"""
try:
# Parse the start date string into a datetime object.
start_date = datetime.fromisoformat(start_date_str)
except ValueError:
print(f"Error: Invalid start date format: {start_date_str}")
return None
try:
# Handle the case where gmt_offset_str is in "HH:MM:SS" format
if gmt_offset_str.count(":") == 2 and "day" not in gmt_offset_str:
hours, minutes, seconds = map(int, gmt_offset_str.split(':'))
offset_timedelta = timedelta(hours=hours, minutes=minutes, seconds=seconds)
# Handle the case where gmt_offset_str is in "-1 day, HH:MM:SS" format
elif "day" in gmt_offset_str and gmt_offset_str.count(":") == 2:
parts = gmt_offset_str.split(', ')
days = int(parts[0].split(' ')[0])
hours, minutes, seconds = map(int, parts[1].split(':'))
offset_timedelta = timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
else:
print(f"Error: Invalid GMT offset format: {gmt_offset_str}")
return None
# Subtract the timedelta from the start date
result_date = start_date - offset_timedelta
return result_date
except ValueError as e:
print(f"Error processing GMT offset: {gmt_offset_str} - {e}")
return None
except TypeError as e:
print(f"Error processing GMT offset: {gmt_offset_str} - {e}")
return None
def getPoleSitter(circuit_key):
return