[PR #133] fix(core): Resolve Leaderboard Positioning Anomalies via Distance Metric Refactor #164

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

📋 Pull Request Information

Original PR: https://github.com/IAmTomShaw/f1-race-replay/pull/133
Author: @shash-hq
Created: 12/27/2025
Status: 🔄 Open

Base: mainHead: fix/leaderboard-position


📝 Commits (10+)

  • fcb3b48 Fix: Leaderboard positions now use reliable FastF1 distance metric
  • bece282 Feat: Add Fastest Lap Sectors to Qualifying Leaderboard
  • b21580e Fix(data): Add error logging for missing sector data
  • 55affd9 fix(deps): pin compatible dependencies for python 3.14
  • b132a87 fix(cli): use argparse and decouple library logic
  • 5872136 refactor: extract duplicate weather processing logic
  • 918e6c5 feat(cli): add global exception handling for better user experience
  • c6d5721 fix(data): correctly accumulate race distance across laps
  • c73bd2a fix(gui): log errors instead of silencing them
  • f130fa1 fix(core): Apply grid offset to leaderboard distance metric

📊 Changes

6 files changed (+198 additions, -187 deletions)

View changed files

📝 main.py (+57 -40)
📝 requirements.txt (+6 -5)
📝 src/f1_data.py (+84 -108)
📝 src/gui/race_selection.py (+4 -4)
📝 src/interfaces/race_replay.py (+10 -20)
📝 src/ui_components.py (+37 -10)

📄 Description

Analysis of Issue

An investigation into the repository's src/interfaces/race_replay.py revealed that the leaderboard sorting mechanism relied on a geometric projection of (x, y) coordinates onto a reference track line. This approach introduced significant inaccuracies:

  • Pit Stops: Vehicles in the pit lane were projected onto the adjacent main track, causing erroneous distance calculations.
  • Lap Transition: The "wrap-around" logic for the start/finish line was heuristic and prone to edge-case failures (e.g., negative progress glitches).

Additionally, the src/f1_data.py data ingestion pipeline failed to accumulate Distance across laps, resetting the metric to zero on each new lap, which necessitated the faulty projection logic.

Implementation Details

  1. Data Pipeline Fix (src/f1_data.py):

    • Implemented accumulation logic for the total_dist_so_far variable within the telemetry processing loop.
    • Ensures the dist field now represents the true, monotonically increasing race distance fetched from FastF1.
  2. Leaderboard Logic Refactor (src/interfaces/race_replay.py):

    • Deprecated the _project_to_reference method for leaderboard sorting.
    • Refactored driver_progress calculation to utilize the verified dist telemetry field directly.
    • Removed the fragile "Lap 1 negative progress" workaround.

Verification

  • Verified that leaderboard order remains stable during pit stops.
  • Confirmed seamless lap transitions without positional flickering.

🔄 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/133 **Author:** [@shash-hq](https://github.com/shash-hq) **Created:** 12/27/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/leaderboard-position` --- ### 📝 Commits (10+) - [`fcb3b48`](https://github.com/IAmTomShaw/f1-race-replay/commit/fcb3b486850aa3cd741cbcf40fc9df52e06e70ca) Fix: Leaderboard positions now use reliable FastF1 distance metric - [`bece282`](https://github.com/IAmTomShaw/f1-race-replay/commit/bece28290b1ae21e3edf713ec368743a2159b2b9) Feat: Add Fastest Lap Sectors to Qualifying Leaderboard - [`b21580e`](https://github.com/IAmTomShaw/f1-race-replay/commit/b21580e71ea383730853f4351170aecfdc1c3c32) Fix(data): Add error logging for missing sector data - [`55affd9`](https://github.com/IAmTomShaw/f1-race-replay/commit/55affd9d4a38b09568eb904a8be22df1c5b4bcc9) fix(deps): pin compatible dependencies for python 3.14 - [`b132a87`](https://github.com/IAmTomShaw/f1-race-replay/commit/b132a8777456e5737b4b230fc82a8f40cc15cc57) fix(cli): use argparse and decouple library logic - [`5872136`](https://github.com/IAmTomShaw/f1-race-replay/commit/58721364609a02e7aa5e0e2c917108860b8b7199) refactor: extract duplicate weather processing logic - [`918e6c5`](https://github.com/IAmTomShaw/f1-race-replay/commit/918e6c50ecfbe04f8d227d74c35ccb9a4c688369) feat(cli): add global exception handling for better user experience - [`c6d5721`](https://github.com/IAmTomShaw/f1-race-replay/commit/c6d5721f417b07b8731bbb48b0570a0f0f255deb) fix(data): correctly accumulate race distance across laps - [`c73bd2a`](https://github.com/IAmTomShaw/f1-race-replay/commit/c73bd2af6a9ae932a4f042c3336a9b8535104989) fix(gui): log errors instead of silencing them - [`f130fa1`](https://github.com/IAmTomShaw/f1-race-replay/commit/f130fa1f7ffb6a4a515300a00a2d73c97bae404b) fix(core): Apply grid offset to leaderboard distance metric ### 📊 Changes **6 files changed** (+198 additions, -187 deletions) <details> <summary>View changed files</summary> 📝 `main.py` (+57 -40) 📝 `requirements.txt` (+6 -5) 📝 `src/f1_data.py` (+84 -108) 📝 `src/gui/race_selection.py` (+4 -4) 📝 `src/interfaces/race_replay.py` (+10 -20) 📝 `src/ui_components.py` (+37 -10) </details> ### 📄 Description ## Analysis of Issue An investigation into the repository's `src/interfaces/race_replay.py` revealed that the leaderboard sorting mechanism relied on a geometric projection of `(x, y)` coordinates onto a reference track line. This approach introduced significant inaccuracies: - **Pit Stops:** Vehicles in the pit lane were projected onto the adjacent main track, causing erroneous distance calculations. - **Lap Transition:** The "wrap-around" logic for the start/finish line was heuristic and prone to edge-case failures (e.g., negative progress glitches). Additionally, the `src/f1_data.py` data ingestion pipeline failed to accumulate `Distance` across laps, resetting the metric to zero on each new lap, which necessitated the faulty projection logic. ## Implementation Details 1. **Data Pipeline Fix (`src/f1_data.py`):** - Implemented accumulation logic for the `total_dist_so_far` variable within the telemetry processing loop. - Ensures the `dist` field now represents the true, monotonically increasing race distance fetched from FastF1. 2. **Leaderboard Logic Refactor (`src/interfaces/race_replay.py`):** - Deprecated the `_project_to_reference` method for leaderboard sorting. - Refactored `driver_progress` calculation to utilize the verified `dist` telemetry field directly. - Removed the fragile "Lap 1 negative progress" workaround. ## Verification - Verified that leaderboard order remains stable during pit stops. - Confirmed seamless lap transitions without positional flickering. --- <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#164
No description provided.