Showing posts with label fuel corrected laptimes. Show all posts
Showing posts with label fuel corrected laptimes. Show all posts

Sunday, May 29, 2011

F1 2011 Monaco Race - Fuel Corrected Laptime Comparison (Vettel, Alonso, Button)

A quick visual comparison of the first three drivers' fuel corrected laptimes (about fuel corrected laptimes):



And in close up:



Here's the delta between fuel-corrected laptimes of VET, ALO and BUT compared to the current leader of the lap:



srcfile='mco_2011comprehensiveLapTimes.csv'
set title 'F1 2011 Monaco: Laptime Delta Compared to Leader (VET,ALO,BUT)'
d1n="VET fuelcorrected"
d2n="ALO fuelcorrected"
d3n="HAM fuelcorrected"
driver=1
driver2=5
driver3=4
typ=17
col3="blue"
col2="magenta"
col2="red"
set xrange [0:90]
set yrange [-10:15]
plot srcfile using ($4==driver && $2==1? $3:1/0):typ with lines lc rgb col1 title d1n,srcfile using ($4==driver && $2==2? $3:1/0):typ with lines lc rgb col1 title d1n,srcfile using ($4==driver && $2==3? $3:1/0):typ with lines lc rgb col1 title d1n,srcfile using ($4==driver && $2==4? $3:1/0):typ with lines lc rgb col1 title d1n,srcfile using ($4==driver && $2==5? $3:1/0):typ with lines lc rgb col1 title d1n,srcfile using ($4==driver2 && $2==1? $3:1/0):typ with lines lc rgb col2 title d2n,srcfile using ($4==driver2 && $2==2? $3:1/0):typ with lines lc rgb col2 title d2n,srcfile using ($4==driver2 && $2==3? $3:1/0):typ with lines lc rgb col2 title d2n,srcfile using ($4==driver2 && $2==4? $3:1/0):typ with lines lc rgb col2 title d2n,srcfile using ($4==driver2 && $2==5? $3:1/0):typ with lines lc rgb col2 title d2n,srcfile using ($4==driver3 && $2==1? $3:1/0):typ with lines lc rgb col3 title d3n,srcfile using ($4==driver3 && $2==2? $3:1/0):typ with lines lc rgb col3 title d3n,srcfile using ($4==driver3 && $2==3? $3:1/0):typ with lines lc rgb col3 title d3n,srcfile using ($4==driver3 && $2==4? $3:1/0):typ with lines lc rgb col3 title d3n,srcfile using ($4==driver3 && $2==5? $3:1/0):typ with lines lc rgb col3 title d3n

Friday, May 27, 2011

F1 2011 Monaco Free Practice 1 and 2 - Utilisation and Laptime Distribution Comparisons

Have data, will play...

I've been exploring a little more around what's quick and easily achieved using the statistical programming language R (via RStudio. (Don't let the phrase "statistical programming langage" put you offer. With a few simple commands you can generate all manner of complicated graphs and charts without having to know any stats at all!)

The data (in the text based CSV format) is available for download from here: FP1 data, FP2 data

You can download and save these files from my Google spreadsheet archive of the Monaco data by right-clicking on the link and choosing "Save Link As..." or something similar. I saved the files as mco_2001fp1laptimes.csv and mco_2001fp1laptimes.csv respectively.

In Rstudio, you can now load in the data using the Import Dataset option.


(Loading direct from the CSV URL doesn't seem to work for me...)

The datasets I uploaded to Google spreadsheets include things like each laptime in the practice session, the stint (and lap number in the stint), the elapsed time during the session at the end of each lap and the fuel corrected laptime (relative to the stint)

Here's how we can plot how the teams used the session - the following command says "for each driver, plot the elapsed time at which they finished each lap using the FP1 data)":

plot (DriverNum ~ Elapsed,data=mco_2011p1laptimes)


(The Export option in the Chart window allows you to easily save the chart as an image file.)

If we want to plot session 1 and session 2 data on the same chart, we can generate a combined data set. (Both datasets have exactly the same column headings.) Before we do that though, we want to be able to identify the data from free practice 1 and free practice 2 in the combined dataset. We can do that by adding a new column to each dataset within R (it will leave the actual CSV file untouched) that specifies the practice session:

mco_2011p1laptimes$fpsession<-1 mco_2011p12aptimes$fpsession<-2

Here, the first command says: for dataset mco_2011p1laptimes, add a column ($) fpsession and set the value of each cell in that column to 1.

Now we can concatenate the two datasets (rbind, which maybe means "row bind"?) into a single dataset (bothfp), whilst still being able to reference each sessions times directly via the fpsession column.

bothfp=rbind(mco_2011p1laptimes,mco_2011p2laptimes)

We can now plot data from both practice sessions on the the same chart using the following command:

plot (DriverNum ~ Elapsed, col=fpsession,pch=Stint,data=bothfp)

This reads as "plot a scatterplot (plot) for each DriverNum against Elapsed time, colouring the points by the session number (col=fpsession) and using symbols that represent which stint in the session the driver was on (pch=Stint):


We should really add a title too, using the main parameter:

plot (DriverNum ~ Elapsed, col=fpsession,pch=Stint,data=bothfp,main="F1 2011 Monaco: Free Practice 1 and 2 Session Utilisation")

Alternatively, we could have added the title using the command:
par(ps=10)
title(main="F1 2011 Monaco: Free Practice 1 and 2 Session Utilisation")


Here, par(ps=10) says: first set the parameter ps (font size) to 10, then print the title.

Seeing how the teams used the session is one thing, but how about the laptime distribution within a session? The following command shows the laptimes across the second session as a whole by driver:

plot (Time ~ DriverNum, data=mco_2011p2laptimes)


If we want to look at the distributions of laptimes by driver, we can plot the "density" of laptimes according to driver (this is a bit like a histogram, but it uses a continuous line to display the distribution of the laptimes).

d3=subset(mco_2011p2laptimes,DriverNum==3)
plot (density(d1$Time))


(Another way of writing the above would be plot (density(Time),subset(mco_2011p2laptimes,DriverNum==3)). Can you see how they achieve the same thing?)


If we include the lattice package in out set up (which may need installing via Packages/Install Packages), we can plot multiple kernel density plots on the same chart. Here's a comparison the in-stint fuel corrected laptimes between Hamilton and Vettel:

require(lattice)
densityplot(~Fuel.Corrected.Laptime, groups=DriverNum, data=subset(mco_2011p2laptimes,DriverNum==1 | DriverNum==3),main="F1 2011 Monaco - FP2: VET vs HAM")



(This really needs a legend to identify each driver.)

At first glance, this is quite appealing, but on second thoughts I wonder if a histogram wouldn't actually reveal more? For example, if you look closely, you see that there Hamilton's laptimes may also be split into two main clusters, as Vettel's are, although this distinction is masked by the smoothed density plot? Hmm...

Note that we can also use the lattice to plot a separate distribution plot for each driver:

densityplot(~fuelCorrectedLaptime|DriverNum,data=mco_2011p2laptimes)


(In this case, I need to work out how to label each chart; note that there is a visual indicator of each DriverNum in each celll title bar. Hint: VET is the bottom left chart.)

Okay - enough for now. What I wanted to start exploring was some of the charting tools in R that might make a visual comparison of laptimes from practice possible at a glance. The kernel density plot for comparing laptime distributions between two drivers looks like it could be really handy, though at times maybe misleading in a way that a histogram wouldn't be..? Along the way, I also learned how to add a column to a dataset and concatenate two separate datasets into a single one.:-)

Monday, May 9, 2011

F1 2011 Turkey Race - Fuel Corrected Laptimes

When in-race refuelling was still part of the game, calculating fuel strategies was one of the things the F1 amateur strategist could try to play along with. (For a summary of what was involved, see the Royal Academy of Engineering/McLaren worksheet on Formula One Fuel Strategy [PDF].)

Fuel loads still have a part to play now, of course: for every lap travelled, the car uses up fuel, gets lighter, and as a result travels faster (the available kinetic energy has less mass to accelerate around the circuit). Another way of thinking about it is that a fuel weight penalty apples in the form of an increase in laptime for each extra kilogram of mass carried. At the start of a race, when the car is heaviest, a large penalty applies. At the end of the race, when the car is lightest, the penalty is small. If we know how much fuel a car burns per lap, and what the approximate time saving is per unit mass, we can calculate the "fuel corrected" laptimes.

The Williams Turkey preview suggests that the Fuel Consumption round the circuit is 2.7kg / lap with a Fuel Laptime Penalty of 0.3 s / 10kg.

That is: fuelConsumption=2.7, fuelPenalty=0.03, fuelLapsWeightPenalty=mass of fuel * fuelPenalty = (fuelConsumption * laps worth of fuel) * fuelPenalty



We can see how at the start of the race there is a approximately a 4.5 second time penalty due to the weight of the fuel at the start of the race compared to at the end. If we take this time from the laptimes we get a fuel corrected laptime, shown here for VET:



(The label also shows the tyre strategy, as published by Pirellli.)

Note how the unadjusted laptime comes down naturally over the course of the race as the fuel weight penalty is burned off. When we take the fuel weight penalty into account, we get the fuel corrected laptime, which shows an increasing gradient towards the end of each stint as the tyres go off. (It's particulary noticeable in the final stint.) [UPDATE: In a comment, HenningO suggests this final slowing is probably just VET easing off, rather than tyres going off...That's probably right, isn't it?! Doh!]

Another correction we can make is to subtract the fuel corrected fastest laptime for each driver from their laptimes. (That is, take their fastest race lap, caculate the fuel penalty, and subtract that to give a fuel corrected fastest laptime.) If we take this from each laptime, we can see whether the fastest lap was actually the fastest lap (taking into account the fuel penalty).

The lowest fuel and fast lap fuel corrected laptime is actually (fuel weight penalty considered) the fastest lap.

Here are the fuel and fast lap fuel corrected laptimes for HAM, BUT and AMB, all of whom had different tyre strategies:



Note how AMB's soft tyres go off (the corrected laptimes increase towards the end of the corresponding stints), but the hard tyres last well. We also see how BUT's tyres aren't doing him any favours in the final laps of the race.

(Note that the fuel corrected laptime chart could be produced live/during a race from published laptimes, Do any F1 sites publish such a live chart during races?)

Howto make the graphs

The generic fuel penalty chart was plotted using Gnuplot:

gnuplot> set term x11
//My mac doesn't display anything with the aqua setting?
gnuplot> set datafile separator ","
//my data file is CSV, so define the separator, just in case...
gnuplot> set xrange [1:58]
gnuplot> set xlabel "Lap"
gnuplot> set ylabel "Fuel Weight Time Penalty"
gnuplot> plot 0.03*(58-x)*2.7 title "Fuel mass * fuel weight penalty"


The fuel adjusted lap time chart was generated from a CSV file (turlapTimeFuel.csv) of the form:

"Driver,Lap,Lap Time,Fuel Adjusted Laptime,Fuel and fastest lap adjusted laptime
25,1,106.951,102.334,9.73
25,2,99.264,94.728,2.124"


using the following gnuplot command (howto):

plot 'turlapTimeFuel.csv' using ($1==3 ? $2:1/0):5 with lines title "HAM Su | Su(9) Su(20) Hn(34) Hn(46)",'turlapTimeFuel.csv' using ($1==4 ? $2:1/0):5 with lines title "BUT Su | Su(13) Su(26) Hn(39)",'turlapTimeFuel.csv' using ($1==25 ? $2:1/0):5 with lines title "AMB Sn Su(16) Hn(33)"