Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my code. Please make it so 'TASK 4 ' gives me an output. if there is any data that i need that i

This is my code. Please make it so 'TASK 4' gives me an output. if there is any data that i need that i need to put in please PLEASE LABEL CLEARLY where i need to put it.and if there is any mistakes or errors please correct it: MY CODE: task 1:
import sqlite3
import pandas as pd
import csv
import sqlite3
class F1DB:
def __init__(self, db_name='F1Results.DB'):
self.conn = sqlite3.connect(db_name)
self.cursor = self.conn.cursor()
def close_connection(self):
self.conn.close()
def create_f1_results_db(db_name='F1Results.DB'):
conn = sqlite3.connect(db_name)
return conn
def import_csv_to_table(conn, csv_path, table_name):
df = pd.read_csv(csv_path)
def close_connection(conn):
conn.close()
results_csv_path ='/Users/armaa/Documents/f1dbdb/results.csv'
constructors_csv_path ='/Users/armaa/Documents/f1dbdb/constructors.csv'
drivers_csv_path ='/Users/armaa/Documents/f1dbdb/drivers.csv'
races_csv_path ='/Users/armaa/Documents/f1dbdb/races.csv'
pit_stops_csv_path ='/Users/armaa/Documents/f1dbdb/pit_stops.csv'
circuits_csv_path ='/Users/armaa/Documents/f1dbdb/circuits.csv'
lap_times_csv_path ='/Users/armaa/Documents/f1dbdb/lap_times.csv'
conn = create_f1_results_db()
import_csv_to_table(conn, results_csv_path, 'results')
import_csv_to_table(conn, constructors_csv_path, 'constructors')
import_csv_to_table(conn, drivers_csv_path, 'drivers')
import_csv_to_table(conn, races_csv_path, 'races')
import_csv_to_table(conn, pit_stops_csv_path, 'pit_stops')
import_csv_to_table(conn, circuits_csv_path, 'circuits')
import_csv_to_table(conn, lap_times_csv_path, 'lap_times')
f1_db = F1DB()
close_connection(conn)
task 2:
import sqlite3
class QueryF1DB:
def __init__(self, db_name='F1Results.DB'):
self.conn = sqlite3.connect(db_name)
self.cursor = self.conn.cursor()
def close_connection(self):
self.conn.close()
def get_race_results(self, race_year, circuit_name):
query = f"""
SELECT
r.raceId, r.name AS race_name, c.name AS circuit_name, d.driverId,
d.forename, d.surname, rtr.position AS result_position
FROM results rtr
JOIN races r ON rtr.raceId = r.raceId
JOIN circuits c ON r.circuitId = c.circuitId
JOIN drivers d ON rtr.driverId = d.driverId
WHERE r.year ={race_year} AND c.name ='{circuit_name}'
ORDER BY rtr.position
"""
self.cursor.execute(query)
return self.cursor.fetchall()
def get_driver_standings(self, year):
query = f"""
SELECT
d.driverId, d.forename, d.surname, ds.points
FROM driver_standings ds
JOIN drivers d ON ds.driverId = d.driverId
WHERE ds.year ={year}
ORDER BY ds.points DESC
"""
self.cursor.execute(query)
return self.cursor.fetchall()
def get_constructor_standings(self, year):
query = f"""
SELECT
c.constructorId, c.name AS constructor_name, cs.points
FROM constructor_standings cs
JOIN constructors c ON cs.constructorId = c.constructorId
WHERE cs.year ={year}
ORDER BY cs.points DESC
"""
self.cursor.execute(query)
return self.cursor.fetchall()
task 3:
import sqlite3
class QueryF1DB:
def __init__(self, db_name='F1Results.DB'):
self.conn = sqlite3.connect(db_name)
self.cursor = self.conn.cursor()
def close_connection(self):
self.conn.close()
def get_driver_info(self, driver_id):
query = f"SELECT * FROM drivers WHERE driverId ={driver_id}"
self.cursor.execute(query)
result = self.cursor.fetchone()
return result
def get_race_results(self, race_id):
query = f"SELECT * FROM results WHERE raceId ={race_id}"
self.cursor.execute(query)
result = self.cursor.fetchall()
return result
task 4:
import matplotlib.pyplot as plt
import seaborn as sns
from F1DB import F1DB
from QueryF1DB import QueryF1DB
class VisQueryF1DB:
def __init__(self):
self.f1_db = F1DB()
self.query_db = QueryF1DB()
def visualize_driver_info(self, driver_id):
driver_info = self.query_db.get_driver_info(driver_id)
plt.figure(figsize=(10,6))
sns.barplot(x='statistic', y='value', data=driver_info)
plt.title('Driver Statistics')
plt.show()
def visualize_race_results(self, race_id):
race_results = self.query_db.get_race_results(race_id)
plt.figure(figsize=(12,8))
sns.scatterplot(x='position', y='points', hue='driver_name', data=race_results)
plt.title('Race Results')
plt.show()
def close_connections(self):
self.f1_db.close_connection()
self.query_db.close_connection()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

Compare the different types of employee separation actions.

Answered: 1 week ago

Question

Assess alternative dispute resolution methods.

Answered: 1 week ago

Question

Distinguish between intrinsic and extrinsic rewards.

Answered: 1 week ago