Repository navigation
Conversation
The sidebar leaderboard is ordered every frame by a live on-track progress proxy (lap plus projected track distance). That sort keeps running after the checkered flag, where it no longer matches the classified result: post-race penalties, lapped cars and retirements change the finishing order without changing on-track progress, and the telemetry proxy is noisy once cars have parked. Add a GUI-free src/lib/leaderboard.py with two small helpers: official_finishing_order(results) reads the classified order from session.results, and order_leaderboard_codes(...) keeps the live order during the race but switches to the official order once it is over, without ever dropping a driver from the board. The replay window derives the official order from session.results at startup and applies it to the frozen final frame only, so mid-race ordering is untouched. Keeping the policy out of the arcade window lets it be unit tested headlessly. Add tests/test_leaderboard.py covering position ordering, retirements, unclassified rows, and the live/finished switch.
Author
|
Friendly bump on this when you have a minute. It still applies cleanly to main as far as I can tell. If you'd like it split up or changed, tell me and I'll update it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #309.
What was happening
The sidebar leaderboard is rebuilt every frame in
race_replay.pyby sorting drivers on a live progress metric:(lap - 1) * lap_length + projected_track_distance, largest first. That is a fine proxy for position while the cars are running, but the same sort keeps running after the checkered flag. At the finish it cannot be right:I confirmed this against real data before writing anything. I ran the full 2024 Spanish GP through
get_race_telemetryand looked at the last frame. The live order was:The actual result was
VER, NOR, HAM, RUS, LEC, SAI, ..., so the winner was being shown fifth and Hulkenberg was on top. That matches the report.How I approached it
My first instinct was to just re-sort in the draw method when the race is over, but that method lives inside the arcade window, which I cannot open headlessly on this machine, so I could not have tested it. So I pulled the ordering decision out into a small module with no arcade or FastF1 imports,
src/lib/leaderboard.py:official_finishing_order(results)reads the classified order straight fromsession.results, which FastF1 already sorts byPosition(that column reflects penalties, lapped cars and retirements, with retired drivers classified at the back).order_leaderboard_codes(live_order, official_order, race_finished)returns the live order untouched during the race, and the official order once it is over. It never drops a driver: anyone present live but missing from the classification is appended.The window derives the official order once from
session.resultsat startup and applies it only on the frozen final frame (frame_indexat the last frame). Mid-race ordering is byte-for-byte unchanged, so there is no risk to the normal replay.Testing
tests/test_leaderboard.py(8 cases) covers ordering byPositionregardless of row order, retirements and unclassified rows sorting to the back, the live/finished switch, and the "never drop a driver" behaviour. Runs offline with synthetic frames.official_finishing_orderagainst real sessions: exact match on 2024 Spain, and on 2024 Australia the retirements (Hamilton, Verstappen) correctly land at the back.I could not drive the arcade window itself without a display, so the rendering side is covered by the unit tests plus the end-to-end ordering check rather than by clicking through the GUI.
For transparency: I paired with Claude on this one. It was not fully autonomous, but the investigation, the design decision to keep the ordering testable, and the verification against real sessions were done together rather than blindly generated.