Files
gridpilot.gg/apps/website/lib/view-models/AnalyticsDashboardViewModel.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

41 lines
1.3 KiB
TypeScript

/**
* Analytics dashboard view model
*
* View model for analytics dashboard data.
*
* Accepts AnalyticsDashboardInputViewData as input and produces UI-ready data.
*/
import { AnalyticsDashboardInputViewData } from "../view-data/AnalyticsDashboardInputViewData";
import { ViewModel } from "../contracts/view-models/ViewModel";
export class AnalyticsDashboardViewModel extends ViewModel {
readonly totalUsers: number;
readonly activeUsers: number;
readonly totalRaces: number;
readonly totalLeagues: number;
constructor(viewData: AnalyticsDashboardInputViewData) {
super();
this.totalUsers = viewData.totalUsers;
this.activeUsers = viewData.activeUsers;
this.totalRaces = viewData.totalRaces;
this.totalLeagues = viewData.totalLeagues;
}
/** UI-specific: User engagement rate */
get userEngagementRate(): number {
return this.totalUsers > 0 ? (this.activeUsers / this.totalUsers) * 100 : 0;
}
/** UI-specific: Formatted engagement rate */
get formattedEngagementRate(): string {
return `${this.userEngagementRate.toFixed(1)}%`;
}
/** UI-specific: Activity level */
get activityLevel(): string {
if (this.userEngagementRate > 70) return 'High';
if (this.userEngagementRate > 40) return 'Medium';
return 'Low';
}
}