def getCircuitRaceList(filepath): """ Parameters ---------- filepath : string The filepath relative to the parentPath Returns ------- dict{key:[list]} {circuitID: [raceID]} """ circuit_Data = getDataset(filepath) dataObtained = circuit_Data.next() RecentTracksList = getRecentTracks() print "Data from file: " + str(dataObtained) print "Data Extracted: " + 'circuitID ' + " raceID" circuitDict_raceList = defaultdict( lambda: []) # initialise the dictionary value to an empty list for race_circuit in circuit_Data: # print race_circuit if (race_circuit[2] in RecentTracksList): circuitDict_raceList[race_circuit[2]].append( race_circuit[0]) # {circuitID: [raceID]} return circuitDict_raceList
def getPitStops(filepath): """ Parameters ---------- filepath: string The directory to the file relative to the parentPath # [raceId, driverId, stop, lap, time, duration, milliseconds] Returns ------- tuple (headings, data, dictionary) """ RecentDriversList = getRecentDrivers(2000) circuitRaceList = getCircuitRaceList("races.csv") circuitRaceKeys = circuitRaceList.keys() PitStopsData = getDataset(filepath) dataObtained = PitStopsData.next() Data = [] for data in PitStopsData: if (ifExist(data[1], RecentDriversList)): for key in circuitRaceKeys: if (data[0] in circuitRaceList[key]): Data.append(data) # Data = list(PitStopsData) print "Data from file: " + str(dataObtained) # print "Data Extracted: " + 'Year ' + " raceID" _ret_dict = defaultdict(lambda: defaultdict(lambda: 0.0)) for d in Data: # {raceId, driverId :{ stop: pit time }} _ret_dict[str(d[0]) + "," + str(d[1])][d[2]] = d[6] return (dataObtained, Data, _ret_dict)
def getPreprocessedData(filepath): """ Parameters ---------- filepath: string The directory to the file relative to the parentPath # [raceId, driverId, constructorId, rank, points, grid, position, positionOrder, positionText , firstLapChange, pitStops] Returns ------- tuple (headings, data, dictionary) """ RecentDriversList = getRecentDrivers(2000) circuitRaceList = getCircuitRaceList("races.csv") circuitRaceKeys = circuitRaceList.keys() PreprocessedData = getDataset(filepath) dataObtained = PreprocessedData.next() # Data = list(PreprocessedData) Data = [] for data in PreprocessedData: if (ifExist(data[1], RecentDriversList)): for key in circuitRaceKeys: if (data[0] in circuitRaceList[key]): Data.append(data) print "Data from file: " + str(dataObtained) return (dataObtained, Data)
def getDataFromResults(filepath): """ Parameters ---------- filepath: string The directory to the file relative to the parentPath # [raceID, driverID, constructorID, rank, points, grid, postion, positionOrder] Returns ------- tuple (headings, data) """ RecentDriversList = getRecentDrivers(2000) circuitRaceList = getCircuitRaceList("races.csv") circuitRaceKeys = circuitRaceList.keys() ResultData = getDataset(filepath) dataObtained = ResultData.next() Data = [] # Data = list(ResultData) for data in ResultData: if (ifExist(data[1], RecentDriversList)): for key in circuitRaceKeys: if (data[0] in circuitRaceList[key]): Data.append(data) print "Data from file: " + str(dataObtained) # print "Data Extracted: " + 'Year ' + " raceID" # yearDict_raceList = defaultdict(lambda:[]) # initialise the dictionary value to an empty list # dataObtained.append("firstLapChange") # for d in Data: # d.append(int(d[5]) - int(d[7])) return (dataObtained, Data)
def getCircuitInfoList(filepath): """ Parameters ---------- filepath : string The filepath relative to the parentPath Returns ------- dict{key:[list]} {circuitID: [track information]} """ circuit_Data = getDataset(filepath) dataObtained = circuit_Data.next() print "Data from file: " + str(dataObtained) print "Data Extracted: " + 'circuitID ' + " raceInfo" circuitDict_InfoList = defaultdict(lambda: np.array([ ])) # initialise the dictionary value to an empty list for circuitInfo in circuit_Data: # print race_circuit for i in xrange(len(circuitInfo)): if ((i > 8) & (i < 1009)): # print circuitInfo[i] # if( circuitInfo[i] != ""): circuitDict_InfoList[circuitInfo[1]] = np.append( circuitDict_InfoList[circuitInfo[1]], np.int(circuitInfo[i])) # else: # print circuitInfo[1] return circuitDict_InfoList
def getRaceDriverConstRankPts(filepath): """ Parameters ---------- filepath : string The filepath relative to the parentPath Returns ------- [raceID, driverID, constructorID, rank, points] """ cons_Data = getDataset(filepath) dataObtained = cons_Data.next() print "Data Extracted: " + str(dataObtained) return list(cons_Data)
def getLapTimes(filepath): """ Parameters ---------- filepath: string The directory to the file relative to the parentPath # [raceId, driverId, lap, position, time, milliseconds] Returns ------- tuple (headings, data, dictionary, dictionary of dictionary) """ RecentDriversList = getRecentDrivers(2000) circuitRaceList = getCircuitRaceList("races.csv") circuitRaceKeys = circuitRaceList.keys() LapTimesData = getDataset(filepath) dataObtained = LapTimesData.next() # Data = list(LapTimesData) Data = [] for data in LapTimesData: if (ifExist(data[1], RecentDriversList)): for key in circuitRaceKeys: if (data[0] in circuitRaceList[key]): Data.append(data) print "Data from file: " + str(dataObtained) # {raceID: [[driverID, lap#, laptime]]} _ret_dict = defaultdict(lambda: []) # {raceID: {lap#: [driverID, laptime]}} _ret_dict_dict = defaultdict(lambda: defaultdict(lambda: [])) for d in Data: # {raceId, driverId :{ lap: laptime]] # _ret_dict[str(d[0]) +"," + str(d[1])][d[2]] = d[5] _ret_dict[int(d[0])].append(np.array([int(d[1]), int(d[2]), int(d[5])])) # {raceID: {lap#: [driverID, laptime]}} _ret_dict_dict[int(d[0])][int(d[2])].append([int(d[1]), int(d[5])]) # keys = sorted(_ret_dict_dict.keys(), lambda _key: int(_key)) keys = _ret_dict_dict.keys() for key in keys: _keys = _ret_dict_dict[key].keys() for _key in _keys: _ret_dict_dict[key][_key].sort(key=itemgetter(1)) # print _ret_dict_dict[key][_key] return (dataObtained, Data, _ret_dict, _ret_dict_dict)
def getDriverIDName(filepath): """ filepath: drivers.csv Returns: -------- dictionary: {DriverID: DriverName} """ driversData = getDataset(filepath) dataObtained = driversData.next() print "Data from file: " + str(dataObtained) print "Data Extracted: " + 'driverID ' + " driverName" driverIDNameDict = defaultdict( lambda: []) # initialise the dictionary value to an empty list for data in driversData: driverIDNameDict[data[0]] = data[1] + " " + data[2] return driverIDNameDict
def getDriverIDName(filepath): """ Parameters ---------- filepath : string The filepath relative to the parentPath Returns ------- dict{key:string} {ConstructorID: ConstructorName} """ driver_Data = getDataset(filepath) # print list(cons_Data) dataObtained = driver_Data.next() print "Data Extracted: " + str(dataObtained) ret_dict = {} for _driver in driver_Data: ret_dict[_driver[0]] = _driver[1] + " " + _driver[2] return ret_dict
def getYearRaceID(filepath): """ Parameters ---------- filepath: string The directory to the file relative to the parentPath Returns ------- dictionary of list {year: [raceID]} """ YearRace_Data = getDataset(filepath) dataObtained = YearRace_Data.next() print "Data from file: " + str(dataObtained) print "Data Extracted: " + 'Year ' + " raceID" yearDict_raceList = defaultdict(lambda:[]) # initialise the dictionary value to an empty list for race_year in YearRace_Data: # print race_circuit yearDict_raceList[race_year[1]].append(race_year[0]) # {circuitID: [raceID]} return yearDict_raceList
def getConstructorRaceList(filepath): """ Parameters ---------- filepath : string The filepath relative to the parentPath Returns ------- dict{key:[list]} {constructorID: [raceID]} """ cons_Data = getDataset(filepath) dataObtained = cons_Data.next() print "Data Extracted: " + str(dataObtained) consDict_raceList = defaultdict( lambda: []) # initialise the dictionary value to an empty list for race_cons in cons_Data: consDict_raceList[race_cons[1]].append( race_cons[0]) # {constructorID: [raceID]} return consDict_raceList
def getDataFromTracks(filepath): """ Parameters ---------- filepath: string The directory to the file relative to the parentPath # [raceID, driverID, constructorID, rank, points, grid, postion, positionOrder] Returns ------- tuple (headings, data) """ TrackData = getDataset(filepath) # TrackData.next() dataObtained = TrackData.next() Data = list(TrackData) print "Data from file: " + str(dataObtained) # print "Data Extracted: " + 'Year ' + " raceID" # yearDict_raceList = defaultdict(lambda:[]) # initialise the dictionary value to an empty list # dataObtained.append("firstLapChange") # for d in Data: # d.append(int(d[5]) - int(d[7])) return (dataObtained, Data)