Skip to content

Commit 8cacbbd

Browse files
authored
fix: don't use car number as a fallback for position (#32)
1 parent de453fd commit 8cacbbd

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/frontend/components/Standings/components/DriverInfoRow/DriverInfoRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface DriverRowInfoProps {
1212
isPlayer: boolean;
1313
hasFastestTime: boolean;
1414
delta?: number;
15-
position: number;
15+
position?: number;
1616
badge?: React.ReactNode;
1717
iratingChange?: React.ReactNode;
1818
lastTime?: number;

src/frontend/components/Standings/createStandings.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
export interface Standings {
1515
carIdx: number;
1616
position?: number;
17-
classPosition: number;
17+
classPosition?: number;
1818
lap?: number;
1919
lappedState?: 'ahead' | 'behind' | 'same';
2020
delta?: number;
@@ -171,14 +171,16 @@ export const augmentStandingsWithIRating = (
171171
groupedStandings: [string, Standings[]][]
172172
): [string, Standings[]][] => {
173173
return groupedStandings.map(([classId, classStandings]) => {
174-
const raceResultsInput: RaceResult<number>[] = classStandings.map(
175-
(driverStanding) => ({
176-
driver: driverStanding.carIdx,
177-
finishRank: driverStanding.classPosition,
178-
startIRating: driverStanding.driver.rating,
179-
started: true, // This is a critical assumption.
180-
})
181-
);
174+
const raceResultsInput: RaceResult<number>[] = classStandings
175+
.filter(s => !!s.classPosition) // Only include drivers with a class position, should not happen in races
176+
.map(
177+
(driverStanding) => ({
178+
driver: driverStanding.carIdx,
179+
finishRank: driverStanding.classPosition ?? 0,
180+
startIRating: driverStanding.driver.rating,
181+
started: true, // This is a critical assumption.
182+
})
183+
);
182184

183185
if (raceResultsInput.length === 0) {
184186
return [classId, classStandings];

src/frontend/components/Standings/hooks/useDriverPositions.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,12 @@ export const useDriverStandings = () => {
9696
}
9797

9898
// If the driver is not in the standings, use the qualifying position
99-
// else fallback to the car number, shitty workaround for now
100-
let classPosition = driverPos.classPosition;
99+
let classPosition: number | undefined = driverPos.classPosition;
101100
if (classPosition <= 0) {
102101
const qualifyingPosition = qualifyingPositions?.find(
103102
(q) => q.CarIdx === driver.carIdx
104103
);
105-
classPosition = qualifyingPosition
106-
? qualifyingPosition.Position + 1
107-
: driver.carNumRaw;
104+
classPosition = qualifyingPosition ? qualifyingPosition.Position + 1 : undefined;
108105
}
109106

110107
return {

0 commit comments

Comments
 (0)