Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def filterDataAccordingToRecentDrivers2(dataset):
	_ret_dataset = []
	RecentDriverList = getRecentDrivers(2000)
	_temp_headings = dataset[0]
	_ret_dataset.append(_temp_headings)
	for data in dataset:
		if(data[1] in RecentDriverList):
			_ret_dataset.append(data)
	return _ret_dataset
Exemplo n.º 5
0
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)