40 lines
1.3 KiB
TypeScript
40 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 { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import { AnalyticsDashboardInputViewData } from "../view-data/AnalyticsDashboardInputViewData";
|
|
|
|
export class AnalyticsDashboardViewModel extends ViewModel {
|
|
private readonly data: AnalyticsDashboardInputViewData;
|
|
|
|
constructor(data: AnalyticsDashboardInputViewData) {
|
|
super();
|
|
this.data = data;
|
|
}
|
|
|
|
get totalUsers(): number { return this.data.totalUsers; }
|
|
get activeUsers(): number { return this.data.activeUsers; }
|
|
get totalRaces(): number { return this.data.totalRaces; }
|
|
get totalLeagues(): number { return this.data.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';
|
|
}
|
|
} |