[PR #47] Feature: Add Last Lap Time and Interval Gaps to Race Replay Leaderboard #99

Open
opened 2026-05-07 00:18:39 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/IAmTomShaw/f1-race-replay/pull/47
Author: @KingSajxxd
Created: 12/15/2025
Status: 🔄 Open

Base: mainHead: main


📝 Commits (1)

  • 4aba004 feat: Add lap times and interval gaps to race leaderboard

📊 Changes

3 files changed (+140 additions, -27 deletions)

View changed files

📝 src/f1_data.py (+79 -13)
📝 src/interfaces/race_replay.py (+11 -3)
📝 src/ui_components.py (+50 -11)

📄 Description

Screenshot 2025-12-15 at 8 52 33 PM

Description

This PR enhances the Race Replay UI by adding two critical data points to the leaderboard: Last Lap Time and Interval (time gap to the car ahead). This brings the replay experience closer to a real F1 broadcast.

Previously, the leaderboard only showed positions and tire compounds. Now, it calculates real-time gaps in seconds (interpolated from telemetry data) and displays the most recent lap time for every driver.

Changes Overview

1. Data Processing (src/f1_data.py)

Added Last Lap Logic:

  • Modified _process_single_driver to capture the LapTime of the previous lap and forward-fill it into the current lap's telemetry frames.

Added Interval Calculation:

  • Updated get_race_telemetry to calculate the time gap (in seconds) between cars.
  • Logic: It uses np.interp to find the exact timestamp when the "car ahead" was at the "current car's" current distance, then calculates the difference (current_time - time_ahead_was_here).

Frame Payload:

  • Updated the frame structure to include last_lap_time_str and interval_str for every driver.

2. UI Components (src/ui_components.py)

Widened Leaderboard:

  • Increased LeaderboardComponent width from 240px to 400px to accommodate the new columns.

New Headers:

  • Added a header row for POS / DRV, LAP TIME, and INTERVAL.

Rendering:

  • Updated the draw() method to render the new last_lap_time (center-aligned) and interval (right-aligned) text strings.

3. Race Replay Interface (src/interfaces/race_replay.py)

Window Layout:

  • Increased the right_ui_margin from 260 to 420 to fit the wider leaderboard without overlapping the track.

Data Passing:

  • Updated on_draw to extract the new fields (last_lap_time_str, interval_str) from the frame data and pass them as a 6-item tuple to the LeaderboardComponent.

How to Test

Run the replay with the --refresh-data flag to regenerate the cache with the new metrics:

python main.py --year 2024 --round 1 --refresh-data

Observe the leaderboard on the right side; it should now display lap times and intervals.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/IAmTomShaw/f1-race-replay/pull/47 **Author:** [@KingSajxxd](https://github.com/KingSajxxd) **Created:** 12/15/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`4aba004`](https://github.com/IAmTomShaw/f1-race-replay/commit/4aba00435db3188e77858a95c802b9bd823cb5a0) feat: Add lap times and interval gaps to race leaderboard ### 📊 Changes **3 files changed** (+140 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `src/f1_data.py` (+79 -13) 📝 `src/interfaces/race_replay.py` (+11 -3) 📝 `src/ui_components.py` (+50 -11) </details> ### 📄 Description <img width="1512" height="949" alt="Screenshot 2025-12-15 at 8 52 33 PM" src="https://github.com/user-attachments/assets/7a04b84d-8786-4dae-a989-6d199d139fbf" /> ## Description This PR enhances the Race Replay UI by adding two critical data points to the leaderboard: **Last Lap Time** and **Interval** (time gap to the car ahead). This brings the replay experience closer to a real F1 broadcast. Previously, the leaderboard only showed positions and tire compounds. Now, it calculates real-time gaps in seconds (interpolated from telemetry data) and displays the most recent lap time for every driver. ## Changes Overview ### 1. Data Processing (`src/f1_data.py`) **Added Last Lap Logic:** - Modified `_process_single_driver` to capture the `LapTime` of the previous lap and forward-fill it into the current lap's telemetry frames. **Added Interval Calculation:** - Updated `get_race_telemetry` to calculate the time gap (in seconds) between cars. - **Logic:** It uses `np.interp` to find the exact timestamp when the "car ahead" was at the "current car's" current distance, then calculates the difference (`current_time - time_ahead_was_here`). **Frame Payload:** - Updated the frame structure to include `last_lap_time_str` and `interval_str` for every driver. ### 2. UI Components (`src/ui_components.py`) **Widened Leaderboard:** - Increased `LeaderboardComponent` width from 240px to 400px to accommodate the new columns. **New Headers:** - Added a header row for POS / DRV, LAP TIME, and INTERVAL. **Rendering:** - Updated the `draw()` method to render the new `last_lap_time` (center-aligned) and `interval` (right-aligned) text strings. ### 3. Race Replay Interface (`src/interfaces/race_replay.py`) **Window Layout:** - Increased the `right_ui_margin` from 260 to 420 to fit the wider leaderboard without overlapping the track. **Data Passing:** - Updated `on_draw` to extract the new fields (`last_lap_time_str`, `interval_str`) from the frame data and pass them as a 6-item tuple to the `LeaderboardComponent`. ## How to Test Run the replay with the `--refresh-data` flag to regenerate the cache with the new metrics: ```bash python main.py --year 2024 --round 1 --refresh-data ``` Observe the leaderboard on the right side; it should now display lap times and intervals. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/f1-race-replay#99
No description provided.