'use client'; import { DailyMetrics } from '@/services/metrics'; interface ProductivityInsightsProps { data: DailyMetrics[]; className?: string; } export function ProductivityInsights({ data, className }: ProductivityInsightsProps) { // Calculer les insights const totalCompleted = data.reduce((sum, day) => sum + day.completed, 0); const totalCreated = data.reduce((sum, day) => sum + day.newTasks, 0); // const averageCompletion = data.reduce((sum, day) => sum + day.completionRate, 0) / data.length; // Trouver le jour le plus productif const mostProductiveDay = data.reduce((best, day) => day.completed > best.completed ? day : best ); // Trouver le jour avec le plus de nouvelles tâches const mostCreativeDay = data.reduce((best, day) => day.newTasks > best.newTasks ? day : best ); // Analyser la tendance const firstHalf = data.slice(0, Math.ceil(data.length / 2)); const secondHalf = data.slice(Math.ceil(data.length / 2)); const firstHalfAvg = firstHalf.reduce((sum, day) => sum + day.completed, 0) / firstHalf.length; const secondHalfAvg = secondHalf.reduce((sum, day) => sum + day.completed, 0) / secondHalf.length; const trend = secondHalfAvg > firstHalfAvg ? 'up' : secondHalfAvg < firstHalfAvg ? 'down' : 'stable'; // Calculer la consistance (écart-type faible = plus consistant) const avgCompleted = totalCompleted / data.length; const variance = data.reduce((sum, day) => { const diff = day.completed - avgCompleted; return sum + diff * diff; }, 0) / data.length; const standardDeviation = Math.sqrt(variance); const consistencyScore = Math.max(0, 100 - (standardDeviation * 10)); // Score sur 100 // Ratio création/completion const creationRatio = totalCreated > 0 ? (totalCompleted / totalCreated) * 100 : 0; const getTrendIcon = () => { switch (trend) { case 'up': return { icon: '📈', color: 'text-green-600', label: 'En amélioration' }; case 'down': return { icon: '📉', color: 'text-red-600', label: 'En baisse' }; default: return { icon: '➡️', color: 'text-blue-600', label: 'Stable' }; } }; const getConsistencyLevel = () => { if (consistencyScore >= 80) return { label: 'Très régulier', color: 'text-green-600', icon: '🎯' }; if (consistencyScore >= 60) return { label: 'Assez régulier', color: 'text-blue-600', icon: '📊' }; if (consistencyScore >= 40) return { label: 'Variable', color: 'text-yellow-600', icon: '📊' }; return { label: 'Très variable', color: 'text-red-600', icon: '📊' }; }; const getRatioStatus = () => { if (creationRatio >= 100) return { label: 'Équilibré+', color: 'text-green-600', icon: '⚖️' }; if (creationRatio >= 80) return { label: 'Bien équilibré', color: 'text-blue-600', icon: '⚖️' }; if (creationRatio >= 60) return { label: 'Légèrement en retard', color: 'text-yellow-600', icon: '⚖️' }; return { label: 'Accumulation', color: 'text-red-600', icon: '⚖️' }; }; const trendInfo = getTrendIcon(); const consistencyInfo = getConsistencyLevel(); const ratioInfo = getRatioStatus(); return (
{mostProductiveDay.dayName} - {mostProductiveDay.completed} tâches terminées
Taux: {mostProductiveDay.completionRate.toFixed(1)}%
{mostCreativeDay.dayName} - {mostCreativeDay.newTasks} nouvelles tâches
{mostCreativeDay.dayName === mostProductiveDay.dayName ? 'Également jour le plus productif!' : 'Journée de planification'}
{trendInfo.label}
{secondHalfAvg > firstHalfAvg ? `+${(((secondHalfAvg - firstHalfAvg) / firstHalfAvg) * 100).toFixed(1)}%` : `${(((secondHalfAvg - firstHalfAvg) / firstHalfAvg) * 100).toFixed(1)}%`}
{consistencyInfo.label}
Score: {consistencyScore.toFixed(0)}/100
{ratioInfo.label}
{creationRatio.toFixed(0)}% de completion
• Essayez de retrouver votre rythme du début de semaine
)} {consistencyScore < 60 && (• Essayez de maintenir un rythme plus régulier
)} {creationRatio < 80 && (• Concentrez-vous plus sur terminer les tâches existantes
)} {creationRatio > 120 && (• Excellent rythme! Peut-être ralentir la création de nouvelles tâches
)} {mostProductiveDay.dayName === mostCreativeDay.dayName && (• Excellente synergie création/exécution le {mostProductiveDay.dayName}
)}