Files
gridpilot.gg/apps/website/lib/view-models/LeagueViewModel.ts
Marc Mintel 046852703f
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-24 12:14:08 +01:00

64 lines
2.2 KiB
TypeScript

import { ViewModel } from "../contracts/view-models/ViewModel";
import { CurrencyFormatter } from "../formatters/CurrencyFormatter";
import { LeagueTierFormatter } from "../formatters/LeagueTierFormatter";
import type { LeagueViewData } from "../view-data/LeagueViewData";
export class LeagueViewModel extends ViewModel {
private readonly data: LeagueViewData;
constructor(data: LeagueViewData) {
super();
this.data = data;
}
get id(): string { return this.data.id; }
get name(): string { return this.data.name; }
get game(): string { return this.data.game; }
get tier(): 'premium' | 'standard' | 'starter' { return this.data.tier; }
get season(): string { return this.data.season; }
get description(): string { return this.data.description; }
get drivers(): number { return this.data.drivers; }
get races(): number { return this.data.races; }
get completedRaces(): number { return this.data.completedRaces; }
get totalImpressions(): number { return this.data.totalImpressions; }
get avgViewsPerRace(): number { return this.data.avgViewsPerRace; }
get engagement(): number { return this.data.engagement; }
get rating(): number { return this.data.rating; }
get seasonStatus(): 'active' | 'upcoming' | 'completed' { return this.data.seasonStatus; }
get seasonDates() { return this.data.seasonDates; }
get nextRace() { return this.data.nextRace; }
get sponsorSlots() { return this.data.sponsorSlots; }
get formattedTotalImpressions(): string {
return this.totalImpressions.toLocaleString();
}
get formattedAvgViewsPerRace(): string {
return this.avgViewsPerRace.toLocaleString();
}
get projectedTotalViews(): number {
return Math.round(this.avgViewsPerRace * this.races);
}
get formattedProjectedTotal(): string {
return this.projectedTotalViews.toLocaleString();
}
get mainSponsorCpm(): number {
return Math.round((this.sponsorSlots.main.price / this.projectedTotalViews) * 1000);
}
get formattedMainSponsorCpm(): string {
return CurrencyFormatter.format(this.mainSponsorCpm);
}
get racesLeft(): number {
return this.races - this.completedRaces;
}
get tierConfig() {
return LeagueTierFormatter.getDisplay(this.tier);
}
}