Answered step by step
Verified Expert Solution
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 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 itand if there is any mistakes or errors please correct it: MY CODE: task :
import sqlite
import pandas as pd
import csv
import sqlite
class FDB:
def initself dbnameFResults.DB:
self.conn sqliteconnectdbname
self.cursor self.conn.cursor
def closeconnectionself:
self.conn.close
def createfresultsdbdbnameFResults.DB:
conn sqliteconnectdbname
return conn
def importcsvtotableconn csvpath, tablename:
df pdreadcsvcsvpath
def closeconnectionconn:
conn.close
resultscsvpath UsersarmaaDocumentsfdbdbresultscsv
constructorscsvpath UsersarmaaDocumentsfdbdbconstructorscsv
driverscsvpath UsersarmaaDocumentsfdbdbdriverscsv
racescsvpath UsersarmaaDocumentsfdbdbracescsv
pitstopscsvpath UsersarmaaDocumentsfdbdbpitstops.csv
circuitscsvpath UsersarmaaDocumentsfdbdbcircuitscsv
laptimescsvpath UsersarmaaDocumentsfdbdblaptimes.csv
conn createfresultsdb
importcsvtotableconn resultscsvpath, 'results'
importcsvtotableconn constructorscsvpath, 'constructors'
importcsvtotableconn driverscsvpath, 'drivers'
importcsvtotableconn racescsvpath, 'races'
importcsvtotableconn pitstopscsvpath, 'pitstops'
importcsvtotableconn circuitscsvpath, 'circuits'
importcsvtotableconn laptimescsvpath, 'laptimes'
fdb FDB
closeconnectionconn
task :
import sqlite
class QueryFDB:
def initself dbnameFResults.DB:
self.conn sqliteconnectdbname
self.cursor self.conn.cursor
def closeconnectionself:
self.conn.close
def getraceresultsself raceyear, circuitname:
query f
SELECT
rraceId, rname AS racename, cname AS circuitname, ddriverId,
dforename, dsurname, rtrposition AS resultposition
FROM results rtr
JOIN races r ON rtrraceId rraceId
JOIN circuits c ON rcircuitId ccircuitId
JOIN drivers d ON rtrdriverId ddriverId
WHERE ryear raceyear AND cname circuitname
ORDER BY rtrposition
self.cursor.executequery
return self.cursor.fetchall
def getdriverstandingsself year:
query f
SELECT
ddriverId, dforename, dsurname, dspoints
FROM driverstandings ds
JOIN drivers d ON dsdriverId ddriverId
WHERE dsyear year
ORDER BY dspoints DESC
self.cursor.executequery
return self.cursor.fetchall
def getconstructorstandingsself year:
query f
SELECT
cconstructorId, cname AS constructorname, cspoints
FROM constructorstandings cs
JOIN constructors c ON csconstructorId cconstructorId
WHERE csyear year
ORDER BY cspoints DESC
self.cursor.executequery
return self.cursor.fetchall
task :
import sqlite
class QueryFDB:
def initself dbnameFResults.DB:
self.conn sqliteconnectdbname
self.cursor self.conn.cursor
def closeconnectionself:
self.conn.close
def getdriverinfoself driverid:
query fSELECT FROM drivers WHERE driverId driverid
self.cursor.executequery
result self.cursor.fetchone
return result
def getraceresultsself raceid:
query fSELECT FROM results WHERE raceId raceid
self.cursor.executequery
result self.cursor.fetchall
return result
task :
import matplotlib.pyplot as plt
import seaborn as sns
from FDB import FDB
from QueryFDB import QueryFDB
class VisQueryFDB:
def initself:
self.fdb FDB
self.querydb QueryFDB
def visualizedriverinfoself driverid:
driverinfo self.querydbgetdriverinfodriverid
pltfigurefigsize
snsbarplotx'statistic', y'value', datadriverinfo
plttitleDriver Statistics'
pltshow
def visualizeraceresultsself raceid:
raceresults self.querydbgetraceresultsraceid
pltfigurefigsize
snsscatterplotx'position', y'points', hue'drivername', dataraceresults
plttitleRace Results'
pltshow
def closeconnectionsself:
self.fdbcloseconnection
self.querydbcloseconnection
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started