f1-race-replay README

The project's README from github.com/IAmTomShaw/f1-race-replay. As one markdown file: README.md.

F1 Race Replay 🏎️ 🏁

A Python application for visualizing Formula 1 race telemetry and replaying race events with interactive controls and a graphical interface.

Race Replay Preview

HUGE NEWS: The telemetry stream feature is now in a usable state. See the telemetry demo documentation for access instructions, data format details, and usage ideas.

Features

Controls

Safety Car

The replay includes a simulated Safety Car that appears on track whenever the F1 data indicates a Safety Car deployment (track status code 4). Since the F1 API does not provide GPS telemetry for the actual Safety Car, its position is simulated based on the race leader's position.

How it works

Technical details

The SC position computation happens in _compute_safety_car_positions() in src/f1_data.py. Each frame gets a safety_car field:

{
  "safety_car": {
    "x": 1234.56,
    "y": 7890.12,
    "phase": "on_track",
    "alpha": 1.0
  }
}
Field Description
x, y World coordinates of the SC
phase "deploying", "on_track", or "returning"
alpha Opacity value from 0.0 (invisible) to 1.0 (fully visible), used for fade in/out animation

Note: If you have existing cached .pkl files from previous runs, you must re-run with --refresh-data to generate SC position data. Older cached files will simply show no Safety Car.

Qualifying Session Support (in development)

Recently added support for Qualifying session replays with telemetry visualization including speed, gear, throttle, and brake over the lap distance. This feature is still being refined.

Requirements

Install dependencies:

pip install -r requirements.txt

FastF1 cache folder will be created automatically on first run. If it is not created, you can manually create a folder named .fastf1-cache in the project root

First Run Notice: Loading a session for the first time may take noticeably longer because telemetry data must be downloaded, processed, and cached locally. Subsequent launches of the same session are significantly faster..

Environment Setup

To get started with this project locally, you can follow these steps:

  1. Clone the Repository:

    git clone https://github.com/IAmTomShaw/f1-race-replay
     cd f1-race-replay
    
  2. Create a Virtual Environment: This process differs based on your operating system.

    • On macOS/Linux:
      python3 -m venv venv
      source venv/bin/activate
      
    • On Windows:
      python -m venv venv
      .\venv\Scripts\activate
      
  3. Install Dependencies:

    pip install -r requirements.txt
    
  4. Run the Application: You can now run the application using the instructions in the Usage section below.

Troubleshooting

If the pull data proccess fails, run:

pip install --upgrade fastf1

Usage

DEFAULT GUI MENU: To use the new GUI menu system, you can simply run:

python main.py

GUI Menu Preview

This will open a graphical interface where you can select the year and round of the race weekend you want to replay. This is still a new feature, so please report any issues you encounter.

OPTIONAL CLI MENU: To use the CLI menu system, you can simply run:

python main.py --cli

CLI Menu Preview

This will prompt you with series of questions and a list of options to make your choice from using the arrow keys and enter key.

If you would already know the year and round number of the session you would like to watch, you run the commands directly as follows:

Run the main script and specify the year and round:

python main.py --viewer --year 2025 --round 12

To run without HUD:

python main.py --viewer --year 2025 --round 12 --no-hud

To run a Sprint session (if the event has one), add --sprint:

python main.py --viewer --year 2025 --round 12 --sprint

The application will load a pre-computed telemetry dataset if you have run it before for the same event. To force re-computation of telemetry data, use the --refresh-data flag:

python main.py --viewer --year 2025 --round 12 --refresh-data

Qualifying Session Replay

To run a Qualifying session replay, use the --qualifying flag:

python main.py --viewer --year 2025 --round 12 --qualifying

To run a Sprint Qualifying session (if the event has one), add --sprint:

python main.py --viewer --year 2025 --round 12 --qualifying --sprint

File Structure

f1-race-replay/
├── main.py                    # Entry point, handles session loading and starts the replay
├── requirements.txt           # Python dependencies
├── README.md                  # Project documentation
├── roadmap.md                 # Planned features and project vision
├── resources/
│   └── preview.png           # Race replay preview image
├── src/
│   ├── f1_data.py            # Telemetry loading, processing, frame generation & SC position simulation
│   ├── arcade_replay.py      # Visualization and UI logic
│   └── ui_components.py      # UI components like buttons and leaderboard
│   ├── interfaces/
│   │   └── qualifying.py     # Qualifying session interface and telemetry visualization
│   │   └── race_replay.py    # Race replay interface, SC rendering & telemetry visualization
│   └── lib/
│       └── tyres.py          # Type definitions for telemetry data structures
│       └── time.py           # Time formatting utilities
└── .fastf1-cache/            # FastF1 cache folder (created automatically upon first run)
└── computed_data/            # Computed telemetry data (created automatically upon first run)

Building Custom Telemetry Windows

When you start a race replay, an Insights Menu automatically appears, providing quick access to various telemetry analysis tools. You can easily create custom insight windows that receive live telemetry data using the PitWallWindow base class:

from src.gui.pit_wall_window import PitWallWindow

class MyInsightWindow(PitWallWindow):
    def setup_ui(self):
        # Create your custom UI
        pass
    
    def on_telemetry_data(self, data):
        # Process telemetry data
        pass

The PitWallWindow base class handles all telemetry stream connection logic automatically, allowing you to focus solely on your window's functionality.

Key Features:

Documentation & Examples:

Customization

Contributing

There have been several contributions from the community that have helped enhance this project. I have added a contributors.md file to acknowledge those who have contributed features and improvements.

If you would like to contribute, feel free to:

Please see roadmap.md for planned features and project vision.

Known Issues

arcade.application.NoOpenGLException: Unable to create an OpenGL 3.3+ context. Check to make sure your system supports OpenGL 3.3 or higher

You can easily fix this by running this command:

$ conda install -c conda-forge libstdcxx-ng

Thanks to @el-mandaloriano for showing how to resolve this issue: #12

📝 License

This project is licensed under the MIT License.

⚠️ Disclaimer

No copyright infringement intended. Formula 1 and related trademarks are the property of their respective owners. All data used is sourced from publicly available APIs and is used for educational and non-commercial purposes only.


Built with ❤️ by Tom Shaw

f1-race-replay (IAmTomShaw/f1-race-replay)

Searching Database…

这是什么?F1 Race Replay 是一款 Python 桌面应用,可以可视化真实的一级方程式赛车遥测数据,并通过带有动画效果的交互式赛道视图回放比赛事件。
这是图形界面应用,还是只是命令行脚本?它是一款基于 Arcade 游戏库构建的桌面图形界面应用,同时也提供可选的文本命令行菜单,用于选择要回放的赛段。
我该如何让它运行起来?克隆仓库,创建虚拟环境(macOS/Linux 与 Windows 的步骤略有不同),安装依赖,然后运行图形界面菜单,或直接向主脚本传入 --year 和 --round 参数。
我需要先安装什么?你需要 Python 3.11+,以及 FastF1、Arcade 和 numpy 库;FastF1 在首次运行时还会创建一个本地缓存文件夹,用于存储下载的遥测数据。
排行榜总是准确的吗?不是——由于根据遥测数据计算车手位置时存在误差,排行榜在前几个弯道、进站期间以及终点处可能出现偏差;团队仍在努力修复这一问题。
它需要 Apple Silicon 或其他特殊配置吗?不需要,它可以在 macOS、Linux 和 Windows 上跨平台运行;唯一与硬件相关的步骤是首次运行任意比赛时速度较慢,因为需要下载并缓存遥测数据。
如果 F1 不提供 GPS 数据,安全车在回放中是如何显示的?根据 FastF1 赛道状态数据中的真实安全车计时信息,其位置会在赛道折线上被模拟为位于领先车手前方约 500 米处,并带有动画效果的部署、在赛道上和返回阶段,以及脉动的橙色光晕。
我也能观看排位赛,而不只是正赛吗?可以,目前正在开发对排位赛(以及冲刺排位赛)回放的支持,可按赛道距离显示车速、挡位、油门和刹车等遥测数据,通过 --qualifying 参数启用。
我能自己制作遥测组件吗?可以,你可以继承 PitWallWindow 基类,它会自动处理实时遥测连接和清理工作,因此你只需实现 setupui() 和 ontelemetrydata() 即可。
哪些键盘快捷键可以控制回放?空格键可暂停或继续,方向键可快退、快进并调整速度,数字键 1-4 可跳转到预设速度,R 键重新开始,D/B/L 键分别切换 DRS 区域、进度条和车手名称的显示。
Creator
IAmTomShaw
Size
14 MB
Stars
6.8K
Updated
CommitOct 09
Age
10mo
Commits · 90 Days