Implement a comprehensive reports dashboard including user question summaries, AI performance metrics, and usage trends. This includes the creation of several reusable chart components and supporting services. - Add `ReportsPage` with tabbed navigation for questions and performance - Implement `ReportsService` with mock data support for rapid development - Create reusable UI components: `BarChartComponent`, `DoughnutChartComponent`, and `LineChartComponent` - Add `format.util.ts` for Persian digit and number formatting - Integrate 'Lahze' font family and add font assets - Add unit tests for `ReportsPage` and `ReportsService`
89 lines
3.3 KiB
TypeScript
89 lines
3.3 KiB
TypeScript
import {
|
|
AiChannelUsage,
|
|
AiPerformance,
|
|
CategoryShare,
|
|
QuestionSummary,
|
|
TopQuestion,
|
|
UsageTrendPoint,
|
|
} from './reports.types';
|
|
|
|
const TREND_DAYS = 30;
|
|
|
|
/** Deterministic pseudo-random source so mock data stays stable across reloads and tests. */
|
|
function seededNoise(seed: number): number {
|
|
const value = Math.sin(seed * 12.9898) * 43758.5453;
|
|
return Math.abs(value - Math.floor(value));
|
|
}
|
|
|
|
function buildTrend(): UsageTrendPoint[] {
|
|
const points: UsageTrendPoint[] = [];
|
|
const today = new Date();
|
|
|
|
for (let offset = TREND_DAYS - 1; offset >= 0; offset--) {
|
|
const date = new Date(today);
|
|
date.setDate(today.getDate() - offset);
|
|
|
|
const weekday = date.getDay();
|
|
const isWeekend = weekday === 4 || weekday === 5;
|
|
const noise = seededNoise(offset + 1);
|
|
|
|
// Recent campaign window lifts the last two weeks.
|
|
const campaign = offset <= 14 ? 9 : 0;
|
|
const base = isWeekend ? 34 : 58;
|
|
|
|
const count = Math.round(base + noise * 22 - (isWeekend ? 12 : 0) + campaign);
|
|
|
|
points.push({
|
|
label: date.toLocaleDateString('fa-IR', { day: 'numeric', month: 'long' }),
|
|
count,
|
|
});
|
|
}
|
|
|
|
return points;
|
|
}
|
|
|
|
export const MOCK_TOP_QUESTIONS: TopQuestion[] = [
|
|
{ id: 'q1', text: 'چگونه رمز عبور حساب کاربری خود را بازیابی کنم؟', count: 142, category: 'حساب کاربری' },
|
|
{ id: 'q2', text: 'ساعات کاری پشتیبانی در چه ساعتی است؟', count: 128, category: 'پشتیبانی' },
|
|
{ id: 'q3', text: 'برای دریافت فاکتور رسمی چگونه اقدام کنم؟', count: 97, category: 'پرداخت و فاکتور' },
|
|
{ id: 'q4', text: 'آیا ارسال به شهرستانها امکانپذیر است؟', count: 88, category: 'سفارش و ارسال' },
|
|
{ id: 'q5', text: 'چگونه سفارش خود را پیگیری کنم؟', count: 76, category: 'سفارش و ارسال' },
|
|
{ id: 'q6', text: 'هزینه ارسال چگونه محاسبه میشود؟', count: 61, category: 'سفارش و ارسال' },
|
|
{ id: 'q7', text: 'شرایط مرجوع کردن کالا چیست؟', count: 54, category: 'پشتیبانی' },
|
|
{ id: 'q8', text: 'آیا امکان پرداخت اقساطی وجود دارد؟', count: 47, category: 'پرداخت و فاکتور' },
|
|
];
|
|
|
|
export const MOCK_QUESTION_SUMMARY: QuestionSummary = {
|
|
totalQuestions: 4802,
|
|
uniqueUsers: 1736,
|
|
aiAnswered: 4318,
|
|
escalatedToAgent: 484,
|
|
periodLabel: '۳۰ روز گذشته',
|
|
};
|
|
|
|
export const MOCK_CATEGORY_SHARES: CategoryShare[] = [
|
|
{ category: 'حساب کاربری', count: 1265 },
|
|
{ category: 'سفارش و ارسال', count: 1148 },
|
|
{ category: 'پرداخت و فاکتور', count: 862 },
|
|
{ category: 'پشتیبانی', count: 668 },
|
|
{ category: 'محصولات', count: 479 },
|
|
{ category: 'سایر', count: 380 },
|
|
];
|
|
|
|
export const MOCK_USAGE_TREND: UsageTrendPoint[] = buildTrend();
|
|
|
|
export const MOCK_AI_CHANNELS: AiChannelUsage[] = [
|
|
{ label: 'گفتگوی متنی', count: 3622 },
|
|
{ label: 'گفتگوی صوتی', count: 1180 },
|
|
];
|
|
|
|
export const MOCK_AI_PERFORMANCE: AiPerformance = {
|
|
totalResponses: 4802,
|
|
faqBasedResponses: 3553,
|
|
avgResponseSeconds: 1.8,
|
|
successRate: 91,
|
|
satisfactionRate: 87,
|
|
escalationRate: 10,
|
|
channels: MOCK_AI_CHANNELS,
|
|
};
|