33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import type { GetDashboardDataOutputDTO } from '@/lib/types/generated/GetDashboardDataOutputDTO';
|
|
import type { AnalyticsDashboardViewData } from '@/lib/view-data/AnalyticsDashboardViewData';
|
|
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
|
|
|
export class AnalyticsDashboardViewDataBuilder {
|
|
public static build(apiDto: GetDashboardDataOutputDTO): AnalyticsDashboardViewData {
|
|
const totalUsers = apiDto.totalUsers;
|
|
const activeUsers = apiDto.activeUsers;
|
|
const totalRaces = apiDto.totalRaces;
|
|
const totalLeagues = apiDto.totalLeagues;
|
|
|
|
const userEngagementRate = totalUsers > 0 ? (activeUsers / totalUsers) * 100 : 0;
|
|
const formattedEngagementRate = `${userEngagementRate.toFixed(1)}%`;
|
|
const activityLevel = userEngagementRate > 70 ? 'High' : userEngagementRate > 40 ? 'Medium' : 'Low';
|
|
|
|
return {
|
|
metrics: {
|
|
totalUsers,
|
|
activeUsers,
|
|
totalRaces,
|
|
totalLeagues,
|
|
userEngagementRate,
|
|
formattedEngagementRate,
|
|
activityLevel,
|
|
},
|
|
};
|
|
}
|
|
}
|
|
|
|
AnalyticsDashboardViewDataBuilder satisfies ViewDataBuilder<GetDashboardDataOutputDTO, AnalyticsDashboardViewData>;
|