Files
gridpilot.gg/apps/website/lib/view-models/DriverLeaderboardViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

39 lines
1.5 KiB
TypeScript

import { LeaderboardsViewData } from '@/lib/view-data/LeaderboardsViewData';
import { DriverLeaderboardItemViewModel } from './DriverLeaderboardItemViewModel';
import { ViewModel } from "../contracts/view-models/ViewModel";
export class DriverLeaderboardViewModel extends ViewModel {
drivers: DriverLeaderboardItemViewModel[];
constructor(
viewData: LeaderboardsViewData,
previousRatings?: Record<string, number>,
) {
super();
this.drivers = viewData.drivers.map((driver) => {
const previousRating = previousRatings?.[driver.id];
return new DriverLeaderboardItemViewModel(driver, previousRating);
});
}
/** UI-specific: Total races across all drivers */
get totalRaces(): number {
return this.drivers.reduce((sum, driver) => sum + driver.racesCompleted, 0);
}
/** UI-specific: Total wins across all drivers */
get totalWins(): number {
return this.drivers.reduce((sum, driver) => sum + driver.wins, 0);
}
/** UI-specific: Active drivers count */
get activeCount(): number {
// Note: LeaderboardDriverItem doesn't have isActive, but DriverLeaderboardItemViewModel might need it.
// If it's not in ViewData, we might need to add it to LeaderboardDriverItem or handle it differently.
// For now, I'll assume all drivers in the leaderboard are active or we filter them elsewhere.
// Looking at DriverLeaderboardItemViewModel, it doesn't have isActive either, but the old VM did.
return this.drivers.length;
}
}