While watching F1 races, I find it difficult to figure out the time gap between drivers, and how this changed over the course of multiple laps.
Instead of improving my mental maths, or paying attention to the race, I took the easy option of engaging on a multi-month project to make a little program to do it for me
At first, I hoped that someone had done work on this before me. Fast F1 is a python library that can record live F1 data, from an api on the F1 website.
In the docs, it is stated that it isn't possible to use the data live in a session, and can only be used after a session. I took this as a challenge.
For initial testing and development, the data was displayed to the terminal screen. This was to have some quick display of the data with minimal extra development time. Ultimately, this worked for these purposes. However, as no library for controlling the terminal was used, there were difficulties in keeping the table a constant width. Additionally, the fixed number of columns in a terminal mean that only so many datapoints could be plotted. While a shell could be used to allow for interactivity, this would not be a friendly user interface. The main issue with continuing with a terminal user interface was that I wanted to display a graphic of where the drivers were on track. Obviously, this is not practical with a terminal so I chose to move to a graphical user interface.
As I knew that I would want to move away from the terminal display at some point, I tried to make the data ingestion system entirely separate from the frontend, with the frontend being sent a dictionary of data to then do as it pleases.
This paid off, as the change to a graphical user interface was very simple.
The libaray chosen for this was tkinter, as it is a popular library.
While PyQt could have been used, I decided against it for no particular reason.
Uni work has conditioned me to justify this choice but this is a hobby project, so you aren't getting a justification.
Reproducing the table from the table was pretty simple.
The main difficulty was trying to use the pack system to put all the little labels in place.
After doing a little more reading, it turns out that grid works WAY better for my use case so I used that instead.
An issue that persisted between the terminal and the window is that it can be hard to tell whcih line you're looking at.
It would have been possible to colour the text in the terminal, but I kinda get uncomfortable any time I have to use the terminal control codes, idk why.
tkinter has a nice method to colour the labels, so I used this to colour each row of the table the team colour of the driver.
This makes it so much easier to tell who's time you're looking at. yippee!!
Right. Onto the track map.
There's a convenient little bit of data transmitted that gives me the position of the cars in x, y, and z as integers.
What units the integers are? I have no idea.
I plot a little dot for the x and y position of each driver and I don't question the data coming in, sometimes its all negative, sometimes all positive, but it usually kinda just works.
Thats a bit of a lie, sometimes the track is mirrored but I'll work on that later.
I keep the last 100,000 positions of the drivers, so about 5000 positions per driver.
These are then plotted as white dots, and this nicely shows the shape of the track.
Each driver's most recent position is plotted as a 3px square with their driver colour.
This works pretty well, but some of the teams have really similar colours which can make it a bit difficult.
particularly, Red Bull, Williams, and VCARB all have similar colours which can be a bit of a pain.
Luckilly, Red Bull is usually out in front so thats not a problem but Williams and VCARB can be problematic.
It kinda feels like watching the season where they were all big things of carbon fibre with little flecks of paint.
Initially, i could only test the software while a session was going on.
This is not ideal.
To get around this, each message from the server is logged to a file and later, another little script acted like the server so testing to be as close to a live session as possible.
This allowed me to develop when I felt like it, and watch the sessions when I wanted to watch them.
To control wether I was watching a live session or developing the program, I have a single variable that controls everything.
Its really convenient, and it allows me to use the exact code I've just been working on while I'm watching a race.