コード例 #1
0
ファイル: f1datajunkie.py プロジェクト: ap1/f1DataJunkie
def output_pitStops(stops,history,analysis):
	#['24', 'T. GLOCK', 'Marussia Virgin Racing', '1', '1', '14:05:58', '35.092', '35.092']
	driverHistory={}
	#modify driverHistory to be analysis but with lap 1 time from history
	lap1times=history[0]
	for t in lap1times:
		driverHistory[t[0]]={}
	for hl in analysis:
		driver=hl[0]
		if driver in driverHistory:
			for pair in tsa.pairs(hl[4:]):
				driverHistory[driver][pair[0]]=tsa.getTime(pair[1])

	for stop in stops:
		carNum=stop[0]
		lap=stop[4]
		stoptime=tsa.getTime(stop[6])
		if carNum in driverHistory:	
			threelaps=instopafterLaps(driverHistory[carNum],carNum,lap)
		else: threelaps=['','','','']
		print carNum,lap,stoptime,threelaps
コード例 #2
0
def output_pitStops(stops, history, analysis):
    #['24', 'T. GLOCK', 'Marussia Virgin Racing', '1', '1', '14:05:58', '35.092', '35.092']
    driverHistory = {}
    #modify driverHistory to be analysis but with lap 1 time from history
    lap1times = history[0]
    for t in lap1times:
        driverHistory[t[0]] = {}
    for hl in analysis:
        driver = hl[0]
        if driver in driverHistory:
            for pair in tsa.pairs(hl[4:]):
                driverHistory[driver][pair[0]] = tsa.getTime(pair[1])

    for stop in stops:
        carNum = stop[0]
        lap = stop[4]
        stoptime = tsa.getTime(stop[6])
        if carNum in driverHistory:
            threelaps = instopafterLaps(driverHistory[carNum], carNum, lap)
        else:
            threelaps = ['', '', '', '']
        print carNum, lap, stoptime, threelaps
コード例 #3
0
def output_practiceAndQuali(sessiondata, sessionName):
    fastlaps = {}
    driverQuali = {}
    sectors = {}
    sep = ','

    fname = sessionName
    #timing=sessiondata
    #f=open('../generatedFiles/'+race+fname+'.csv','wb')
    #writer = csv.writer(f)

    earlyStart = '99:99:99'
    earlyStartTime = startTimeInSeconds(earlyStart)
    for dn in sessiondata:
        driver = sessiondata[dn]['times']
        driverNum = sessiondata[dn]['driverNum']  #str(driver[0])
        if driverNum != dn:
            print 'Augmentation mismatch', driverNum, dn
            sys.exit(0)
        if len(driver) > 2:
            #if earlyStart>driver[3]: earlyStart=driver[3]
            sttmp = startTimeInSeconds(driver[3])
            if earlyStartTime > sttmp: earlyStartTime = sttmp
    #earlyStartTime=startTimeInSeconds(earlyStart)
    for dn in sessiondata:
        driver = sessiondata[dn]['times']
        driverNum = sessiondata[dn]['driverNum']  #str(driver[0])
        if len(driver) > 2:
            clockTime = driver[3]
        else:
            clockTime = '0:0:0'
        driverQuali[driverNum] = {
            'times': [],
            'driverName': sessionData[dn]['name'],
            'driverNum': driverNum,
            'startTime': '',
            'clockStartTime': clockTime
        }
        dsTime = startTimeInSeconds(driverQuali[driverNum]['clockStartTime'])
        print driverQuali[driverNum][
            'clockStartTime'], earlyStartTime, earlyStart
        driverQuali[driverNum]['startTime'] = "%.1f" % (dsTime -
                                                        earlyStartTime)
        if 'fastlap' in sessiondata[dn]:
            driverQuali[driverNum]['times'].append({
                'time':
                driverQuali[driverNum]['startTime'],
                'elapsed':
                driverQuali[driverNum]['startTime']
            })
            for pair in tsa.pairs(driver[4:]):
                t = pair[1].split(':')
                tm = 60 * int(t[0]) + float(t[1])
                timing = {
                    'time':
                    "%.3f" % tm,
                    'elapsed':
                    "%.3f" %
                    (float(driverQuali[driverNum]['times'][-1]['elapsed']) +
                     tm)
                }
                driverQuali[driverNum]['times'].append(timing)

    print driverQuali

    f2 = open('../generatedFiles/' + race + fname + 'laptimes.csv', 'wb')
    writer2 = csv.writer(f2)

    #header=sep.join(['Name','DriverNum','Lap','Time','Elapsed'])
    #writer.writerow(['Name','DriverNum','Lap','Time','Elapsed'])
    writer2.writerow([
        'Name', 'DriverNum', 'Lap', 'Time', 'Elapsed', 'Stint',
        'Fuel Corrected Laptime', 'Stint Length', 'Lap in stint'
    ])
    #f.write(header+'\n')
    for driver in driverQuali:
        lc = 1
        core = [
            driverQuali[driver]['driverName'], driverQuali[driver]['driverNum']
        ]
        stint = 0
        driverQuali[driver]['stint'] = {}
        for lap in driverQuali[driver]['times'][1:]:
            if float(lap['time']) >= float(
                    sessiondata[driver]['fastlap']) and float(
                        lap['time']) <= 1.5 * float(
                            sessiondata[driver]['fastlap']):
                if stint == 0:
                    stint = 1
                    driverQuali[driver]['stint'][str(stint)] = []
                driverQuali[driver]['stint'][str(stint)].append(lap['time'])
            else:
                stint = stint + 1
                driverQuali[driver]['stint'][str(stint)] = []
        stint = 0
        for lap in driverQuali[driver]['times'][1:]:
            txt = []
            for c in core:
                txt.append(c)
            txt.append(str(lc))
            txt.append(lap['time'])
            txt.append(lap['elapsed'])
            lc = lc + 1
            #f.write(sep.join(txt)+'\n')
            #writer.writerow(txt)
            print driverQuali[driver]
            if float(lap['time']) >= float(
                    sessiondata[driver]['fastlap']) and float(
                        lap['time']) <= 1.5 * float(
                            sessiondata[driver]['fastlap']):
                if stint == 0:
                    stint = 1
                    slc = 1
                else:
                    slc = slc + 1
                txt.append(stint)
                stintLength = len(driverQuali[driver]['stint'][str(stint)])
                fct = tsa.fuelCorrectedLapTime(stintLength, slc,
                                               float(lap['time']))
                txt.append(fct)
                txt.append(len(driverQuali[driver]['stint'][str(stint)]))
                txt.append(slc)
                writer2.writerow(txt)
            else:
                stint = stint + 1
                slc = 0
    f2.close()

    f = open('../generatedFiles/' + race + fname + '.js', 'wb')
    #txt='var data=['
    txt = []
    bigtxt = []
    for driver in [
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
            '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24',
            '25'
    ]:
        #txt=txt+'['
        txt.append([])
        bigtxt.append({})
        bigtxt[-1]['times'] = []
        if driver in driverQuali:
            for lap in driverQuali[driver]['times']:
                txt[-1].append(float(lap['time']))
                #txt=txt+lap['time']+','
                bigtxt[-1]['times'].append(float(lap['time']))
            for att in sessiondata[driver]:
                if att != 'times': bigtxt[-1][att] = sessiondata[driver][att]
            #txt=txt.rstrip(',')+'], '
    #txt=txt.rstrip(',')+'];'
    print txt, bigtxt

    f.write('var data=[' + ','.join(map(str, bigtxt)) + '];')
    f.close()
    return fastlaps
コード例 #4
0
ファイル: f1datajunkie.py プロジェクト: ap1/f1DataJunkie
def output_practiceAndQuali(sessiondata,sessionName):
	fastlaps={}
	driverQuali={}
	sectors={}
	sep=','
	
	fname=sessionName
	#timing=sessiondata
	#f=open('../generatedFiles/'+race+fname+'.csv','wb')
	#writer = csv.writer(f)
		
	earlyStart='99:99:99'
	earlyStartTime=startTimeInSeconds(earlyStart)
	for dn in sessiondata:
		driver=sessiondata[dn]['times']
		driverNum= sessiondata[dn]['driverNum']#str(driver[0])
		if driverNum!=dn:
			print 'Augmentation mismatch',driverNum,dn
			sys.exit(0)
		if len(driver)>2:
			#if earlyStart>driver[3]: earlyStart=driver[3]
			sttmp=startTimeInSeconds(driver[3])
			if earlyStartTime>sttmp: earlyStartTime=sttmp
	#earlyStartTime=startTimeInSeconds(earlyStart)
	for dn in sessiondata:
		driver=sessiondata[dn]['times']
		driverNum= sessiondata[dn]['driverNum']#str(driver[0])
		if len(driver)>2:
			clockTime=driver[3]
		else:
			clockTime='0:0:0'
		driverQuali[driverNum]={'times':[],'driverName':sessionData[dn]['name'],'driverNum':driverNum, 'startTime':'','clockStartTime':clockTime}
		dsTime=startTimeInSeconds(driverQuali[driverNum]['clockStartTime'])
		print driverQuali[driverNum]['clockStartTime'],earlyStartTime,earlyStart
		driverQuali[driverNum]['startTime']= "%.1f" % (dsTime-earlyStartTime)
		if 'fastlap' in sessiondata[dn]:
			driverQuali[driverNum]['times'].append({'time':driverQuali[driverNum]['startTime'],'elapsed':driverQuali[driverNum]['startTime']})
			for pair in tsa.pairs(driver[4:]):
				t=pair[1].split(':')
				tm=60*int(t[0])+float(t[1])
				timing={'time':"%.3f" % tm, 'elapsed':"%.3f" %( float(driverQuali[driverNum]['times'][-1]['elapsed'])+tm)}
				driverQuali[driverNum]['times'].append(timing)

	print driverQuali

	f2=open('../generatedFiles/'+race+fname+'laptimes.csv','wb')
	writer2 = csv.writer(f2)

	#header=sep.join(['Name','DriverNum','Lap','Time','Elapsed'])
	#writer.writerow(['Name','DriverNum','Lap','Time','Elapsed'])
	writer2.writerow(['Name','DriverNum','Lap','Time','Elapsed','Stint','Fuel Corrected Laptime','Stint Length','Lap in stint'])
	#f.write(header+'\n')
	for driver in driverQuali:
		lc=1
		core=[driverQuali[driver]['driverName'],driverQuali[driver]['driverNum']]
		stint=0
		driverQuali[driver]['stint']={}
		for lap in driverQuali[driver]['times'][1:]:
			if float(lap['time']) >= float(sessiondata[driver]['fastlap']) and float(lap['time']) <= 1.5*float(sessiondata[driver]['fastlap']):
				if stint==0:
					stint=1
					driverQuali[driver]['stint'][str(stint)]=[]
				driverQuali[driver]['stint'][str(stint)].append(lap['time'])
			else:
				stint=stint+1
				driverQuali[driver]['stint'][str(stint)]=[]		
		stint=0
		for lap in driverQuali[driver]['times'][1:]:
			txt=[]
			for c in core: txt.append(c)
			txt.append(str(lc))
			txt.append(lap['time'])
			txt.append(lap['elapsed'])
			lc=lc+1
			#f.write(sep.join(txt)+'\n')
			#writer.writerow(txt)
			print driverQuali[driver]
			if float(lap['time']) >= float(sessiondata[driver]['fastlap']) and float(lap['time']) <= 1.5*float(sessiondata[driver]['fastlap']):
				if stint==0:
					stint=1
					slc=1
				else: slc=slc+1
				txt.append(stint)
				stintLength=len(driverQuali[driver]['stint'][str(stint)])
				fct=tsa.fuelCorrectedLapTime(stintLength,slc,float(lap['time']))
				txt.append(fct)
				txt.append(len(driverQuali[driver]['stint'][str(stint)]))
				txt.append(slc)
				writer2.writerow(txt)
			else:
				stint=stint+1
				slc=0
	f2.close()

	f=open('../generatedFiles/'+race+fname+'.js','wb')
	#txt='var data=['
	txt=[]
	bigtxt=[]
	for driver in ['1','2','3','4','5','6','7','8','9','10','11','12','14','15','16','17','18','19','20','21','22','23','24','25']:
		#txt=txt+'['
		txt.append([])
		bigtxt.append({})
		bigtxt[-1]['times']=[]
		if driver in driverQuali:
			for lap in driverQuali[driver]['times']:
				txt[-1].append(float(lap['time']))
				#txt=txt+lap['time']+','
				bigtxt[-1]['times'].append(float(lap['time']))
			for att in sessiondata[driver]:
				if att!='times': bigtxt[-1][att]=sessiondata[driver][att]
			#txt=txt.rstrip(',')+'], '
	#txt=txt.rstrip(',')+'];'
	print txt,bigtxt
	
	f.write('var data=['+','.join(map(str, bigtxt))+'];')
	f.close()
	return fastlaps