chore(formula1_databases): add print statements as a form of feedback
Browse files
notebooks/formula1_databases.py
CHANGED
@@ -4,9 +4,16 @@ import pandas as pd
|
|
4 |
from datetime import datetime
|
5 |
from fastf1.core import Session
|
6 |
import fastf1
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
class FastF1ToSQL:
|
|
|
|
|
|
|
|
|
10 |
def __init__(self, db_path: str) -> None:
|
11 |
"""
|
12 |
Initialize the FastF1ToSQL class.
|
@@ -17,9 +24,9 @@ class FastF1ToSQL:
|
|
17 |
self.db_path = db_path
|
18 |
self.conn = sqlite3.connect(db_path, timeout=20)
|
19 |
self.cursor = self.conn.cursor()
|
20 |
-
self.
|
21 |
|
22 |
-
def
|
23 |
"""Create all necessary tables and indexes if they don't exist."""
|
24 |
self.cursor.executescript('''
|
25 |
CREATE TABLE IF NOT EXISTS Drivers (
|
@@ -139,6 +146,8 @@ class FastF1ToSQL:
|
|
139 |
Args:
|
140 |
session (Session): The session to process.
|
141 |
"""
|
|
|
|
|
142 |
# Load session data
|
143 |
session.load()
|
144 |
|
@@ -154,7 +163,7 @@ class FastF1ToSQL:
|
|
154 |
self.insert_weather(session)
|
155 |
|
156 |
# Create data analysis views
|
157 |
-
self.
|
158 |
|
159 |
# Commit changes and close connection
|
160 |
self.conn.commit()
|
@@ -236,6 +245,7 @@ class FastF1ToSQL:
|
|
236 |
Args:
|
237 |
session (Session): The FastF1 session object.
|
238 |
"""
|
|
|
239 |
laps_df = session.laps.copy()
|
240 |
laps_df['session_id'] = self._session_id
|
241 |
laps_df['lap_start_time_in_datetime'] = pd.to_datetime(
|
@@ -278,7 +288,7 @@ class FastF1ToSQL:
|
|
278 |
Args:
|
279 |
session (Session): The FastF1 session object.
|
280 |
"""
|
281 |
-
print('> Inserting telemetry data...')
|
282 |
telemetry_data_list = []
|
283 |
|
284 |
for driver in session.drivers:
|
@@ -288,6 +298,7 @@ class FastF1ToSQL:
|
|
288 |
|
289 |
for _, lap in laps_per_driver.iterrows():
|
290 |
lap_number = lap['LapNumber']
|
|
|
291 |
telemetry = lap.get_telemetry()
|
292 |
telemetry['datetime'] = self._session_start_date + \
|
293 |
telemetry['SessionTime']
|
@@ -414,9 +425,9 @@ class FastF1ToSQL:
|
|
414 |
(self._session_id, driver_name, lap['LapNumber']))
|
415 |
return self.cursor.fetchone()[0]
|
416 |
|
417 |
-
def
|
418 |
"""Create data analysis views in the database."""
|
419 |
-
print('> Creating data analysis views...')
|
420 |
self.cursor.executescript('''
|
421 |
-- 1. Driver Performance Summary with Weather
|
422 |
CREATE VIEW IF NOT EXISTS DriverPerformanceSummaryWithWeather AS
|
|
|
4 |
from datetime import datetime
|
5 |
from fastf1.core import Session
|
6 |
import fastf1
|
7 |
+
from rich.console import Console
|
8 |
+
|
9 |
+
console = Console(style="chartreuse1 on grey7")
|
10 |
|
11 |
|
12 |
class FastF1ToSQL:
|
13 |
+
"""
|
14 |
+
A class to convert FastF1 data into a SQLite database.
|
15 |
+
"""
|
16 |
+
|
17 |
def __init__(self, db_path: str) -> None:
|
18 |
"""
|
19 |
Initialize the FastF1ToSQL class.
|
|
|
24 |
self.db_path = db_path
|
25 |
self.conn = sqlite3.connect(db_path, timeout=20)
|
26 |
self.cursor = self.conn.cursor()
|
27 |
+
self.__create_tables()
|
28 |
|
29 |
+
def __create_tables(self) -> None:
|
30 |
"""Create all necessary tables and indexes if they don't exist."""
|
31 |
self.cursor.executescript('''
|
32 |
CREATE TABLE IF NOT EXISTS Drivers (
|
|
|
146 |
Args:
|
147 |
session (Session): The session to process.
|
148 |
"""
|
149 |
+
console.print(
|
150 |
+
f"> Processing session: {session.event.EventName} - {session.name}. This may take a while...")
|
151 |
# Load session data
|
152 |
session.load()
|
153 |
|
|
|
163 |
self.insert_weather(session)
|
164 |
|
165 |
# Create data analysis views
|
166 |
+
self.__create_data_analysis_views()
|
167 |
|
168 |
# Commit changes and close connection
|
169 |
self.conn.commit()
|
|
|
245 |
Args:
|
246 |
session (Session): The FastF1 session object.
|
247 |
"""
|
248 |
+
console.print("> Inserting laps data...")
|
249 |
laps_df = session.laps.copy()
|
250 |
laps_df['session_id'] = self._session_id
|
251 |
laps_df['lap_start_time_in_datetime'] = pd.to_datetime(
|
|
|
288 |
Args:
|
289 |
session (Session): The FastF1 session object.
|
290 |
"""
|
291 |
+
console.print('> Inserting telemetry data...')
|
292 |
telemetry_data_list = []
|
293 |
|
294 |
for driver in session.drivers:
|
|
|
298 |
|
299 |
for _, lap in laps_per_driver.iterrows():
|
300 |
lap_number = lap['LapNumber']
|
301 |
+
console.print(f"> Processing telemetry for lap: {lap_number}")
|
302 |
telemetry = lap.get_telemetry()
|
303 |
telemetry['datetime'] = self._session_start_date + \
|
304 |
telemetry['SessionTime']
|
|
|
425 |
(self._session_id, driver_name, lap['LapNumber']))
|
426 |
return self.cursor.fetchone()[0]
|
427 |
|
428 |
+
def __create_data_analysis_views(self) -> None:
|
429 |
"""Create data analysis views in the database."""
|
430 |
+
console.print('> Creating data analysis views...')
|
431 |
self.cursor.executescript('''
|
432 |
-- 1. Driver Performance Summary with Weather
|
433 |
CREATE VIEW IF NOT EXISTS DriverPerformanceSummaryWithWeather AS
|