theOehrly / Fast-F1

FastF1 is a python package for accessing and analyzing Formula 1 results, schedules, timing data and telemetry
https://docs.fastf1.dev
MIT License
2.44k stars 257 forks source link

[Question and Suggestion] #5

Closed TempBet closed 2 years ago

TempBet commented 4 years ago

Hi, how can I make a Boxplot of the times with a type of rubber? I tried, but he tells me he doesn't accept timedelta

Also, is it possible to implement a function for the SpeedDelta?

PaulusPietsma commented 2 years ago

@theOehrly Thank you for your quick reply. Though I have some questions about your response.

First:

For all that I know, the documentation here and the comments in the code are the best documentation (only maybe?) that you will find.

If so, then I am wondering how were you able to write the code to produce the correct API calls if there is no source explaining what the API structure is, i.e. what all possible API calls are?

Second:

The API isn't public and (sadly) not really intended for third parties (I guess).

Well, I already did some digging into the code and managed to produce a working API call:

https://livetiming.formula1.com/static/2021/2021-09-05_Dutch_Grand_Prix/2021-09-04_Qualifying/TimingData.jsonStream

This gives the qualifying results of the Dutch Grand Prix. The GET request with this URL is valid and gives the 200 success code. So I don't think the API is private, but maybe you are right about it not being intended to be used by third parties?

Again, thank you in advance!

theOehrly commented 2 years ago

@PaulusPietsma just because the API returns data when you request something doesn't necessarily mean it's intended to be public.

If you're actually interested in ways how one could get information about an undocumented api, feel free to send me an email (see bottom of the docs main page).

PaulusPietsma commented 2 years ago

@theOehrly I know, but let's continue this conversation via email.

theOllieS commented 2 years ago

What is the best method to convert the timing result into a simpler form?

For example laps.pick_driver('HAM').pick_fastest()['LapTime'] returns Timedelta('0 days 00:01:22.868000')

Whereas I want it to be represented as simply 1:22.868

Thanks

theOehrly commented 2 years ago

What is the best method to convert the timing result into a simpler form?

For example laps.pick_driver('HAM').pick_fastest()['LapTime'] returns Timedelta('0 days 00:01:22.868000')

Whereas I want it to be represented as simply 1:22.868

Well, a quick and dirty way would be to just slice the string, given that the number of digits (for a lap time) will usually be the same.

str(laps.pick_driver('HAM').pick_fastest()['LapTime'])[-11:-3]

Proper string formatting of timedelta values is available using the timple module.

from timple.timedelta import strftimedelta

td = laps.pick_driver('HAM').pick_fastest()['LapTime']
print(strftimedelta(td, '%m:%s.%ms'))

The string formatters are explained here: https://theoehrly.github.io/Timple/timedelta.html#timedelta-format-strings

Mahshadn commented 2 years ago

Hi, I'm using below code to grab the telemetry data of all drivers. Is there a way to include each driver's lap number for each row in this df?

session = ff1.get_session(2021, 16, 'R')
weekend = session.weekend
laps = session.load_laps(with_telemetry=True)
drivers_list = laps['DriverNumber'].unique().tolist()

first_drvr = drivers_list[1]
pick_first = laps.pick_driver(first_drvr)
tel_first = pick_first.get_telemetry()
tel_first_head = tel_first.head(0)
df = pd.DataFrame(tel_first_head)
df['DriverNumber'] = first_drvr

for i in drivers_list:
    pick_driver = laps.pick_driver(i)
    tel = pick_driver.get_telemetry()
    tel['DriverNumber'] = i
    dfi = pd.DataFrame(tel)
    df = df.append(dfi)

print(df)

thanks

siddharth-tewari commented 2 years ago

How does this api work? Is there any way to use it. http://f1tv-api.formula1.com/

theOllieS commented 2 years ago

@theOehrly A question about 2022 pre season testing.

It is rumoured that the first week of testing will be in Barcelona, but will not be broadcasted. Will this mean that we will not be able to get telemetry from these sessions? Thanks.

siddharth-tewari commented 2 years ago

@theOllieS It may be not broadcasted as teams would not want to reveal their new generation cars to early to others and telemetry may also not be available according to me as No Stream = No Data needed to be uploaded/broadcasted, If they do so, we can get little idea about there cars which they wouldn't want. @theOehrly Can confirm this maybe?

theOllieS commented 2 years ago

@siddharth-tewari that is what I feared, such a shame.

theOehrly commented 2 years ago

I don't know. I don't believe that the teams not wanting to reveal their cars early is a problem. Their competitors are on site at the track, after all. They can see the cars going round and take photos. And there's no value in hiding from the fans, in my opinion.

Also, even if there is no live TV broadcast, there might still be live timing and a live ticker. I guess that the TV broadcast is just comparably expensive, considering that only a small amount of people even watch it.

Still, even if there is live timing, I cannot guarantee that you will be able to get it with FastF1. Last pre-season testing there was only a live stream but not recording afterwards. This makes it difficult as you need to record the data.

Furthermore, who knows what system changes are made over the winter break. I can only find that out once the first session starts. That means I might need to adapt FastF1, which could take some time. I will try to allocate enough time to this project during pre-season testing to be able to work full time on any necessary changes. For obvious reasons, I cannot guarantee that I will actually be able to spend that much time on a hobby project in the middle of the day, though.

hash55 commented 2 years ago

@TempBet: See below the example to use data for colored line segments on the track.

These examples are great. Would you have any idea of how to approach comparing the mini sector times of multiple drivers? I've been trying for a while but can't seem to be making much progress.

Thanks

@theOllieS Sorry I have just seen this issue. Did you manage to work out the minisector times? Thanks

theOllieS commented 2 years ago

@theOllieS Sorry I have just seen this issue. Did you manage to work out the minisector times? Thanks

@hash55 After a long time I figured out a crude script that manages to give me the desired the result. A map of the circuit and each defined minisector, and the quickest driver for each.

Screenshot 2021-11-26 at 23 40 38

Feel free to message me and i'd be happy to share the script with you, although it isn't the easiest to read and I'm sure that there is a lot that can be done to simplify it.

siddharth-tewari commented 2 years ago

@theOllieS I am also interested.

hash55 commented 2 years ago

@theOllieS Sorry I have just seen this issue. Did you manage to work out the minisector times? Thanks

@hash55 After a long time I figured out a crude script that manages to give me the desired the result. A map of the circuit and each defined minisector, and the quickest driver for each.

Screenshot 2021-11-26 at 23 40 38

Feel free to message me and i'd be happy to share the script with you, although it isn't the easiest to read and I'm sure that there is a lot that can be done to simplify it.

Wow that looks very cool. How can I contact with you privately?

theOehrly commented 2 years ago

@theOllieS that looks really nice. Were you able to somehow verify the accuracy of your results?

theOllieS commented 2 years ago

@theOllieS that looks really nice. Were you able to somehow verify the accuracy of your results?

This is not corresponding to the minisectors that may show on the F1 app, this simply divides the circuit up into equal distance sectors and shows the driver with the highest average speed within that sector. At the moment I am only taking the drivers' best laptime from the session.

I'm not sure how to accurately verify this.

theOllieS commented 2 years ago

@hash55 @siddharth-tewari I am thinking of posting a repository on my profile, maybe that will work.

siddharth-tewari commented 2 years ago

@theOllieS Ok, Thank You

hash55 commented 2 years ago

@theOllieS Yup, thanks!

theOehrly commented 2 years ago

This is not corresponding to the minisectors that may show on the F1 app, this simply divides the circuit up into equal distance sectors and shows the driver with the highest average speed within that sector. At the moment I am only taking the drivers' best laptime from the session.

I'm not sure how to accurately verify this.

@theOllieS I like the idea of basing this on the highest average speed. I think it might actually yield a pretty good result. But, from experience, I have learned that you should never trust your results without verifying them somehow. I've created good-looking plots that were absolutely wrong in the past. Although, I don't have a good idea right away on how you could verify this.

hash55 commented 2 years ago

Here is what I would do. (It's not the best option but an initial estimation.) Instead of loading data of all drivers, it would be nice to load just two of them, specifically the fastest lap of Q3. By doing that, you can compare it with the analysis the official F1 Youtube channel sometimes upload. For example: Bottas vs Russell Sakhir 2020

Hamilton vs Vettel USA 2018 At the end of the video, you can see the actual lap with fastest minisectors. As I said before, this is not the best method, because there are only a few comparisons uploaded to YT, but can give you an idea of it. image

theOllieS commented 2 years ago

@theOllieS I like the idea of basing this on the highest average speed. I think it might actually yield a pretty good result. But, from experience, I have learned that you should never trust your results without verifying them somehow. I've created good-looking plots that were absolutely wrong in the past. Although, I don't have a good idea right away on how you could verify this.

Agreed, generally I just apply the sanity check of which cars are typically fast in certain mini sector types. For example, Alfa Romeo are normally very fast at the end of straights, Ferrari are strong in slow corners and the acceleration zones out of them, Merc are good on high speed corners etc. The results tend to agree with this.

theOllieS commented 2 years ago

@hash55 thank you for this, I like this idea. I have found some more examples of these on scuderiafans.com from various sessions. I will try and compare my results to these and show you guys where the differences are.

theOllieS commented 2 years ago

@hash55 @theOehrly I have uploaded some of my results and findings from comparing my minisector head to head results to the official F1 data onto my profile https://github.com/theOllieS/F1-Minisectors-Verification/issues/1 if you are interested. There were so many attachments that I didn't want to clog up this discussion thread so I thought my profile might be a better place.

siddharth-tewari commented 2 years ago

@theOehrly Hello, I have a question that when is Young Drivers Test and will it be available to view on TV and will telemetry, lap times etc. be available from Fast-F1?

theOehrly commented 2 years ago

I don't know if it is broadcasted. I wouldn't think so. The event is not in the official event schedule. Therefore, I assume that there won't be any timing data and telemetry for it.

theOehrly commented 2 years ago

@JSEHV By the way, in case you're reading this, I have finally added one of your cool looking example plots to the examples gallery. Sorry that it took so long. I appreciate the effort that you put into it.

siddharth-tewari commented 2 years ago

@theOehrly Hello, can you fix this if possible?

import fastf1
import fastf1 as ff1

year = input("Enter the Year: ")
race = input("Enter the Race Number/Name: ")

if type(race) == int:
    raceName = race

elif type(race) == float:
    raceName = race

elif type(race) == str:
    raceName = "'" + race + "'"

weekend = ff1.get_session(year, raceName)

lap = fastf1.core.Session(weekend, 'Race')
options = fastf1.api.pages= { 'race_control_messages': 'RaceControlMessages.json', 'team_radio': 'TeamRadio.jsonStream'}

link = fastf1.api.fetch_page(lap, 'team_radio')
print(link)