feat: add weekly summary features and components
- Introduced `CategoryBreakdown`, `JiraWeeklyMetrics`, `PeriodSelector`, and `VelocityMetrics` components to enhance the weekly summary dashboard. - Updated `WeeklySummaryClient` to manage period selection and PDF export functionality. - Enhanced `WeeklySummaryService` to support period comparisons and activity categorization. - Added new API route for fetching weekly summary data based on selected period. - Updated `package.json` and `package-lock.json` to include `jspdf` and related types for PDF generation. - Marked several tasks as complete in `TODO.md` to reflect progress on summary features.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { prisma } from './database';
|
||||
import { Task, TaskStatus, TaskPriority, TaskSource } from '@/lib/types';
|
||||
import { TaskCategorizationService } from './task-categorization';
|
||||
|
||||
export interface DailyItem {
|
||||
id: string;
|
||||
@@ -39,44 +40,99 @@ export interface WeeklyActivity {
|
||||
dayName: string;
|
||||
}
|
||||
|
||||
export interface VelocityMetrics {
|
||||
currentWeekTasks: number;
|
||||
previousWeekTasks: number;
|
||||
weeklyTrend: number; // Pourcentage d'amélioration/détérioration
|
||||
fourWeekAverage: number;
|
||||
weeklyData: Array<{
|
||||
weekStart: Date;
|
||||
weekEnd: Date;
|
||||
completedTasks: number;
|
||||
completedCheckboxes: number;
|
||||
totalActivities: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface PeriodComparison {
|
||||
currentPeriod: {
|
||||
tasks: number;
|
||||
checkboxes: number;
|
||||
total: number;
|
||||
};
|
||||
previousPeriod: {
|
||||
tasks: number;
|
||||
checkboxes: number;
|
||||
total: number;
|
||||
};
|
||||
changes: {
|
||||
tasks: number; // pourcentage de changement
|
||||
checkboxes: number;
|
||||
total: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface WeeklySummary {
|
||||
stats: WeeklyStats;
|
||||
activities: WeeklyActivity[];
|
||||
velocity: VelocityMetrics;
|
||||
categoryBreakdown: { [categoryName: string]: { count: number; percentage: number; color: string; icon: string } };
|
||||
periodComparison: PeriodComparison | null;
|
||||
period: {
|
||||
start: Date;
|
||||
end: Date;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PeriodOption {
|
||||
label: string;
|
||||
days: number;
|
||||
key: string;
|
||||
}
|
||||
|
||||
export const PERIOD_OPTIONS: PeriodOption[] = [
|
||||
{ label: 'Dernière semaine', days: 7, key: 'week' },
|
||||
{ label: 'Dernières 2 semaines', days: 14, key: '2weeks' },
|
||||
{ label: 'Dernier mois', days: 30, key: 'month' }
|
||||
];
|
||||
|
||||
export class WeeklySummaryService {
|
||||
/**
|
||||
* Récupère le résumé complet de la semaine écoulée
|
||||
*/
|
||||
static async getWeeklySummary(): Promise<WeeklySummary> {
|
||||
static async getWeeklySummary(periodDays: number = 7): Promise<WeeklySummary> {
|
||||
const now = new Date();
|
||||
const startOfWeek = new Date(now);
|
||||
startOfWeek.setDate(now.getDate() - 7);
|
||||
startOfWeek.setHours(0, 0, 0, 0);
|
||||
const startOfPeriod = new Date(now);
|
||||
startOfPeriod.setDate(now.getDate() - periodDays);
|
||||
startOfPeriod.setHours(0, 0, 0, 0);
|
||||
|
||||
const endOfWeek = new Date(now);
|
||||
endOfWeek.setHours(23, 59, 59, 999);
|
||||
const endOfPeriod = new Date(now);
|
||||
endOfPeriod.setHours(23, 59, 59, 999);
|
||||
|
||||
console.log(`📊 Génération du résumé hebdomadaire du ${startOfWeek.toLocaleDateString()} au ${endOfWeek.toLocaleDateString()}`);
|
||||
console.log(`📊 Génération du résumé (${periodDays} jours) du ${startOfPeriod.toLocaleDateString()} au ${endOfPeriod.toLocaleDateString()}`);
|
||||
|
||||
const [checkboxes, tasks] = await Promise.all([
|
||||
this.getWeeklyCheckboxes(startOfWeek, endOfWeek),
|
||||
this.getWeeklyTasks(startOfWeek, endOfWeek)
|
||||
const [checkboxes, tasks, velocity] = await Promise.all([
|
||||
this.getWeeklyCheckboxes(startOfPeriod, endOfPeriod),
|
||||
this.getWeeklyTasks(startOfPeriod, endOfPeriod),
|
||||
this.calculateVelocityMetrics(endOfPeriod)
|
||||
]);
|
||||
|
||||
const stats = this.calculateStats(checkboxes, tasks, startOfWeek, endOfWeek);
|
||||
const stats = this.calculateStats(checkboxes, tasks, startOfPeriod, endOfPeriod);
|
||||
const activities = this.mergeActivities(checkboxes, tasks);
|
||||
const categoryBreakdown = this.analyzeCategorization(checkboxes, tasks);
|
||||
|
||||
// Calculer la comparaison avec la période précédente
|
||||
const periodComparison = await this.calculatePeriodComparison(startOfPeriod, endOfPeriod, periodDays);
|
||||
|
||||
return {
|
||||
stats,
|
||||
activities,
|
||||
velocity,
|
||||
categoryBreakdown,
|
||||
periodComparison,
|
||||
period: {
|
||||
start: startOfWeek,
|
||||
end: endOfWeek
|
||||
start: startOfPeriod,
|
||||
end: endOfPeriod
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -214,6 +270,128 @@ export class WeeklySummaryService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcule les métriques de vélocité sur 4 semaines
|
||||
*/
|
||||
private static async calculateVelocityMetrics(currentEndDate: Date): Promise<VelocityMetrics> {
|
||||
const weeks = [];
|
||||
const currentDate = new Date(currentEndDate);
|
||||
|
||||
// Générer les 4 dernières semaines
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const weekEnd = new Date(currentDate);
|
||||
weekEnd.setDate(weekEnd.getDate() - (i * 7));
|
||||
weekEnd.setHours(23, 59, 59, 999);
|
||||
|
||||
const weekStart = new Date(weekEnd);
|
||||
weekStart.setDate(weekEnd.getDate() - 6);
|
||||
weekStart.setHours(0, 0, 0, 0);
|
||||
|
||||
const [weekCheckboxes, weekTasks] = await Promise.all([
|
||||
this.getWeeklyCheckboxes(weekStart, weekEnd),
|
||||
this.getWeeklyTasks(weekStart, weekEnd)
|
||||
]);
|
||||
|
||||
const completedTasks = weekTasks.filter(t => t.status === 'done').length;
|
||||
const completedCheckboxes = weekCheckboxes.filter(c => c.isChecked).length;
|
||||
|
||||
weeks.push({
|
||||
weekStart,
|
||||
weekEnd,
|
||||
completedTasks,
|
||||
completedCheckboxes,
|
||||
totalActivities: completedTasks + completedCheckboxes
|
||||
});
|
||||
}
|
||||
|
||||
// Calculer les métriques
|
||||
const currentWeek = weeks[0];
|
||||
const previousWeek = weeks[1];
|
||||
const fourWeekAverage = weeks.reduce((sum, week) => sum + week.totalActivities, 0) / weeks.length;
|
||||
|
||||
let weeklyTrend = 0;
|
||||
if (previousWeek.totalActivities > 0) {
|
||||
weeklyTrend = ((currentWeek.totalActivities - previousWeek.totalActivities) / previousWeek.totalActivities) * 100;
|
||||
} else if (currentWeek.totalActivities > 0) {
|
||||
weeklyTrend = 100; // 100% d'amélioration si on passe de 0 à quelque chose
|
||||
}
|
||||
|
||||
return {
|
||||
currentWeekTasks: currentWeek.completedTasks,
|
||||
previousWeekTasks: previousWeek.completedTasks,
|
||||
weeklyTrend,
|
||||
fourWeekAverage,
|
||||
weeklyData: weeks.reverse() // Plus ancien en premier pour l'affichage du graphique
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcule la comparaison avec la période précédente
|
||||
*/
|
||||
private static async calculatePeriodComparison(
|
||||
currentStart: Date,
|
||||
currentEnd: Date,
|
||||
periodDays: number
|
||||
): Promise<PeriodComparison> {
|
||||
// Période précédente
|
||||
const previousEnd = new Date(currentStart);
|
||||
previousEnd.setHours(23, 59, 59, 999);
|
||||
|
||||
const previousStart = new Date(previousEnd);
|
||||
previousStart.setDate(previousEnd.getDate() - periodDays);
|
||||
previousStart.setHours(0, 0, 0, 0);
|
||||
|
||||
const [currentCheckboxes, currentTasks, previousCheckboxes, previousTasks] = await Promise.all([
|
||||
this.getWeeklyCheckboxes(currentStart, currentEnd),
|
||||
this.getWeeklyTasks(currentStart, currentEnd),
|
||||
this.getWeeklyCheckboxes(previousStart, previousEnd),
|
||||
this.getWeeklyTasks(previousStart, previousEnd)
|
||||
]);
|
||||
|
||||
const currentCompletedTasks = currentTasks.filter(t => t.status === 'done').length;
|
||||
const currentCompletedCheckboxes = currentCheckboxes.filter(c => c.isChecked).length;
|
||||
const currentTotal = currentCompletedTasks + currentCompletedCheckboxes;
|
||||
|
||||
const previousCompletedTasks = previousTasks.filter(t => t.status === 'done').length;
|
||||
const previousCompletedCheckboxes = previousCheckboxes.filter(c => c.isChecked).length;
|
||||
const previousTotal = previousCompletedTasks + previousCompletedCheckboxes;
|
||||
|
||||
const calculateChange = (current: number, previous: number): number => {
|
||||
if (previous === 0) return current > 0 ? 100 : 0;
|
||||
return ((current - previous) / previous) * 100;
|
||||
};
|
||||
|
||||
return {
|
||||
currentPeriod: {
|
||||
tasks: currentCompletedTasks,
|
||||
checkboxes: currentCompletedCheckboxes,
|
||||
total: currentTotal
|
||||
},
|
||||
previousPeriod: {
|
||||
tasks: previousCompletedTasks,
|
||||
checkboxes: previousCompletedCheckboxes,
|
||||
total: previousTotal
|
||||
},
|
||||
changes: {
|
||||
tasks: calculateChange(currentCompletedTasks, previousCompletedTasks),
|
||||
checkboxes: calculateChange(currentCompletedCheckboxes, previousCompletedCheckboxes),
|
||||
total: calculateChange(currentTotal, previousTotal)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyse la catégorisation des activités
|
||||
*/
|
||||
private static analyzeCategorization(checkboxes: DailyItem[], tasks: Task[]): { [categoryName: string]: { count: number; percentage: number; color: string; icon: string } } {
|
||||
const allActivities = [
|
||||
...checkboxes.map(c => ({ title: c.text, description: '' })),
|
||||
...tasks.map(t => ({ title: t.title, description: t.description || '' }))
|
||||
];
|
||||
|
||||
return TaskCategorizationService.analyzeActivitiesByCategory(allActivities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fusionne les activités (checkboxes + tâches) en une timeline
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user