File size: 34,900 Bytes
c502ece
1
2
{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Save fastf1 data a to SQL database\n","\n","Useful for generating quick reports during the race.\n"]},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[{"name":"stderr","output_type":"stream","text":["req         WARNING \tDEFAULT CACHE ENABLED! (1.04 GB) /Users/diegomaradona/Library/Caches/fastf1\n","core           INFO \tLoading data for Spanish Grand Prix - Practice 1 [v3.3.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 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","core        WARNING \tNo lap data for driver 27\n","core        WARNING \tFailed to perform lap accuracy check - all laps marked as inaccurate (driver 27)\n","req            INFO \tUsing cached data for car_data\n","req            INFO \tUsing cached data for position_data\n","req            INFO \tUsing cached data for weather_data\n","core           INFO \tFinished loading data for 21 drivers: ['1', '10', '11', '14', '16', '18', '2', '20', '22', '23', '24', '27', '3', '31', '4', '44', '50', '55', '63', '77', '81']\n"]}],"source":["import fastf1\n","from fastf1.core import Session\n","\n","GRAND_PRIX = 'Spain'\n","YEAR = 2024\n","SESSION = 'FP1'\n","\n","session = fastf1.get_session(YEAR, GRAND_PRIX, SESSION)\n","session.load(messages=False)"]},{"cell_type":"code","execution_count":3,"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>Time</th>\n","      <th>AirTemp</th>\n","      <th>Humidity</th>\n","      <th>Pressure</th>\n","      <th>Rainfall</th>\n","      <th>TrackTemp</th>\n","      <th>WindDirection</th>\n","      <th>WindSpeed</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>0 days 00:00:25.642000</td>\n","      <td>27.5</td>\n","      <td>37.0</td>\n","      <td>1004.3</td>\n","      <td>False</td>\n","      <td>46.3</td>\n","      <td>93</td>\n","      <td>0.0</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>0 days 00:01:25.662000</td>\n","      <td>27.5</td>\n","      <td>36.0</td>\n","      <td>1004.5</td>\n","      <td>False</td>\n","      <td>46.4</td>\n","      <td>0</td>\n","      <td>0.0</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>0 days 00:02:25.653000</td>\n","      <td>27.5</td>\n","      <td>36.0</td>\n","      <td>1004.5</td>\n","      <td>False</td>\n","      <td>47.3</td>\n","      <td>241</td>\n","      <td>2.3</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>0 days 00:03:25.660000</td>\n","      <td>27.6</td>\n","      <td>34.0</td>\n","      <td>1004.4</td>\n","      <td>False</td>\n","      <td>47.5</td>\n","      <td>226</td>\n","      <td>2.0</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>0 days 00:04:25.667000</td>\n","      <td>27.7</td>\n","      <td>35.0</td>\n","      <td>1004.4</td>\n","      <td>False</td>\n","      <td>46.4</td>\n","      <td>242</td>\n","      <td>2.0</td>\n","    </tr>\n","    <tr>\n","      <th>...</th>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","    </tr>\n","    <tr>\n","      <th>76</th>\n","      <td>0 days 01:16:25.846000</td>\n","      <td>28.3</td>\n","      <td>37.0</td>\n","      <td>1004.1</td>\n","      <td>False</td>\n","      <td>48.0</td>\n","      <td>107</td>\n","      <td>0.7</td>\n","    </tr>\n","    <tr>\n","      <th>77</th>\n","      <td>0 days 01:17:25.835000</td>\n","      <td>28.4</td>\n","      <td>36.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>47.8</td>\n","      <td>276</td>\n","      <td>1.0</td>\n","    </tr>\n","    <tr>\n","      <th>78</th>\n","      <td>0 days 01:18:25.832000</td>\n","      <td>28.5</td>\n","      <td>36.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>46.1</td>\n","      <td>230</td>\n","      <td>2.1</td>\n","    </tr>\n","    <tr>\n","      <th>79</th>\n","      <td>0 days 01:19:25.839000</td>\n","      <td>28.5</td>\n","      <td>37.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>46.2</td>\n","      <td>259</td>\n","      <td>1.7</td>\n","    </tr>\n","    <tr>\n","      <th>80</th>\n","      <td>0 days 01:20:25.848000</td>\n","      <td>28.5</td>\n","      <td>38.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>47.0</td>\n","      <td>200</td>\n","      <td>1.5</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>81 rows × 8 columns</p>\n","</div>"],"text/plain":["                     Time  AirTemp  Humidity  Pressure  Rainfall  TrackTemp  \\\n","0  0 days 00:00:25.642000     27.5      37.0    1004.3     False       46.3   \n","1  0 days 00:01:25.662000     27.5      36.0    1004.5     False       46.4   \n","2  0 days 00:02:25.653000     27.5      36.0    1004.5     False       47.3   \n","3  0 days 00:03:25.660000     27.6      34.0    1004.4     False       47.5   \n","4  0 days 00:04:25.667000     27.7      35.0    1004.4     False       46.4   \n","..                    ...      ...       ...       ...       ...        ...   \n","76 0 days 01:16:25.846000     28.3      37.0    1004.1     False       48.0   \n","77 0 days 01:17:25.835000     28.4      36.0    1004.2     False       47.8   \n","78 0 days 01:18:25.832000     28.5      36.0    1004.2     False       46.1   \n","79 0 days 01:19:25.839000     28.5      37.0    1004.2     False       46.2   \n","80 0 days 01:20:25.848000     28.5      38.0    1004.2     False       47.0   \n","\n","    WindDirection  WindSpeed  \n","0              93        0.0  \n","1               0        0.0  \n","2             241        2.3  \n","3             226        2.0  \n","4             242        2.0  \n","..            ...        ...  \n","76            107        0.7  \n","77            276        1.0  \n","78            230        2.1  \n","79            259        1.7  \n","80            200        1.5  \n","\n","[81 rows x 8 columns]"]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["session.weather_data"]},{"cell_type":"code","execution_count":4,"metadata":{},"outputs":[{"data":{"text/plain":["RoundNumber                                                   10\n","Country                                                    Spain\n","Location                                               Barcelona\n","OfficialEventName    FORMULA 1 ARAMCO GRAN PREMIO DE ESPAÑA 2024\n","EventDate                                    2024-06-23 00:00:00\n","EventName                                     Spanish Grand Prix\n","EventFormat                                         conventional\n","Session1                                              Practice 1\n","Session1Date                           2024-06-21 13:30:00+02:00\n","Session1DateUtc                              2024-06-21 11:30:00\n","Session2                                              Practice 2\n","Session2Date                           2024-06-21 17:00:00+02:00\n","Session2DateUtc                              2024-06-21 15:00:00\n","Session3                                              Practice 3\n","Session3Date                           2024-06-22 12:30:00+02:00\n","Session3DateUtc                              2024-06-22 10:30:00\n","Session4                                              Qualifying\n","Session4Date                           2024-06-22 16:00:00+02:00\n","Session4DateUtc                              2024-06-22 14:00:00\n","Session5                                                    Race\n","Session5Date                           2024-06-23 15:00:00+02:00\n","Session5DateUtc                              2024-06-23 13:00:00\n","F1ApiSupport                                                True\n","Name: 10, dtype: object"]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["session.event"]},{"cell_type":"code","execution_count":27,"metadata":{},"outputs":[],"source":["from pandas import DataFrame\n","from sqlalchemy import create_engine\n","from typing import cast\n","\n","\n","class Formula1Databases:\n","    \"\"\"\n","    Quickly fetch, extract features and save `fastf1` data to a SQL database\n","    \"\"\"\n","\n","    def __init__(self, session: Session) -> None:\n","        self.laps = session.laps.copy()\n","        self.weather_data = cast(DataFrame, session.weather_data).copy()\n","        self.telemetry = session.car_data.copy()\n","        self.event = session.event.copy()\n","        self._session_start_date = session.session_info['StartDate']\n","\n","        self.sql_engine = None\n","        self.df_laps: DataFrame | None = None\n","        self.df_weather: DataFrame | None = None\n","\n","        self._rename_laps_columns()\n","        self._rename_weather_columns()\n","\n","    def get_weather_df(self) -> DataFrame:\n","        df = self.weather_data.copy()\n","        df = self._calc_timedelta_from_session_start(df, ['time'])\n","\n","        self.df_weather = df\n","\n","        return df\n","\n","    def save_to_SQL_database(self, database_name: str):\n","        \"\"\"\n","        @param database_name str must contain `.db` at the end\n","        \"\"\"\n","        if not self.sql_engine:\n","            self.sql_engine = create_engine(f'sqlite:///{database_name}')\n","\n","        if self.df_laps is not None:\n","            self.df_laps.to_sql(name=\"Laps\", con=self.sql_engine)\n","            print(f'> table \"Laps\" saved to {database_name}')\n","\n","        if self.df_weather is not None:\n","            self.df_weather.to_sql(name=\"Weather\", con=self.sql_engine)\n","            print(f'> table \"Weather\" saved to {database_name}')\n","\n","    def get_laps_df(self) -> DataFrame:\n","        \"\"\"Return the `laps` data related to the given session as a pandas DataFrame\"\"\"\n","        df = self.laps.copy()\n","        df = self._convert_timedelta_to_seconds(df, ['lap_time',\n","                                                     'sector_1_time', 'sector_2_time', 'sector_3_time'])\n","        df = self._calc_timedelta_from_session_start(\n","            df, ['pit_out', 'pit_in', 'lap_end'])\n","        unused_columns = ['DeletedReason', 'FastF1Generated', 'IsAccurate', 'LapStartTime',\n","                          'Sector1SessionTime', 'Sector2SessionTime', 'Sector3SessionTime']\n","        df.drop(columns=[col for col in unused_columns if col in df.columns],\n","                inplace=True,\n","                axis=1)\n","\n","        self.df_laps = df\n","\n","        return df\n","\n","    def _rename_weather_columns(self) -> None:\n","        weather_new_column_names = {\n","            \"Time\": \"time\",\n","            \"AirTemp\": \"air_temperature_in_C\",\n","            \"Humidity\": \"relative_humidity_in_percents\",\n","            \"Pressure\": \"air_pressure_in_mbar\",\n","            \"Rainfall\": \"is_raining\",\n","            \"TrackTemp\": \"track_temperature_in_C\",\n","            \"WindDirection\": \"wind_direction_in_grads\",\n","            \"WindSpeed\": \"wind_speed_in_ms\"\n","        }\n","        self.weather_data.rename(\n","            columns=weather_new_column_names, inplace=True)\n","\n","    def _rename_laps_columns(self) -> None:\n","        laps_new_column_names = {\n","            'Driver': 'driver_name',\n","            'DriverNumber': 'driver_number',\n","            'LapNumber': 'lap_number',\n","            'Stint': 'stint',\n","            'SpeedI1': 'sector_1_speed_trap_in_km',\n","            'SpeedI2': 'sector_2_speed_trap_in_km',\n","            'SpeedFL': 'finish_line_speed_trap_in_km',\n","            'SpeedST': 'longest_strait_speed_trap_in_km',\n","            'IsPersonalBest': 'is_personal_best',\n","            'Compound': 'tyre_compound',\n","            'TyreLife': 'tyre_life_in_laps',\n","            'FreshTyre': 'is_fresh_tyre',\n","            'Position': 'position',\n","            'LapTime': 'lap_time',\n","            'Sector1Time': 'sector_1_time',\n","            'Sector2Time': 'sector_2_time',\n","            'Sector3Time': 'sector_3_time',\n","            'LapStartDate': 'lap_start_datetime',\n","            'Time': 'lap_end',\n","            'PitInTime': 'pit_in',\n","            'PitOutTime': 'pit_out',\n","            'Team': 'team_name',\n","            'TrackStatus': 'track_status',\n","            'Deleted': 'is_lap_deleted'\n","        }\n","        self.laps.rename(columns=laps_new_column_names, inplace=True)\n","\n","    def _convert_timedelta_to_seconds(self, old_df: DataFrame, columns: list[str]) -> DataFrame:\n","        df = old_df.copy()\n","\n","        for col in columns:\n","            if not col in df.columns:\n","                continue\n","            df[col + '_in_seconds'] = df[col].dt.total_seconds()\n","            df.drop(columns=[col], inplace=True, axis=1)\n","\n","        return df\n","\n","    def _calc_timedelta_from_session_start(self, old_df: DataFrame, columns: list[str]) -> DataFrame:\n","        df = old_df.copy()\n","\n","        for col in columns:\n","            if not col in df.columns:\n","                continue\n","            df[col + '_datetime'] = self._session_start_date + df[col]\n","            df.drop(columns=[col], inplace=True, axis=1)\n","\n","        return df"]},{"cell_type":"code","execution_count":28,"metadata":{},"outputs":[],"source":["spanish_session = Formula1Databases(session=session)"]},{"cell_type":"code","execution_count":22,"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>driver_name</th>\n","      <th>driver_number</th>\n","      <th>lap_number</th>\n","      <th>stint</th>\n","      <th>sector_1_speed_trap_in_km</th>\n","      <th>sector_2_speed_trap_in_km</th>\n","      <th>finish_line_speed_trap_in_km</th>\n","      <th>longest_strait_speed_trap_in_km</th>\n","      <th>is_personal_best</th>\n","      <th>tyre_compound</th>\n","      <th>...</th>\n","      <th>track_status</th>\n","      <th>position</th>\n","      <th>is_lap_deleted</th>\n","      <th>lap_time_in_seconds</th>\n","      <th>sector_1_time_in_seconds</th>\n","      <th>sector_2_time_in_seconds</th>\n","      <th>sector_3_time_in_seconds</th>\n","      <th>pit_out_datetime</th>\n","      <th>pit_in_datetime</th>\n","      <th>lap_end_datetime</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>VER</td>\n","      <td>1</td>\n","      <td>1.0</td>\n","      <td>1.0</td>\n","      <td>263.0</td>\n","      <td>213.0</td>\n","      <td>282.0</td>\n","      <td>225.0</td>\n","      <td>False</td>\n","      <td>HARD</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>NaN</td>\n","      <td>NaN</td>\n","      <td>35.704</td>\n","      <td>26.353</td>\n","      <td>2024-06-21 13:47:35.427</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 13:49:02.676</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>VER</td>\n","      <td>1</td>\n","      <td>2.0</td>\n","      <td>1.0</td>\n","      <td>283.0</td>\n","      <td>287.0</td>\n","      <td>281.0</td>\n","      <td>315.0</td>\n","      <td>True</td>\n","      <td>HARD</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>76.254</td>\n","      <td>22.500</td>\n","      <td>30.770</td>\n","      <td>22.984</td>\n","      <td>NaT</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 13:50:18.930</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>VER</td>\n","      <td>1</td>\n","      <td>3.0</td>\n","      <td>1.0</td>\n","      <td>183.0</td>\n","      <td>174.0</td>\n","      <td>NaN</td>\n","      <td>148.0</td>\n","      <td>False</td>\n","      <td>HARD</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>113.995</td>\n","      <td>37.089</td>\n","      <td>43.413</td>\n","      <td>33.493</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 13:52:10.252</td>\n","      <td>2024-06-21 13:52:12.925</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>VER</td>\n","      <td>1</td>\n","      <td>4.0</td>\n","      <td>2.0</td>\n","      <td>87.0</td>\n","      <td>143.0</td>\n","      <td>286.0</td>\n","      <td>223.0</td>\n","      <td>False</td>\n","      <td>HARD</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>129.370</td>\n","      <td>53.819</td>\n","      <td>50.332</td>\n","      <td>25.219</td>\n","      <td>2024-06-21 13:52:33.412</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 13:54:22.295</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>VER</td>\n","      <td>1</td>\n","      <td>5.0</td>\n","      <td>2.0</td>\n","      <td>288.0</td>\n","      <td>303.0</td>\n","      <td>284.0</td>\n","      <td>317.0</td>\n","      <td>True</td>\n","      <td>HARD</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>75.424</td>\n","      <td>22.229</td>\n","      <td>30.458</td>\n","      <td>22.737</td>\n","      <td>NaT</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 13:55:37.719</td>\n","    </tr>\n","    <tr>\n","      <th>...</th>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","    </tr>\n","    <tr>\n","      <th>535</th>\n","      <td>PIA</td>\n","      <td>81</td>\n","      <td>25.0</td>\n","      <td>6.0</td>\n","      <td>272.0</td>\n","      <td>262.0</td>\n","      <td>NaN</td>\n","      <td>304.0</td>\n","      <td>False</td>\n","      <td>MEDIUM</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>83.305</td>\n","      <td>23.511</td>\n","      <td>31.976</td>\n","      <td>27.818</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 14:41:44.036</td>\n","      <td>2024-06-21 14:41:46.718</td>\n","    </tr>\n","    <tr>\n","      <th>536</th>\n","      <td>PIA</td>\n","      <td>81</td>\n","      <td>26.0</td>\n","      <td>7.0</td>\n","      <td>268.0</td>\n","      <td>258.0</td>\n","      <td>282.0</td>\n","      <td>250.0</td>\n","      <td>False</td>\n","      <td>SOFT</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>103.611</td>\n","      <td>47.185</td>\n","      <td>32.579</td>\n","      <td>23.847</td>\n","      <td>2024-06-21 14:42:11.042</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 14:43:30.329</td>\n","    </tr>\n","    <tr>\n","      <th>537</th>\n","      <td>PIA</td>\n","      <td>81</td>\n","      <td>27.0</td>\n","      <td>7.0</td>\n","      <td>272.0</td>\n","      <td>253.0</td>\n","      <td>282.0</td>\n","      <td>313.0</td>\n","      <td>False</td>\n","      <td>SOFT</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>79.723</td>\n","      <td>23.062</td>\n","      <td>32.377</td>\n","      <td>24.284</td>\n","      <td>NaT</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 14:44:50.052</td>\n","    </tr>\n","    <tr>\n","      <th>538</th>\n","      <td>PIA</td>\n","      <td>81</td>\n","      <td>28.0</td>\n","      <td>7.0</td>\n","      <td>207.0</td>\n","      <td>177.0</td>\n","      <td>40.0</td>\n","      <td>263.0</td>\n","      <td>False</td>\n","      <td>SOFT</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>109.685</td>\n","      <td>28.978</td>\n","      <td>38.690</td>\n","      <td>42.017</td>\n","      <td>NaT</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 14:46:39.737</td>\n","    </tr>\n","    <tr>\n","      <th>539</th>\n","      <td>PIA</td>\n","      <td>81</td>\n","      <td>29.0</td>\n","      <td>7.0</td>\n","      <td>159.0</td>\n","      <td>230.0</td>\n","      <td>NaN</td>\n","      <td>283.0</td>\n","      <td>False</td>\n","      <td>SOFT</td>\n","      <td>...</td>\n","      <td>1</td>\n","      <td>NaN</td>\n","      <td>None</td>\n","      <td>129.879</td>\n","      <td>50.085</td>\n","      <td>34.877</td>\n","      <td>44.917</td>\n","      <td>NaT</td>\n","      <td>2024-06-21 14:48:46.331</td>\n","      <td>2024-06-21 14:48:49.616</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>540 rows × 24 columns</p>\n","</div>"],"text/plain":["    driver_name driver_number  lap_number  stint  sector_1_speed_trap_in_km  \\\n","0           VER             1         1.0    1.0                      263.0   \n","1           VER             1         2.0    1.0                      283.0   \n","2           VER             1         3.0    1.0                      183.0   \n","3           VER             1         4.0    2.0                       87.0   \n","4           VER             1         5.0    2.0                      288.0   \n","..          ...           ...         ...    ...                        ...   \n","535         PIA            81        25.0    6.0                      272.0   \n","536         PIA            81        26.0    7.0                      268.0   \n","537         PIA            81        27.0    7.0                      272.0   \n","538         PIA            81        28.0    7.0                      207.0   \n","539         PIA            81        29.0    7.0                      159.0   \n","\n","     sector_2_speed_trap_in_km  finish_line_speed_trap_in_km  \\\n","0                        213.0                         282.0   \n","1                        287.0                         281.0   \n","2                        174.0                           NaN   \n","3                        143.0                         286.0   \n","4                        303.0                         284.0   \n","..                         ...                           ...   \n","535                      262.0                           NaN   \n","536                      258.0                         282.0   \n","537                      253.0                         282.0   \n","538                      177.0                          40.0   \n","539                      230.0                           NaN   \n","\n","     longest_strait_speed_trap_in_km  is_personal_best tyre_compound  ...  \\\n","0                              225.0             False          HARD  ...   \n","1                              315.0              True          HARD  ...   \n","2                              148.0             False          HARD  ...   \n","3                              223.0             False          HARD  ...   \n","4                              317.0              True          HARD  ...   \n","..                               ...               ...           ...  ...   \n","535                            304.0             False        MEDIUM  ...   \n","536                            250.0             False          SOFT  ...   \n","537                            313.0             False          SOFT  ...   \n","538                            263.0             False          SOFT  ...   \n","539                            283.0             False          SOFT  ...   \n","\n","     track_status  position is_lap_deleted lap_time_in_seconds  \\\n","0               1       NaN           None                 NaN   \n","1               1       NaN           None              76.254   \n","2               1       NaN           None             113.995   \n","3               1       NaN           None             129.370   \n","4               1       NaN           None              75.424   \n","..            ...       ...            ...                 ...   \n","535             1       NaN           None              83.305   \n","536             1       NaN           None             103.611   \n","537             1       NaN           None              79.723   \n","538             1       NaN           None             109.685   \n","539             1       NaN           None             129.879   \n","\n","    sector_1_time_in_seconds  sector_2_time_in_seconds  \\\n","0                        NaN                    35.704   \n","1                     22.500                    30.770   \n","2                     37.089                    43.413   \n","3                     53.819                    50.332   \n","4                     22.229                    30.458   \n","..                       ...                       ...   \n","535                   23.511                    31.976   \n","536                   47.185                    32.579   \n","537                   23.062                    32.377   \n","538                   28.978                    38.690   \n","539                   50.085                    34.877   \n","\n","    sector_3_time_in_seconds        pit_out_datetime         pit_in_datetime  \\\n","0                     26.353 2024-06-21 13:47:35.427                     NaT   \n","1                     22.984                     NaT                     NaT   \n","2                     33.493                     NaT 2024-06-21 13:52:10.252   \n","3                     25.219 2024-06-21 13:52:33.412                     NaT   \n","4                     22.737                     NaT                     NaT   \n","..                       ...                     ...                     ...   \n","535                   27.818                     NaT 2024-06-21 14:41:44.036   \n","536                   23.847 2024-06-21 14:42:11.042                     NaT   \n","537                   24.284                     NaT                     NaT   \n","538                   42.017                     NaT                     NaT   \n","539                   44.917                     NaT 2024-06-21 14:48:46.331   \n","\n","           lap_end_datetime  \n","0   2024-06-21 13:49:02.676  \n","1   2024-06-21 13:50:18.930  \n","2   2024-06-21 13:52:12.925  \n","3   2024-06-21 13:54:22.295  \n","4   2024-06-21 13:55:37.719  \n","..                      ...  \n","535 2024-06-21 14:41:46.718  \n","536 2024-06-21 14:43:30.329  \n","537 2024-06-21 14:44:50.052  \n","538 2024-06-21 14:46:39.737  \n","539 2024-06-21 14:48:49.616  \n","\n","[540 rows x 24 columns]"]},"execution_count":22,"metadata":{},"output_type":"execute_result"}],"source":["\n","spanish_session.get_laps_df()"]},{"cell_type":"code","execution_count":17,"metadata":{},"outputs":[],"source":["spanish_session.save_to_SQL_database(\"Spanish_Session\")"]},{"cell_type":"code","execution_count":29,"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>air_temperature_in_C</th>\n","      <th>relative_humidity_in_percents</th>\n","      <th>air_pressure_in_mbar</th>\n","      <th>is_raining</th>\n","      <th>track_temperature_in_C</th>\n","      <th>wind_direction_in_grads</th>\n","      <th>wind_speed_in_ms</th>\n","      <th>time_datetime</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>27.5</td>\n","      <td>37.0</td>\n","      <td>1004.3</td>\n","      <td>False</td>\n","      <td>46.3</td>\n","      <td>93</td>\n","      <td>0.0</td>\n","      <td>2024-06-21 13:30:25.642</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>27.5</td>\n","      <td>36.0</td>\n","      <td>1004.5</td>\n","      <td>False</td>\n","      <td>46.4</td>\n","      <td>0</td>\n","      <td>0.0</td>\n","      <td>2024-06-21 13:31:25.662</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>27.5</td>\n","      <td>36.0</td>\n","      <td>1004.5</td>\n","      <td>False</td>\n","      <td>47.3</td>\n","      <td>241</td>\n","      <td>2.3</td>\n","      <td>2024-06-21 13:32:25.653</td>\n","    </tr>\n","    <tr>\n","      <th>3</th>\n","      <td>27.6</td>\n","      <td>34.0</td>\n","      <td>1004.4</td>\n","      <td>False</td>\n","      <td>47.5</td>\n","      <td>226</td>\n","      <td>2.0</td>\n","      <td>2024-06-21 13:33:25.660</td>\n","    </tr>\n","    <tr>\n","      <th>4</th>\n","      <td>27.7</td>\n","      <td>35.0</td>\n","      <td>1004.4</td>\n","      <td>False</td>\n","      <td>46.4</td>\n","      <td>242</td>\n","      <td>2.0</td>\n","      <td>2024-06-21 13:34:25.667</td>\n","    </tr>\n","    <tr>\n","      <th>...</th>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","      <td>...</td>\n","    </tr>\n","    <tr>\n","      <th>76</th>\n","      <td>28.3</td>\n","      <td>37.0</td>\n","      <td>1004.1</td>\n","      <td>False</td>\n","      <td>48.0</td>\n","      <td>107</td>\n","      <td>0.7</td>\n","      <td>2024-06-21 14:46:25.846</td>\n","    </tr>\n","    <tr>\n","      <th>77</th>\n","      <td>28.4</td>\n","      <td>36.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>47.8</td>\n","      <td>276</td>\n","      <td>1.0</td>\n","      <td>2024-06-21 14:47:25.835</td>\n","    </tr>\n","    <tr>\n","      <th>78</th>\n","      <td>28.5</td>\n","      <td>36.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>46.1</td>\n","      <td>230</td>\n","      <td>2.1</td>\n","      <td>2024-06-21 14:48:25.832</td>\n","    </tr>\n","    <tr>\n","      <th>79</th>\n","      <td>28.5</td>\n","      <td>37.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>46.2</td>\n","      <td>259</td>\n","      <td>1.7</td>\n","      <td>2024-06-21 14:49:25.839</td>\n","    </tr>\n","    <tr>\n","      <th>80</th>\n","      <td>28.5</td>\n","      <td>38.0</td>\n","      <td>1004.2</td>\n","      <td>False</td>\n","      <td>47.0</td>\n","      <td>200</td>\n","      <td>1.5</td>\n","      <td>2024-06-21 14:50:25.848</td>\n","    </tr>\n","  </tbody>\n","</table>\n","<p>81 rows × 8 columns</p>\n","</div>"],"text/plain":["    air_temperature_in_C  relative_humidity_in_percents  air_pressure_in_mbar  \\\n","0                   27.5                           37.0                1004.3   \n","1                   27.5                           36.0                1004.5   \n","2                   27.5                           36.0                1004.5   \n","3                   27.6                           34.0                1004.4   \n","4                   27.7                           35.0                1004.4   \n","..                   ...                            ...                   ...   \n","76                  28.3                           37.0                1004.1   \n","77                  28.4                           36.0                1004.2   \n","78                  28.5                           36.0                1004.2   \n","79                  28.5                           37.0                1004.2   \n","80                  28.5                           38.0                1004.2   \n","\n","    is_raining  track_temperature_in_C  wind_direction_in_grads  \\\n","0        False                    46.3                       93   \n","1        False                    46.4                        0   \n","2        False                    47.3                      241   \n","3        False                    47.5                      226   \n","4        False                    46.4                      242   \n","..         ...                     ...                      ...   \n","76       False                    48.0                      107   \n","77       False                    47.8                      276   \n","78       False                    46.1                      230   \n","79       False                    46.2                      259   \n","80       False                    47.0                      200   \n","\n","    wind_speed_in_ms           time_datetime  \n","0                0.0 2024-06-21 13:30:25.642  \n","1                0.0 2024-06-21 13:31:25.662  \n","2                2.3 2024-06-21 13:32:25.653  \n","3                2.0 2024-06-21 13:33:25.660  \n","4                2.0 2024-06-21 13:34:25.667  \n","..               ...                     ...  \n","76               0.7 2024-06-21 14:46:25.846  \n","77               1.0 2024-06-21 14:47:25.835  \n","78               2.1 2024-06-21 14:48:25.832  \n","79               1.7 2024-06-21 14:49:25.839  \n","80               1.5 2024-06-21 14:50:25.848  \n","\n","[81 rows x 8 columns]"]},"execution_count":29,"metadata":{},"output_type":"execute_result"}],"source":["spanish_session.get_weather_df()"]}],"metadata":{"kernelspec":{"display_name":"formula-1","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.11.0"}},"nbformat":4,"nbformat_minor":2}