35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { AnalyticsDashboardInputViewData } from '@/lib/view-data/AnalyticsDashboardInputViewData';
|
|
import { AnalyticsDashboardViewData } from '@/lib/view-data/AnalyticsDashboardViewData';
|
|
|
|
/**
|
|
* AnalyticsDashboardViewDataBuilder
|
|
*
|
|
* Transforms AnalyticsDashboardInputViewData into AnalyticsDashboardViewData for server-side rendering.
|
|
* Deterministic; side-effect free; no HTTP calls.
|
|
*/
|
|
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
|
|
|
export class AnalyticsDashboardViewDataBuilder implements ViewDataBuilder<any, any> {
|
|
build(input: any): any {
|
|
return AnalyticsDashboardViewDataBuilder.build(input);
|
|
}
|
|
|
|
static build(viewData: AnalyticsDashboardInputViewData): AnalyticsDashboardViewData {
|
|
const userEngagementRate = viewData.totalUsers > 0 ? (viewData.activeUsers / viewData.totalUsers) * 100 : 0;
|
|
const formattedEngagementRate = `${userEngagementRate.toFixed(1)}%`;
|
|
const activityLevel = userEngagementRate > 70 ? 'High' : userEngagementRate > 40 ? 'Medium' : 'Low';
|
|
|
|
return {
|
|
metrics: {
|
|
totalUsers: viewData.totalUsers,
|
|
activeUsers: viewData.activeUsers,
|
|
totalRaces: viewData.totalRaces,
|
|
totalLeagues: viewData.totalLeagues,
|
|
userEngagementRate,
|
|
formattedEngagementRate,
|
|
activityLevel,
|
|
},
|
|
};
|
|
}
|
|
}
|