refactor: remove deprecated weekly summary components and related services
- Deleted `WeeklySummaryClient`, `VelocityMetrics`, `PeriodSelector`, and associated services to streamline the codebase. - Removed the `weekly-summary` API route and related PDF export functionality, as these features are no longer in use. - Updated `TODO.md` to reflect the removal of these components and their functionalities.
This commit is contained in:
@@ -1,193 +0,0 @@
|
||||
import jsPDF from 'jspdf';
|
||||
import { WeeklySummary } from './weekly-summary';
|
||||
|
||||
export class PDFExportService {
|
||||
/**
|
||||
* Génère un PDF du résumé hebdomadaire
|
||||
*/
|
||||
static async exportWeeklySummary(summary: WeeklySummary): Promise<void> {
|
||||
const pdf = new jsPDF();
|
||||
const pageWidth = pdf.internal.pageSize.getWidth();
|
||||
const margin = 20;
|
||||
let yPosition = margin + 10;
|
||||
|
||||
// Header avec logo/titre
|
||||
pdf.setFontSize(24);
|
||||
pdf.setFont('helvetica', 'bold');
|
||||
pdf.text('📊 RÉSUMÉ HEBDOMADAIRE', pageWidth / 2, yPosition, { align: 'center' });
|
||||
|
||||
yPosition += 15;
|
||||
pdf.setFontSize(12);
|
||||
pdf.setFont('helvetica', 'normal');
|
||||
const dateRange = `Du ${this.formatDate(summary.period.start)} au ${this.formatDate(summary.period.end)}`;
|
||||
pdf.text(dateRange, pageWidth / 2, yPosition, { align: 'center' });
|
||||
|
||||
yPosition += 20;
|
||||
|
||||
// Section métriques principales
|
||||
pdf.setFontSize(16);
|
||||
pdf.setFont('helvetica', 'bold');
|
||||
pdf.text('🎯 MÉTRIQUES PRINCIPALES', margin, yPosition);
|
||||
yPosition += 15;
|
||||
|
||||
pdf.setFontSize(11);
|
||||
pdf.setFont('helvetica', 'normal');
|
||||
|
||||
// Statistiques en deux colonnes
|
||||
const statsLeft = [
|
||||
`Tâches complétées: ${summary.stats.completedTasks}/${summary.stats.totalTasks}`,
|
||||
`Taux de réussite tâches: ${summary.stats.taskCompletionRate.toFixed(1)}%`,
|
||||
`Daily items complétés: ${summary.stats.completedCheckboxes}/${summary.stats.totalCheckboxes}`,
|
||||
`Taux de réussite daily: ${summary.stats.checkboxCompletionRate.toFixed(1)}%`
|
||||
];
|
||||
|
||||
const statsRight = [
|
||||
`Vélocité actuelle: ${summary.velocity.currentWeekTasks} tâches`,
|
||||
`Semaine précédente: ${summary.velocity.previousWeekTasks} tâches`,
|
||||
`Moyenne 4 semaines: ${summary.velocity.fourWeekAverage.toFixed(1)}`,
|
||||
`Tendance: ${this.formatTrend(summary.velocity.weeklyTrend)}`
|
||||
];
|
||||
|
||||
// Colonne gauche
|
||||
statsLeft.forEach((stat, index) => {
|
||||
pdf.text(`• ${stat}`, margin, yPosition + (index * 8));
|
||||
});
|
||||
|
||||
// Colonne droite
|
||||
statsRight.forEach((stat, index) => {
|
||||
pdf.text(`• ${stat}`, pageWidth / 2 + 10, yPosition + (index * 8));
|
||||
});
|
||||
|
||||
yPosition += 40;
|
||||
|
||||
// Section jour le plus productif
|
||||
pdf.setFontSize(14);
|
||||
pdf.setFont('helvetica', 'bold');
|
||||
pdf.text('⭐ INSIGHTS', margin, yPosition);
|
||||
yPosition += 12;
|
||||
|
||||
pdf.setFontSize(11);
|
||||
pdf.setFont('helvetica', 'normal');
|
||||
pdf.text(`• Jour le plus productif: ${summary.stats.mostProductiveDay}`, margin + 5, yPosition);
|
||||
yPosition += 8;
|
||||
|
||||
// Tendance insight
|
||||
let trendInsight = '';
|
||||
if (summary.velocity.weeklyTrend > 10) {
|
||||
trendInsight = `• Excellente progression ! Amélioration de ${summary.velocity.weeklyTrend.toFixed(1)}% cette semaine.`;
|
||||
} else if (summary.velocity.weeklyTrend < -10) {
|
||||
trendInsight = `• Baisse d'activité de ${Math.abs(summary.velocity.weeklyTrend).toFixed(1)}%. Temps de revoir le planning ?`;
|
||||
} else {
|
||||
trendInsight = '• Rythme stable maintenu cette semaine.';
|
||||
}
|
||||
pdf.text(trendInsight, margin + 5, yPosition);
|
||||
yPosition += 12;
|
||||
|
||||
// Section breakdown par jour
|
||||
pdf.setFontSize(14);
|
||||
pdf.setFont('helvetica', 'bold');
|
||||
pdf.text('📅 RÉPARTITION PAR JOUR', margin, yPosition);
|
||||
yPosition += 12;
|
||||
|
||||
pdf.setFontSize(10);
|
||||
pdf.setFont('helvetica', 'normal');
|
||||
|
||||
// Headers du tableau
|
||||
const colWidth = (pageWidth - 2 * margin) / 4;
|
||||
pdf.text('Jour', margin, yPosition);
|
||||
pdf.text('Tâches', margin + colWidth, yPosition);
|
||||
pdf.text('Daily Items', margin + 2 * colWidth, yPosition);
|
||||
pdf.text('Total', margin + 3 * colWidth, yPosition);
|
||||
yPosition += 8;
|
||||
|
||||
// Ligne de séparation
|
||||
pdf.line(margin, yPosition - 2, pageWidth - margin, yPosition - 2);
|
||||
|
||||
// Données du tableau
|
||||
summary.stats.dailyBreakdown.forEach((day) => {
|
||||
pdf.text(day.dayName, margin, yPosition);
|
||||
pdf.text(`${day.completedTasks}/${day.tasks}`, margin + colWidth, yPosition);
|
||||
pdf.text(`${day.completedCheckboxes}/${day.checkboxes}`, margin + 2 * colWidth, yPosition);
|
||||
pdf.text(`${day.completedTasks + day.completedCheckboxes}`, margin + 3 * colWidth, yPosition);
|
||||
yPosition += 6;
|
||||
});
|
||||
|
||||
yPosition += 10;
|
||||
|
||||
// Section principales réalisations
|
||||
pdf.setFontSize(14);
|
||||
pdf.setFont('helvetica', 'bold');
|
||||
pdf.text('✅ PRINCIPALES RÉALISATIONS', margin, yPosition);
|
||||
yPosition += 12;
|
||||
|
||||
pdf.setFontSize(10);
|
||||
pdf.setFont('helvetica', 'normal');
|
||||
|
||||
const completedActivities = summary.activities
|
||||
.filter(a => a.completed)
|
||||
.slice(0, 8); // Top 8 réalisations
|
||||
|
||||
if (completedActivities.length === 0) {
|
||||
pdf.text('Aucune réalisation complétée cette semaine.', margin + 5, yPosition);
|
||||
yPosition += 8;
|
||||
} else {
|
||||
completedActivities.forEach((activity) => {
|
||||
const truncatedTitle = activity.title.length > 60
|
||||
? activity.title.substring(0, 57) + '...'
|
||||
: activity.title;
|
||||
|
||||
const icon = activity.type === 'task' ? '🎯' : '✅';
|
||||
pdf.text(`${icon} ${truncatedTitle}`, margin + 5, yPosition);
|
||||
yPosition += 6;
|
||||
|
||||
// Nouvelle page si nécessaire
|
||||
if (yPosition > pdf.internal.pageSize.getHeight() - 30) {
|
||||
pdf.addPage();
|
||||
yPosition = margin + 10;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Footer
|
||||
const totalPages = pdf.internal.getNumberOfPages();
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
pdf.setPage(i);
|
||||
pdf.setFontSize(8);
|
||||
pdf.setFont('helvetica', 'normal');
|
||||
const footerText = `TowerControl - Généré le ${new Date().toLocaleDateString('fr-FR')} - Page ${i}/${totalPages}`;
|
||||
pdf.text(footerText, pageWidth / 2, pdf.internal.pageSize.getHeight() - 10, { align: 'center' });
|
||||
}
|
||||
|
||||
// Télécharger le PDF
|
||||
const fileName = `weekly-summary-${this.formatDateForFilename(summary.period.start)}_${this.formatDateForFilename(summary.period.end)}.pdf`;
|
||||
pdf.save(fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate une date pour l'affichage
|
||||
*/
|
||||
private static formatDate(date: Date): string {
|
||||
return new Date(date).toLocaleDateString('fr-FR', {
|
||||
weekday: 'long',
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate une date pour le nom de fichier
|
||||
*/
|
||||
private static formatDateForFilename(date: Date): string {
|
||||
return new Date(date).toISOString().split('T')[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate le pourcentage de tendance
|
||||
*/
|
||||
private static formatTrend(trend: number): string {
|
||||
const sign = trend > 0 ? '+' : '';
|
||||
return `${sign}${trend.toFixed(1)}%`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,438 +0,0 @@
|
||||
import { prisma } from './database';
|
||||
import { Task, TaskStatus, TaskPriority, TaskSource } from '@/lib/types';
|
||||
import { TaskCategorizationService } from './task-categorization';
|
||||
|
||||
export interface DailyItem {
|
||||
id: string;
|
||||
text: string;
|
||||
isChecked: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
date: Date;
|
||||
}
|
||||
|
||||
export interface WeeklyStats {
|
||||
totalCheckboxes: number;
|
||||
completedCheckboxes: number;
|
||||
totalTasks: number;
|
||||
completedTasks: number;
|
||||
checkboxCompletionRate: number;
|
||||
taskCompletionRate: number;
|
||||
mostProductiveDay: string;
|
||||
dailyBreakdown: Array<{
|
||||
date: string;
|
||||
dayName: string;
|
||||
checkboxes: number;
|
||||
completedCheckboxes: number;
|
||||
tasks: number;
|
||||
completedTasks: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface WeeklyActivity {
|
||||
id: string;
|
||||
type: 'checkbox' | 'task';
|
||||
title: string;
|
||||
completed: boolean;
|
||||
completedAt?: Date;
|
||||
createdAt: Date;
|
||||
date: string;
|
||||
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(periodDays: number = 7): Promise<WeeklySummary> {
|
||||
const now = new Date();
|
||||
const startOfPeriod = new Date(now);
|
||||
startOfPeriod.setDate(now.getDate() - periodDays);
|
||||
startOfPeriod.setHours(0, 0, 0, 0);
|
||||
|
||||
const endOfPeriod = new Date(now);
|
||||
endOfPeriod.setHours(23, 59, 59, 999);
|
||||
|
||||
console.log(`📊 Génération du résumé (${periodDays} jours) du ${startOfPeriod.toLocaleDateString()} au ${endOfPeriod.toLocaleDateString()}`);
|
||||
|
||||
const [checkboxes, tasks, velocity] = await Promise.all([
|
||||
this.getWeeklyCheckboxes(startOfPeriod, endOfPeriod),
|
||||
this.getWeeklyTasks(startOfPeriod, endOfPeriod),
|
||||
this.calculateVelocityMetrics(endOfPeriod)
|
||||
]);
|
||||
|
||||
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: startOfPeriod,
|
||||
end: endOfPeriod
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les checkboxes des 7 derniers jours
|
||||
*/
|
||||
private static async getWeeklyCheckboxes(startDate: Date, endDate: Date): Promise<DailyItem[]> {
|
||||
const items = await prisma.dailyCheckbox.findMany({
|
||||
where: {
|
||||
date: {
|
||||
gte: startDate,
|
||||
lte: endDate
|
||||
}
|
||||
},
|
||||
orderBy: [
|
||||
{ date: 'desc' },
|
||||
{ createdAt: 'desc' }
|
||||
]
|
||||
});
|
||||
|
||||
return items.map(item => ({
|
||||
id: item.id,
|
||||
text: item.text,
|
||||
isChecked: item.isChecked,
|
||||
createdAt: item.createdAt,
|
||||
updatedAt: item.updatedAt,
|
||||
date: item.date
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les tâches des 7 derniers jours (créées ou modifiées)
|
||||
*/
|
||||
private static async getWeeklyTasks(startDate: Date, endDate: Date): Promise<Task[]> {
|
||||
const tasks = await prisma.task.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
createdAt: {
|
||||
gte: startDate,
|
||||
lte: endDate
|
||||
}
|
||||
},
|
||||
{
|
||||
updatedAt: {
|
||||
gte: startDate,
|
||||
lte: endDate
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: 'desc'
|
||||
}
|
||||
});
|
||||
|
||||
return tasks.map(task => ({
|
||||
id: task.id,
|
||||
title: task.title,
|
||||
description: task.description || '',
|
||||
status: task.status as TaskStatus,
|
||||
priority: task.priority as TaskPriority,
|
||||
source: task.source as TaskSource,
|
||||
sourceId: task.sourceId || undefined,
|
||||
createdAt: task.createdAt,
|
||||
updatedAt: task.updatedAt,
|
||||
dueDate: task.dueDate || undefined,
|
||||
completedAt: task.completedAt || undefined,
|
||||
jiraProject: task.jiraProject || undefined,
|
||||
jiraKey: task.jiraKey || undefined,
|
||||
jiraType: task.jiraType || undefined,
|
||||
assignee: task.assignee || undefined,
|
||||
tags: [] // Les tags sont dans une relation séparée, on les laisse vides pour l'instant
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcule les statistiques de la semaine
|
||||
*/
|
||||
private static calculateStats(
|
||||
checkboxes: DailyItem[],
|
||||
tasks: Task[],
|
||||
startDate: Date,
|
||||
endDate: Date
|
||||
): WeeklyStats {
|
||||
const completedCheckboxes = checkboxes.filter(c => c.isChecked);
|
||||
const completedTasks = tasks.filter(t => t.status === 'done');
|
||||
|
||||
// Créer un breakdown par jour
|
||||
const dailyBreakdown = [];
|
||||
const current = new Date(startDate);
|
||||
|
||||
while (current <= endDate) {
|
||||
const dayCheckboxes = checkboxes.filter(c =>
|
||||
c.date.toISOString().split('T')[0] === current.toISOString().split('T')[0]
|
||||
);
|
||||
const dayCompletedCheckboxes = dayCheckboxes.filter(c => c.isChecked);
|
||||
|
||||
// Pour les tâches, on compte celles modifiées ce jour-là
|
||||
const dayTasks = tasks.filter(t =>
|
||||
t.updatedAt.toISOString().split('T')[0] === current.toISOString().split('T')[0] ||
|
||||
t.createdAt.toISOString().split('T')[0] === current.toISOString().split('T')[0]
|
||||
);
|
||||
const dayCompletedTasks = dayTasks.filter(t => t.status === 'done');
|
||||
|
||||
dailyBreakdown.push({
|
||||
date: current.toISOString().split('T')[0],
|
||||
dayName: current.toLocaleDateString('fr-FR', { weekday: 'long' }),
|
||||
checkboxes: dayCheckboxes.length,
|
||||
completedCheckboxes: dayCompletedCheckboxes.length,
|
||||
tasks: dayTasks.length,
|
||||
completedTasks: dayCompletedTasks.length
|
||||
});
|
||||
|
||||
current.setDate(current.getDate() + 1);
|
||||
}
|
||||
|
||||
// Trouver le jour le plus productif
|
||||
const mostProductiveDay = dailyBreakdown.reduce((max, day) => {
|
||||
const dayScore = day.completedCheckboxes + day.completedTasks;
|
||||
const maxScore = max.completedCheckboxes + max.completedTasks;
|
||||
return dayScore > maxScore ? day : max;
|
||||
}, dailyBreakdown[0]);
|
||||
|
||||
return {
|
||||
totalCheckboxes: checkboxes.length,
|
||||
completedCheckboxes: completedCheckboxes.length,
|
||||
totalTasks: tasks.length,
|
||||
completedTasks: completedTasks.length,
|
||||
checkboxCompletionRate: checkboxes.length > 0 ? (completedCheckboxes.length / checkboxes.length) * 100 : 0,
|
||||
taskCompletionRate: tasks.length > 0 ? (completedTasks.length / tasks.length) * 100 : 0,
|
||||
mostProductiveDay: mostProductiveDay.dayName,
|
||||
dailyBreakdown
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private static mergeActivities(checkboxes: DailyItem[], tasks: Task[]): WeeklyActivity[] {
|
||||
const activities: WeeklyActivity[] = [];
|
||||
|
||||
// Ajouter les checkboxes
|
||||
checkboxes.forEach(checkbox => {
|
||||
activities.push({
|
||||
id: `checkbox-${checkbox.id}`,
|
||||
type: 'checkbox',
|
||||
title: checkbox.text,
|
||||
completed: checkbox.isChecked,
|
||||
completedAt: checkbox.isChecked ? checkbox.updatedAt : undefined,
|
||||
createdAt: checkbox.createdAt,
|
||||
date: checkbox.date.toISOString().split('T')[0],
|
||||
dayName: checkbox.date.toLocaleDateString('fr-FR', { weekday: 'long' })
|
||||
});
|
||||
});
|
||||
|
||||
// Ajouter les tâches
|
||||
tasks.forEach(task => {
|
||||
const date = task.updatedAt.toISOString().split('T')[0];
|
||||
const dateObj = new Date(date + 'T00:00:00');
|
||||
activities.push({
|
||||
id: `task-${task.id}`,
|
||||
type: 'task',
|
||||
title: task.title,
|
||||
completed: task.status === 'done',
|
||||
completedAt: task.status === 'done' ? task.updatedAt : undefined,
|
||||
createdAt: task.createdAt,
|
||||
date: date,
|
||||
dayName: dateObj.toLocaleDateString('fr-FR', { weekday: 'long' })
|
||||
});
|
||||
});
|
||||
|
||||
// Trier par date (plus récent en premier)
|
||||
return activities.sort((a, b) => {
|
||||
const dateA = a.completedAt || a.createdAt;
|
||||
const dateB = b.completedAt || b.createdAt;
|
||||
return dateB.getTime() - dateA.getTime();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user