-
-
Save christakahashi/33c98223023dd58fe9cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#LICENSE | |
# Copyright (c) 2014, Chris Takahashi | |
# All rights reserved. | |
#Redistribution and use in source and binary forms, with or without modification, are permitted. | |
# | |
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
from __future__ import print_function | |
from pylab import * | |
import json | |
#the file name for the CSV | |
data_file = "Thunder Hill 4.18.14 - Friday 7 hour - laptimes.csv" | |
#the car numbers | |
cars = [4,201] #3rd 4th | |
#cars = [4,128] #3rd 5th | |
#cars = [4,20] #3rd 6th | |
#cars = [4,117] #3rd 2nd | |
colors = ['g.','r.'] | |
f = open(data_file,'r'); | |
Header = True | |
laps = {} | |
for line in f: | |
#skip header line | |
if Header: | |
Header = False | |
continue | |
#read car number | |
if line[0] != '"': | |
try: | |
car_no = int(line.split(' - ')[0].strip("EC")) | |
except ValueError: #"pace" or something else stupid | |
car_no = -1 | |
laps[car_no] = {"rt":[],"t":[],"lapnumber":[]} | |
else: | |
if car_no == -1: | |
continue | |
ldat = json.loads('['+line+']') | |
t = [float(x) for x in ldat[0].split(":")] | |
racetime = (t[0]*60*60+t[1]*60+t[2] - 10*60*60)/60/60 #in hrs | |
laps[car_no]["rt"].append(racetime) | |
t = [float(x) for x in ldat[3].split(":")] | |
laptime = t[0]*60+t[1] | |
laps[car_no]["t"].append(laptime) | |
laps[car_no]["lapnumber"].append(int(ldat[1])) | |
for params in zip(cars,colors): | |
plot(laps[params[0]]["rt"],laps[params[0]]["t"],params[1]) | |
xlabel("Race time (hrs)") | |
ylabel("Lap time (seconds)") | |
x1,x2,y1,y2 = plt.axis() | |
#plt.axis((x1,x2,120,180)) | |
figure() | |
for params in zip(cars,colors): | |
plot(laps[params[0]]["rt"],laps[params[0]]["lapnumber"],params[1][0]) | |
print("pit laps total:") | |
for c in cars: | |
laptimes = array(laps[c]["t"]) | |
tot_pit = sum(laptimes[laptimes>400]) | |
print("car " + str(c) +": "+ str(tot_pit) ) | |
print("lap stats") | |
hist_data = [] | |
figure() | |
for c in cars: | |
laptimes = array(laps[c]["t"]) | |
real_laps = laptimes[laptimes<160] | |
real_laps = real_laps[real_laps>120] | |
avg = sum(real_laps)/len(real_laps) | |
pctile = percentile(real_laps, 25) | |
print("car " + str(c) +": "+ "avg: " + str(avg)+" pctile:"+str(pctile) ) | |
hist_data.append(real_laps) | |
print("std: " + str(std(hist_data[0])) + ", " + str(std(hist_data[1])) ) | |
subplot(2,1,1) | |
hist(hist_data[0],15,color=['g'],histtype='stepfilled') | |
plt.axis((135,160,0,30)) | |
ylabel("frequency") | |
subplot(2,1,2) | |
hist(hist_data[1],15,color=['r'],histtype='stepfilled') | |
plt.axis((135,160,0,30)) | |
xlabel("Lap time (sec)") | |
ylabel("frequency") | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment