created new notebook for openf1 API and removed resources since gradio auto function cast, only supports tools anyway
Browse files- openf1_api_playground.ipynb +392 -0
- resources.py +0 -0
openf1_api_playground.ipynb
ADDED
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 10,
|
6 |
+
"id": "b7d2515e",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"Successfully loaded in libraries\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"import fastf1\n",
|
19 |
+
"import pandas as pd\n",
|
20 |
+
"from urllib.request import urlopen\n",
|
21 |
+
"from pprint import pprint\n",
|
22 |
+
"from utils.parser_utils import parse_event_info, parse_season_calendar\n",
|
23 |
+
"import json\n",
|
24 |
+
"print(\"Successfully loaded in libraries\")"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"cell_type": "code",
|
29 |
+
"execution_count": 3,
|
30 |
+
"id": "b5d31092",
|
31 |
+
"metadata": {},
|
32 |
+
"outputs": [],
|
33 |
+
"source": [
|
34 |
+
"def make_request(api_action_string: str, debug: bool = False):\n",
|
35 |
+
" try: \n",
|
36 |
+
" response = urlopen(f\"https://api.openf1.org/v1/{api_action_string}\")\n",
|
37 |
+
" data = json.loads(response.read().decode('utf-8'))\n",
|
38 |
+
" if debug: pprint(data)\n",
|
39 |
+
" return data\n",
|
40 |
+
" except Exception as e:\n",
|
41 |
+
" print(f\"Error: {e}\")"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"cell_type": "code",
|
46 |
+
"execution_count": 5,
|
47 |
+
"id": "599aeec3",
|
48 |
+
"metadata": {},
|
49 |
+
"outputs": [
|
50 |
+
{
|
51 |
+
"name": "stdout",
|
52 |
+
"output_type": "stream",
|
53 |
+
"text": [
|
54 |
+
"[{'brake': 0,\n",
|
55 |
+
" 'date': '2023-09-15T13:08:19.923000+00:00',\n",
|
56 |
+
" 'driver_number': 55,\n",
|
57 |
+
" 'drs': 12,\n",
|
58 |
+
" 'meeting_key': 1219,\n",
|
59 |
+
" 'n_gear': 8,\n",
|
60 |
+
" 'rpm': 11141,\n",
|
61 |
+
" 'session_key': 9159,\n",
|
62 |
+
" 'speed': 315,\n",
|
63 |
+
" 'throttle': 99},\n",
|
64 |
+
" {'brake': 100,\n",
|
65 |
+
" 'date': '2023-09-15T13:35:41.808000+00:00',\n",
|
66 |
+
" 'driver_number': 55,\n",
|
67 |
+
" 'drs': 8,\n",
|
68 |
+
" 'meeting_key': 1219,\n",
|
69 |
+
" 'n_gear': 8,\n",
|
70 |
+
" 'rpm': 11023,\n",
|
71 |
+
" 'session_key': 9159,\n",
|
72 |
+
" 'speed': 315,\n",
|
73 |
+
" 'throttle': 57}]\n"
|
74 |
+
]
|
75 |
+
}
|
76 |
+
],
|
77 |
+
"source": [
|
78 |
+
"# Respone object for OpenF1\n",
|
79 |
+
"\n",
|
80 |
+
"response = urlopen('https://api.openf1.org/v1/car_data?driver_number=55&session_key=9159&speed>=315')\n",
|
81 |
+
"data = json.loads(response.read().decode('utf-8'))\n",
|
82 |
+
"pprint(data)"
|
83 |
+
]
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"cell_type": "code",
|
87 |
+
"execution_count": 19,
|
88 |
+
"id": "2b06a5c0",
|
89 |
+
"metadata": {},
|
90 |
+
"outputs": [
|
91 |
+
{
|
92 |
+
"data": {
|
93 |
+
"text/html": [
|
94 |
+
"<div>\n",
|
95 |
+
"<style scoped>\n",
|
96 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
97 |
+
" vertical-align: middle;\n",
|
98 |
+
" }\n",
|
99 |
+
"\n",
|
100 |
+
" .dataframe tbody tr th {\n",
|
101 |
+
" vertical-align: top;\n",
|
102 |
+
" }\n",
|
103 |
+
"\n",
|
104 |
+
" .dataframe thead th {\n",
|
105 |
+
" text-align: right;\n",
|
106 |
+
" }\n",
|
107 |
+
"</style>\n",
|
108 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
109 |
+
" <thead>\n",
|
110 |
+
" <tr style=\"text-align: right;\">\n",
|
111 |
+
" <th></th>\n",
|
112 |
+
" <th>meeting_key</th>\n",
|
113 |
+
" <th>session_key</th>\n",
|
114 |
+
" <th>location</th>\n",
|
115 |
+
" <th>date_start</th>\n",
|
116 |
+
" <th>date_end</th>\n",
|
117 |
+
" <th>session_type</th>\n",
|
118 |
+
" <th>session_name</th>\n",
|
119 |
+
" <th>country_key</th>\n",
|
120 |
+
" <th>country_code</th>\n",
|
121 |
+
" <th>country_name</th>\n",
|
122 |
+
" <th>circuit_key</th>\n",
|
123 |
+
" <th>circuit_short_name</th>\n",
|
124 |
+
" <th>gmt_offset</th>\n",
|
125 |
+
" <th>year</th>\n",
|
126 |
+
" </tr>\n",
|
127 |
+
" </thead>\n",
|
128 |
+
" <tbody>\n",
|
129 |
+
" <tr>\n",
|
130 |
+
" <th>0</th>\n",
|
131 |
+
" <td>1262</td>\n",
|
132 |
+
" <td>9964</td>\n",
|
133 |
+
" <td>Barcelona</td>\n",
|
134 |
+
" <td>2025-05-30T11:30:00+00:00</td>\n",
|
135 |
+
" <td>2025-05-30T12:30:00+00:00</td>\n",
|
136 |
+
" <td>Practice</td>\n",
|
137 |
+
" <td>Practice 1</td>\n",
|
138 |
+
" <td>1</td>\n",
|
139 |
+
" <td>ESP</td>\n",
|
140 |
+
" <td>Spain</td>\n",
|
141 |
+
" <td>15</td>\n",
|
142 |
+
" <td>Catalunya</td>\n",
|
143 |
+
" <td>02:00:00</td>\n",
|
144 |
+
" <td>2025</td>\n",
|
145 |
+
" </tr>\n",
|
146 |
+
" <tr>\n",
|
147 |
+
" <th>1</th>\n",
|
148 |
+
" <td>1262</td>\n",
|
149 |
+
" <td>9965</td>\n",
|
150 |
+
" <td>Barcelona</td>\n",
|
151 |
+
" <td>2025-05-30T15:00:00+00:00</td>\n",
|
152 |
+
" <td>2025-05-30T16:00:00+00:00</td>\n",
|
153 |
+
" <td>Practice</td>\n",
|
154 |
+
" <td>Practice 2</td>\n",
|
155 |
+
" <td>1</td>\n",
|
156 |
+
" <td>ESP</td>\n",
|
157 |
+
" <td>Spain</td>\n",
|
158 |
+
" <td>15</td>\n",
|
159 |
+
" <td>Catalunya</td>\n",
|
160 |
+
" <td>02:00:00</td>\n",
|
161 |
+
" <td>2025</td>\n",
|
162 |
+
" </tr>\n",
|
163 |
+
" </tbody>\n",
|
164 |
+
"</table>\n",
|
165 |
+
"</div>"
|
166 |
+
],
|
167 |
+
"text/plain": [
|
168 |
+
" meeting_key session_key location date_start \\\n",
|
169 |
+
"0 1262 9964 Barcelona 2025-05-30T11:30:00+00:00 \n",
|
170 |
+
"1 1262 9965 Barcelona 2025-05-30T15:00:00+00:00 \n",
|
171 |
+
"\n",
|
172 |
+
" date_end session_type session_name country_key \\\n",
|
173 |
+
"0 2025-05-30T12:30:00+00:00 Practice Practice 1 1 \n",
|
174 |
+
"1 2025-05-30T16:00:00+00:00 Practice Practice 2 1 \n",
|
175 |
+
"\n",
|
176 |
+
" country_code country_name circuit_key circuit_short_name gmt_offset year \n",
|
177 |
+
"0 ESP Spain 15 Catalunya 02:00:00 2025 \n",
|
178 |
+
"1 ESP Spain 15 Catalunya 02:00:00 2025 "
|
179 |
+
]
|
180 |
+
},
|
181 |
+
"execution_count": 19,
|
182 |
+
"metadata": {},
|
183 |
+
"output_type": "execute_result"
|
184 |
+
}
|
185 |
+
],
|
186 |
+
"source": [
|
187 |
+
"# Get session\n",
|
188 |
+
"respone = make_request(\"sessions?country_name=Spain&year=2025\", debug=False)\n",
|
189 |
+
"df = pd.DataFrame(respone)\n",
|
190 |
+
"df.head(n=2)\n"
|
191 |
+
]
|
192 |
+
},
|
193 |
+
{
|
194 |
+
"cell_type": "code",
|
195 |
+
"execution_count": 18,
|
196 |
+
"id": "f13e4f1a",
|
197 |
+
"metadata": {},
|
198 |
+
"outputs": [
|
199 |
+
{
|
200 |
+
"data": {
|
201 |
+
"text/html": [
|
202 |
+
"<div>\n",
|
203 |
+
"<style scoped>\n",
|
204 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
205 |
+
" vertical-align: middle;\n",
|
206 |
+
" }\n",
|
207 |
+
"\n",
|
208 |
+
" .dataframe tbody tr th {\n",
|
209 |
+
" vertical-align: top;\n",
|
210 |
+
" }\n",
|
211 |
+
"\n",
|
212 |
+
" .dataframe thead th {\n",
|
213 |
+
" text-align: right;\n",
|
214 |
+
" }\n",
|
215 |
+
"</style>\n",
|
216 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
217 |
+
" <thead>\n",
|
218 |
+
" <tr style=\"text-align: right;\">\n",
|
219 |
+
" <th></th>\n",
|
220 |
+
" <th>meeting_key</th>\n",
|
221 |
+
" <th>session_key</th>\n",
|
222 |
+
" <th>location</th>\n",
|
223 |
+
" <th>date_start</th>\n",
|
224 |
+
" <th>date_end</th>\n",
|
225 |
+
" <th>session_type</th>\n",
|
226 |
+
" <th>session_name</th>\n",
|
227 |
+
" <th>country_key</th>\n",
|
228 |
+
" <th>country_code</th>\n",
|
229 |
+
" <th>country_name</th>\n",
|
230 |
+
" <th>circuit_key</th>\n",
|
231 |
+
" <th>circuit_short_name</th>\n",
|
232 |
+
" <th>gmt_offset</th>\n",
|
233 |
+
" <th>year</th>\n",
|
234 |
+
" </tr>\n",
|
235 |
+
" </thead>\n",
|
236 |
+
" <tbody>\n",
|
237 |
+
" <tr>\n",
|
238 |
+
" <th>0</th>\n",
|
239 |
+
" <td>1262</td>\n",
|
240 |
+
" <td>9966</td>\n",
|
241 |
+
" <td>Barcelona</td>\n",
|
242 |
+
" <td>2025-05-31T10:30:00+00:00</td>\n",
|
243 |
+
" <td>2025-05-31T11:30:00+00:00</td>\n",
|
244 |
+
" <td>Practice</td>\n",
|
245 |
+
" <td>Practice 3</td>\n",
|
246 |
+
" <td>1</td>\n",
|
247 |
+
" <td>ESP</td>\n",
|
248 |
+
" <td>Spain</td>\n",
|
249 |
+
" <td>15</td>\n",
|
250 |
+
" <td>Catalunya</td>\n",
|
251 |
+
" <td>02:00:00</td>\n",
|
252 |
+
" <td>2025</td>\n",
|
253 |
+
" </tr>\n",
|
254 |
+
" </tbody>\n",
|
255 |
+
"</table>\n",
|
256 |
+
"</div>"
|
257 |
+
],
|
258 |
+
"text/plain": [
|
259 |
+
" meeting_key session_key location date_start \\\n",
|
260 |
+
"0 1262 9966 Barcelona 2025-05-31T10:30:00+00:00 \n",
|
261 |
+
"\n",
|
262 |
+
" date_end session_type session_name country_key \\\n",
|
263 |
+
"0 2025-05-31T11:30:00+00:00 Practice Practice 3 1 \n",
|
264 |
+
"\n",
|
265 |
+
" country_code country_name circuit_key circuit_short_name gmt_offset year \n",
|
266 |
+
"0 ESP Spain 15 Catalunya 02:00:00 2025 "
|
267 |
+
]
|
268 |
+
},
|
269 |
+
"execution_count": 18,
|
270 |
+
"metadata": {},
|
271 |
+
"output_type": "execute_result"
|
272 |
+
}
|
273 |
+
],
|
274 |
+
"source": [
|
275 |
+
"# Current session id (called during FP3 in Spain)\n",
|
276 |
+
"respone = make_request(\"sessions?session_key=latest\")\n",
|
277 |
+
"df = pd.DataFrame(respone)\n",
|
278 |
+
"df.head()"
|
279 |
+
]
|
280 |
+
},
|
281 |
+
{
|
282 |
+
"cell_type": "code",
|
283 |
+
"execution_count": null,
|
284 |
+
"id": "80a5699e",
|
285 |
+
"metadata": {},
|
286 |
+
"outputs": [
|
287 |
+
{
|
288 |
+
"data": {
|
289 |
+
"text/html": [
|
290 |
+
"<div>\n",
|
291 |
+
"<style scoped>\n",
|
292 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
293 |
+
" vertical-align: middle;\n",
|
294 |
+
" }\n",
|
295 |
+
"\n",
|
296 |
+
" .dataframe tbody tr th {\n",
|
297 |
+
" vertical-align: top;\n",
|
298 |
+
" }\n",
|
299 |
+
"\n",
|
300 |
+
" .dataframe thead th {\n",
|
301 |
+
" text-align: right;\n",
|
302 |
+
" }\n",
|
303 |
+
"</style>\n",
|
304 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
305 |
+
" <thead>\n",
|
306 |
+
" <tr style=\"text-align: right;\">\n",
|
307 |
+
" <th></th>\n",
|
308 |
+
" <th>meeting_key</th>\n",
|
309 |
+
" <th>session_key</th>\n",
|
310 |
+
" <th>location</th>\n",
|
311 |
+
" <th>date_start</th>\n",
|
312 |
+
" <th>date_end</th>\n",
|
313 |
+
" <th>session_type</th>\n",
|
314 |
+
" <th>session_name</th>\n",
|
315 |
+
" <th>country_key</th>\n",
|
316 |
+
" <th>country_code</th>\n",
|
317 |
+
" <th>country_name</th>\n",
|
318 |
+
" <th>circuit_key</th>\n",
|
319 |
+
" <th>circuit_short_name</th>\n",
|
320 |
+
" <th>gmt_offset</th>\n",
|
321 |
+
" <th>year</th>\n",
|
322 |
+
" </tr>\n",
|
323 |
+
" </thead>\n",
|
324 |
+
" <tbody>\n",
|
325 |
+
" <tr>\n",
|
326 |
+
" <th>0</th>\n",
|
327 |
+
" <td>1262</td>\n",
|
328 |
+
" <td>9966</td>\n",
|
329 |
+
" <td>Barcelona</td>\n",
|
330 |
+
" <td>2025-05-31T10:30:00+00:00</td>\n",
|
331 |
+
" <td>2025-05-31T11:30:00+00:00</td>\n",
|
332 |
+
" <td>Practice</td>\n",
|
333 |
+
" <td>Practice 3</td>\n",
|
334 |
+
" <td>1</td>\n",
|
335 |
+
" <td>ESP</td>\n",
|
336 |
+
" <td>Spain</td>\n",
|
337 |
+
" <td>15</td>\n",
|
338 |
+
" <td>Catalunya</td>\n",
|
339 |
+
" <td>02:00:00</td>\n",
|
340 |
+
" <td>2025</td>\n",
|
341 |
+
" </tr>\n",
|
342 |
+
" </tbody>\n",
|
343 |
+
"</table>\n",
|
344 |
+
"</div>"
|
345 |
+
],
|
346 |
+
"text/plain": [
|
347 |
+
" meeting_key session_key location date_start \\\n",
|
348 |
+
"0 1262 9966 Barcelona 2025-05-31T10:30:00+00:00 \n",
|
349 |
+
"\n",
|
350 |
+
" date_end session_type session_name country_key \\\n",
|
351 |
+
"0 2025-05-31T11:30:00+00:00 Practice Practice 3 1 \n",
|
352 |
+
"\n",
|
353 |
+
" country_code country_name circuit_key circuit_short_name gmt_offset year \n",
|
354 |
+
"0 ESP Spain 15 Catalunya 02:00:00 2025 "
|
355 |
+
]
|
356 |
+
},
|
357 |
+
"execution_count": 5,
|
358 |
+
"metadata": {},
|
359 |
+
"output_type": "execute_result"
|
360 |
+
}
|
361 |
+
],
|
362 |
+
"source": [
|
363 |
+
"# Current session id V2 (called between FP3 and Quali in Spain)\n",
|
364 |
+
"respone = make_request(\"sessions?session_key=latest\")\n",
|
365 |
+
"df = pd.DataFrame(respone)\n",
|
366 |
+
"df.head()\n",
|
367 |
+
"# session_key=latest points to the current or the most recent session NOT the upcoming one"
|
368 |
+
]
|
369 |
+
}
|
370 |
+
],
|
371 |
+
"metadata": {
|
372 |
+
"kernelspec": {
|
373 |
+
"display_name": "hackaton",
|
374 |
+
"language": "python",
|
375 |
+
"name": "python3"
|
376 |
+
},
|
377 |
+
"language_info": {
|
378 |
+
"codemirror_mode": {
|
379 |
+
"name": "ipython",
|
380 |
+
"version": 3
|
381 |
+
},
|
382 |
+
"file_extension": ".py",
|
383 |
+
"mimetype": "text/x-python",
|
384 |
+
"name": "python",
|
385 |
+
"nbconvert_exporter": "python",
|
386 |
+
"pygments_lexer": "ipython3",
|
387 |
+
"version": "3.12.9"
|
388 |
+
}
|
389 |
+
},
|
390 |
+
"nbformat": 4,
|
391 |
+
"nbformat_minor": 5
|
392 |
+
}
|
resources.py
DELETED
File without changes
|