/f1stats

Formula 1 driver comparison and analyzing tool.

Primary LanguagePython

f1stats

Formula 1 driver comparison and race analyzing tool. f1stats uses Fast-F1 core for race and driver analysis. The Fast-F1 core is a collection of functions and data objects for accessing and analyzing F1 timing and telemetry data.

ezgif com-gif-maker (3)

Setup

Use the package manager pip to install libraries.

pip install fastf1 
pip install matplotlib
pip install numpy
pip install pandas

Usage

Example plots. For example, if you want to compare Bottas and Hamilton.

driver1 = 'BOT' 
driver2 = 'HAM'

You can also choose all other drivers.

# 2020 season
D_LOOKUP = [[44, 'HAM', 'Mercedes'], [77, 'BOT', 'Mercedes'],
            [55, 'SAI', 'Ferrari'], [16, 'LEC', 'Ferrari'],
            [33, 'VER', 'Red Bull'], [11, 'PER', 'Red Bull'],
            [3, 'RIC', 'McLaren'], [4, 'NOR', 'McLaren'],
            [5, 'VET', 'Aston Martin'], [18, 'STR', 'Aston Martin'],
            [14, 'ALO', 'Alpine'], [31, 'OCO', 'Alpine'],
            [22, 'TSU', 'AlphaTauri'], [10, 'GAS', 'AlphaTauri'],
            [47, 'MSC', 'Haas F1 Team'], [9, 'MAZ', 'Haas F1 Team'],
            [7, 'RAI', 'Alfa Romeo'], [99, 'GIO', 'Alfa Romeo'],
            [6, 'LAT', 'Williams'], [63, 'RUS', 'Williams']]

The Fast-F1 developer recommends using cache. From this document:

It is not necessary to enable the usage of the cache, but it is highly recommended. Simply provide the path to some empty folder on your system. Using the cache will greatly speed up loading of the data.

ff1.Cache.enable_cache(r'path/to/folder/for/cache') # Replace with your cache directory

A fuzzy match is performed to find the most likely event for the provided name (e.g. 'Bahrain').

race = ff1.get_session(2021, 'Zandvoort', 'R')  # 'FP1', 'FP2', 'FP3', 'Q', 'SQ' or 'R'
# FP1 : Free Practice 1
# FP2 : Free Practice 2
# FP3 : Free Practice 3
# Q   : Qualifying
# SQ  : Sprint Qualifying
# R   : Race

Functions

def track():  # Track layout - Fastest Lap Gear Shift Visualization
def gas(): # Car telemetry data ['RPM', 'Speed', 'Throttle', 'Brake', 'nGear', 'DRS']
def compare():  # Two drivers comparison
def qualifying():  # Fastest lap

Compatibility

Data is available for the 2018 to 2023 seasons. Fast-F1 uses data from F1's live timing service.

Screenshots

fastest

qualy

racelaps

telemetrycomp

Contributing

Pull requests are welcome. Before PR please open an issue what you would like to change. Follow PEP 8 Coding Style guidelines.