File size: 19,064 Bytes
81c6a41 6269c32 81c6a41 89c9126 81c6a41 89c9126 97a44d4 c6542ed 89c9126 c6542ed 89c9126 6269c32 c6542ed 6269c32 c6542ed 97a44d4 89c9126 c6542ed 89c9126 97a44d4 89c9126 6269c32 c6542ed 6269c32 81c6a41 89c9126 81c6a41 89c9126 81c6a41 |
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"id": "b7d2515e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Successfully loaded in libraries\n"
]
}
],
"source": [
"import fastf1\n",
"import pandas as pd\n",
"from urllib.request import urlopen\n",
"from pprint import pprint\n",
"from utils.parser_utils import parse_event_info, parse_season_calendar\n",
"import json\n",
"print(\"Successfully loaded in libraries\")"
]
},
{
"cell_type": "markdown",
"id": "81c06a3f",
"metadata": {},
"source": [
"# FastF1"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "352270a0",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"core INFO \tLoading data for Japanese Grand Prix - Race [v3.5.3]\n",
"req INFO \tUsing cached data for session_info\n",
"req INFO \tUsing cached data for driver_info\n",
"req INFO \tUsing cached data for session_status_data\n",
"req INFO \tUsing cached data for lap_count\n",
"req INFO \tUsing cached data for track_status_data\n",
"req INFO \tUsing cached data for _extended_timing_data\n",
"req INFO \tUsing cached data for timing_app_data\n",
"core INFO \tProcessing timing data...\n",
"req INFO \tUsing cached data for weather_data\n",
"req INFO \tUsing cached data for race_control_messages\n",
"core INFO \tFinished loading data for 20 drivers: ['1', '4', '81', '16', '63', '12', '44', '6', '23', '87', '14', '22', '10', '55', '7', '27', '30', '31', '5', '18']\n",
"data WARNING \tFailed to generate marker distance information: telemetry data has not been loaded\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CircuitInfo(corners= X Y Number Letter Angle Distance\n",
"0 5954.595977 -6043.797284 1 -359.859187 NaN\n",
"1 5411.746105 -6985.870033 2 -81.205284 NaN\n",
"2 3770.348048 -5370.929541 3 -131.304090 NaN\n",
"3 2554.616588 -4969.478669 4 -304.343564 NaN\n",
"4 1863.122660 -3634.685488 5 -131.398389 NaN\n",
"5 343.857125 -3137.336941 6 -311.879680 NaN\n",
"6 -615.746076 -519.819724 7 -106.459045 NaN\n",
"7 -3936.654450 -2323.145349 8 -57.888888 NaN\n",
"8 -5453.049412 -2538.215879 9 -110.431844 NaN\n",
"9 -6229.209841 449.908978 10 -1.787031 NaN\n",
"10 -5964.645828 1876.742727 11 -126.423013 NaN\n",
"11 -7552.525448 119.000613 12 -237.277364 NaN\n",
"12 -12335.806433 3018.433431 13 -125.951757 NaN\n",
"13 -13731.830146 2733.425582 14 -201.694648 NaN\n",
"14 -4974.205293 -1679.808731 15 -254.712390 NaN\n",
"15 -1819.327067 517.589808 16 -293.925016 NaN\n",
"16 -1184.012753 429.700268 17 -50.270393 NaN\n",
"17 332.706500 616.534453 18 -291.606210 NaN,\n",
" marshal_lights= X Y Number Letter Angle Distance\n",
"0 1690.855950 -638.228799 1 -319.688225 NaN\n",
"1 5783.596809 -5462.065134 2 -326.487422 NaN\n",
"2 4811.098103 -6861.098123 3 -135.071247 NaN\n",
"3 3613.521255 -5257.354862 4 -300.361781 NaN\n",
"4 1815.810860 -3592.898831 5 -297.867821 NaN\n",
"5 198.335929 -2984.219502 6 -140.707699 NaN\n",
"6 298.955074 -1117.388942 7 -335.948534 NaN\n",
"7 -1697.196338 -420.240677 8 -260.369093 NaN\n",
"8 -4279.213479 -2448.991996 9 -80.383553 NaN\n",
"9 -5705.360349 -2278.848846 10 -161.756206 NaN\n",
"10 -6223.720506 612.148266 11 -2.135760 NaN\n",
"11 -6037.625361 1929.727809 12 -295.371985 NaN\n",
"12 -7620.649284 74.874949 13 -58.450233 NaN\n",
"13 -10755.257143 583.334425 14 -126.874237 NaN\n",
"14 -12499.786963 3090.369959 15 -289.937350 NaN\n",
"15 -13787.721653 2369.387645 16 -170.487671 NaN\n",
"16 -12375.140308 938.000955 17 -122.280757 NaN\n",
"17 -10189.779019 -164.943254 18 -109.977438 NaN\n",
"18 -7499.143789 -1076.181403 19 -109.130546 NaN\n",
"19 -4733.288295 -1590.501071 20 -68.544674 NaN\n",
"20 -1984.075069 530.759537 21 -258.330855 NaN\n",
"21 -86.348618 755.041276 22 -284.607743 NaN,\n",
" marshal_sectors= X Y Number Letter Angle Distance\n",
"0 1749.509891 -706.732882 1 -319.461645 NaN\n",
"1 5890.822450 -5655.136054 2 -343.938801 NaN\n",
"2 4982.553266 -6958.944675 3 -107.988939 NaN\n",
"3 3770.348048 -5370.929541 4 -131.463504 NaN\n",
"4 1886.764195 -3655.599156 5 -311.621063 NaN\n",
"5 353.981975 -3146.309291 6 -311.728322 NaN\n",
"6 344.825980 -1220.364548 7 -337.684641 NaN\n",
"7 -1536.171947 -402.081185 8 -268.084725 NaN\n",
"8 -4239.222910 -2442.075986 9 -80.307903 NaN\n",
"9 -5607.722824 -2440.304958 10 -137.786652 NaN\n",
"10 -6229.209841 449.908978 11 -2.314662 NaN\n",
"11 -6082.609487 1931.331580 12 -271.786528 NaN\n",
"12 -7563.880972 111.645273 13 -237.193746 NaN\n",
"13 -10809.400279 623.878159 14 -306.809173 NaN\n",
"14 -12457.333265 3075.178205 15 -289.922395 NaN\n",
"15 -13782.934850 2342.759685 16 -169.348189 NaN\n",
"16 -12386.562623 945.247835 17 -122.394556 NaN\n",
"17 -10177.060736 -169.562715 18 -109.850944 NaN\n",
"18 -7417.936277 -1103.488715 19 -108.299236 NaN\n",
"19 -4779.517092 -1608.478900 20 -68.926520 NaN\n",
"20 -1948.165854 534.110177 21 -85.058804 NaN\n",
"21 53.048886 717.912969 22 -289.674903 NaN,\n",
" rotation=49.0)\n"
]
}
],
"source": [
"session = fastf1.get_session(2025, 3, \"R\")\n",
"session.load(telemetry=False)\n",
"circuit_info = session.get_circuit_info()\n",
"pprint(circuit_info)"
]
},
{
"cell_type": "markdown",
"id": "a5047955",
"metadata": {},
"source": [
"# OpenF1"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b5d31092",
"metadata": {},
"outputs": [],
"source": [
"def make_request(api_action_string: str, debug: bool = False):\n",
" try: \n",
" response = urlopen(f\"https://api.openf1.org/v1/{api_action_string}\")\n",
" data = json.loads(response.read().decode('utf-8'))\n",
" if debug: pprint(data)\n",
" return data\n",
" except Exception as e:\n",
" print(f\"Error: {e}\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "599aeec3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'brake': 0,\n",
" 'date': '2023-09-15T13:08:19.923000+00:00',\n",
" 'driver_number': 55,\n",
" 'drs': 12,\n",
" 'meeting_key': 1219,\n",
" 'n_gear': 8,\n",
" 'rpm': 11141,\n",
" 'session_key': 9159,\n",
" 'speed': 315,\n",
" 'throttle': 99},\n",
" {'brake': 100,\n",
" 'date': '2023-09-15T13:35:41.808000+00:00',\n",
" 'driver_number': 55,\n",
" 'drs': 8,\n",
" 'meeting_key': 1219,\n",
" 'n_gear': 8,\n",
" 'rpm': 11023,\n",
" 'session_key': 9159,\n",
" 'speed': 315,\n",
" 'throttle': 57}]\n"
]
}
],
"source": [
"# Respone object for OpenF1\n",
"\n",
"response = urlopen('https://api.openf1.org/v1/car_data?driver_number=55&session_key=9159&speed>=315')\n",
"data = json.loads(response.read().decode('utf-8'))\n",
"pprint(data)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "2b06a5c0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>meeting_key</th>\n",
" <th>session_key</th>\n",
" <th>location</th>\n",
" <th>date_start</th>\n",
" <th>date_end</th>\n",
" <th>session_type</th>\n",
" <th>session_name</th>\n",
" <th>country_key</th>\n",
" <th>country_code</th>\n",
" <th>country_name</th>\n",
" <th>circuit_key</th>\n",
" <th>circuit_short_name</th>\n",
" <th>gmt_offset</th>\n",
" <th>year</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1262</td>\n",
" <td>9964</td>\n",
" <td>Barcelona</td>\n",
" <td>2025-05-30T11:30:00+00:00</td>\n",
" <td>2025-05-30T12:30:00+00:00</td>\n",
" <td>Practice</td>\n",
" <td>Practice 1</td>\n",
" <td>1</td>\n",
" <td>ESP</td>\n",
" <td>Spain</td>\n",
" <td>15</td>\n",
" <td>Catalunya</td>\n",
" <td>02:00:00</td>\n",
" <td>2025</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1262</td>\n",
" <td>9965</td>\n",
" <td>Barcelona</td>\n",
" <td>2025-05-30T15:00:00+00:00</td>\n",
" <td>2025-05-30T16:00:00+00:00</td>\n",
" <td>Practice</td>\n",
" <td>Practice 2</td>\n",
" <td>1</td>\n",
" <td>ESP</td>\n",
" <td>Spain</td>\n",
" <td>15</td>\n",
" <td>Catalunya</td>\n",
" <td>02:00:00</td>\n",
" <td>2025</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" meeting_key session_key location date_start \\\n",
"0 1262 9964 Barcelona 2025-05-30T11:30:00+00:00 \n",
"1 1262 9965 Barcelona 2025-05-30T15:00:00+00:00 \n",
"\n",
" date_end session_type session_name country_key \\\n",
"0 2025-05-30T12:30:00+00:00 Practice Practice 1 1 \n",
"1 2025-05-30T16:00:00+00:00 Practice Practice 2 1 \n",
"\n",
" country_code country_name circuit_key circuit_short_name gmt_offset year \n",
"0 ESP Spain 15 Catalunya 02:00:00 2025 \n",
"1 ESP Spain 15 Catalunya 02:00:00 2025 "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get session\n",
"respone = make_request(\"sessions?country_name=Spain&year=2025\", debug=False)\n",
"df = pd.DataFrame(respone)\n",
"df.head(n=2)\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "f13e4f1a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>meeting_key</th>\n",
" <th>session_key</th>\n",
" <th>location</th>\n",
" <th>date_start</th>\n",
" <th>date_end</th>\n",
" <th>session_type</th>\n",
" <th>session_name</th>\n",
" <th>country_key</th>\n",
" <th>country_code</th>\n",
" <th>country_name</th>\n",
" <th>circuit_key</th>\n",
" <th>circuit_short_name</th>\n",
" <th>gmt_offset</th>\n",
" <th>year</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1262</td>\n",
" <td>9966</td>\n",
" <td>Barcelona</td>\n",
" <td>2025-05-31T10:30:00+00:00</td>\n",
" <td>2025-05-31T11:30:00+00:00</td>\n",
" <td>Practice</td>\n",
" <td>Practice 3</td>\n",
" <td>1</td>\n",
" <td>ESP</td>\n",
" <td>Spain</td>\n",
" <td>15</td>\n",
" <td>Catalunya</td>\n",
" <td>02:00:00</td>\n",
" <td>2025</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" meeting_key session_key location date_start \\\n",
"0 1262 9966 Barcelona 2025-05-31T10:30:00+00:00 \n",
"\n",
" date_end session_type session_name country_key \\\n",
"0 2025-05-31T11:30:00+00:00 Practice Practice 3 1 \n",
"\n",
" country_code country_name circuit_key circuit_short_name gmt_offset year \n",
"0 ESP Spain 15 Catalunya 02:00:00 2025 "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Current session id (called during FP3 in Spain)\n",
"respone = make_request(\"sessions?session_key=latest\")\n",
"df = pd.DataFrame(respone)\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80a5699e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>meeting_key</th>\n",
" <th>session_key</th>\n",
" <th>location</th>\n",
" <th>date_start</th>\n",
" <th>date_end</th>\n",
" <th>session_type</th>\n",
" <th>session_name</th>\n",
" <th>country_key</th>\n",
" <th>country_code</th>\n",
" <th>country_name</th>\n",
" <th>circuit_key</th>\n",
" <th>circuit_short_name</th>\n",
" <th>gmt_offset</th>\n",
" <th>year</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1262</td>\n",
" <td>9966</td>\n",
" <td>Barcelona</td>\n",
" <td>2025-05-31T10:30:00+00:00</td>\n",
" <td>2025-05-31T11:30:00+00:00</td>\n",
" <td>Practice</td>\n",
" <td>Practice 3</td>\n",
" <td>1</td>\n",
" <td>ESP</td>\n",
" <td>Spain</td>\n",
" <td>15</td>\n",
" <td>Catalunya</td>\n",
" <td>02:00:00</td>\n",
" <td>2025</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" meeting_key session_key location date_start \\\n",
"0 1262 9966 Barcelona 2025-05-31T10:30:00+00:00 \n",
"\n",
" date_end session_type session_name country_key \\\n",
"0 2025-05-31T11:30:00+00:00 Practice Practice 3 1 \n",
"\n",
" country_code country_name circuit_key circuit_short_name gmt_offset year \n",
"0 ESP Spain 15 Catalunya 02:00:00 2025 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Current session id V2 (called between FP3 and Quali in Spain)\n",
"respone = make_request(\"sessions?session_key=latest\")\n",
"df = pd.DataFrame(respone)\n",
"df.head()\n",
"# session_key=latest points to the current or the most recent session NOT the upcoming one"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "hackaton",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|