-
📊 Répartition par jour
+
+ 📊 Répartition par jour
+ {activeTab !== 'all' && - {activeTab}}
+
- {summary.stats.dailyBreakdown.map((day) => (
-
- ))}
+ {summary.stats.dailyBreakdown.map((day) => {
+ // Pour chaque jour, calculer les activités de la catégorie sélectionnée
+ const dayActivitiesAll = summary.activities.filter(a => a.dayName === day.dayName);
+ const dayActivitiesFiltered = activeTab === 'all'
+ ? dayActivitiesAll
+ : dayActivitiesAll.filter(activity => getActivityCategory(activity) === activeTab);
+
+ const completedCount = dayActivitiesFiltered.filter(a => a.completed).length;
+ const totalCount = dayActivitiesFiltered.length;
+
+ return (
+
+ );
+ })}
{selectedDay && (
📍 Filtré sur:
{selectedDay}
+ {activeTab !== 'all' &&
• Catégorie: {activeTab}}
);
}
diff --git a/components/ui/Header.tsx b/components/ui/Header.tsx
index e9e87f1..a348a01 100644
--- a/components/ui/Header.tsx
+++ b/components/ui/Header.tsx
@@ -53,7 +53,7 @@ export function Header({ title = "TowerControl", subtitle = "Task Management", s
{ href: '/', label: 'Dashboard' },
{ href: '/kanban', label: 'Kanban' },
{ href: '/daily', label: 'Daily' },
- { href: '/weekly-summary', label: 'Résumé' },
+ { href: '/weekly-summary', label: 'Hebdo' },
{ href: '/tags', label: 'Tags' },
...(isJiraConfigured ? [{ href: '/jira-dashboard', label: `Jira${jiraConfig?.projectKey ? ` (${jiraConfig.projectKey})` : ''}` }] : []),
{ href: '/settings', label: 'Settings' }
diff --git a/package-lock.json b/package-lock.json
index 19835e2..4c0f8ce 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -12,8 +12,10 @@
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@prisma/client": "^6.16.1",
+ "@types/jspdf": "^1.3.3",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
+ "jspdf": "^3.0.3",
"next": "15.5.3",
"prisma": "^6.16.1",
"react": "19.1.0",
@@ -51,6 +53,15 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/@babel/runtime": {
+ "version": "7.28.4",
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.4.tgz",
+ "integrity": "sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=6.9.0"
+ }
+ },
"node_modules/@dnd-kit/accessibility": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@dnd-kit/accessibility/-/accessibility-3.1.1.tgz",
@@ -2035,6 +2046,12 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/jspdf": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/@types/jspdf/-/jspdf-1.3.3.tgz",
+ "integrity": "sha512-DqwyAKpVuv+7DniCp2Deq1xGvfdnKSNgl9Agun2w6dFvR5UKamiv4VfYUgcypd8S9ojUyARFIlZqBrYrBMQlew==",
+ "license": "MIT"
+ },
"node_modules/@types/node": {
"version": "20.19.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.14.tgz",
@@ -2045,6 +2062,19 @@
"undici-types": "~6.21.0"
}
},
+ "node_modules/@types/pako": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/@types/pako/-/pako-2.0.4.tgz",
+ "integrity": "sha512-VWDCbrLeVXJM9fihYodcLiIv0ku+AlOa/TQ1SvYOaBuyrSKgEcro95LJyIsJ4vSo6BXIxOKxiJAat04CmST9Fw==",
+ "license": "MIT"
+ },
+ "node_modules/@types/raf": {
+ "version": "3.4.3",
+ "resolved": "https://registry.npmjs.org/@types/raf/-/raf-3.4.3.tgz",
+ "integrity": "sha512-c4YAvMedbPZ5tEyxzQdMoOhhJ4RD3rngZIdwC2/qDN3d7JpEhB6fiBRKVY1lg5B7Wk+uPBjn5f39j1/2MY1oOw==",
+ "license": "MIT",
+ "optional": true
+ },
"node_modules/@types/react": {
"version": "19.1.13",
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.13.tgz",
@@ -2065,6 +2095,13 @@
"@types/react": "^19.0.0"
}
},
+ "node_modules/@types/trusted-types": {
+ "version": "2.0.7",
+ "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz",
+ "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==",
+ "license": "MIT",
+ "optional": true
+ },
"node_modules/@types/use-sync-external-store": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
@@ -3000,6 +3037,16 @@
"devOptional": true,
"license": "MIT"
},
+ "node_modules/base64-arraybuffer": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
+ "integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==",
+ "license": "MIT",
+ "optional": true,
+ "engines": {
+ "node": ">= 0.6.0"
+ }
+ },
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
@@ -3254,6 +3301,26 @@
],
"license": "CC-BY-4.0"
},
+ "node_modules/canvg": {
+ "version": "3.0.11",
+ "resolved": "https://registry.npmjs.org/canvg/-/canvg-3.0.11.tgz",
+ "integrity": "sha512-5ON+q7jCTgMp9cjpu4Jo6XbvfYwSB2Ow3kzHKfIyJfaCAOHLbdKPQqGKgfED/R5B+3TFFfe8pegYA+b423SRyA==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "@babel/runtime": "^7.12.5",
+ "@types/raf": "^3.4.0",
+ "core-js": "^3.8.3",
+ "raf": "^3.4.1",
+ "regenerator-runtime": "^0.13.7",
+ "rgbcolor": "^1.0.1",
+ "stackblur-canvas": "^2.0.0",
+ "svg-pathdata": "^6.0.3"
+ },
+ "engines": {
+ "node": ">=10.0.0"
+ }
+ },
"node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
@@ -3413,6 +3480,18 @@
"license": "ISC",
"optional": true
},
+ "node_modules/core-js": {
+ "version": "3.45.1",
+ "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.45.1.tgz",
+ "integrity": "sha512-L4NPsJlCfZsPeXukyzHFlg/i7IIVwHSItR0wg0FLNqYClJ4MQYTYLbC7EkjKYRLZF2iof2MUgN0EGy7MdQFChg==",
+ "hasInstallScript": true,
+ "license": "MIT",
+ "optional": true,
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/core-js"
+ }
+ },
"node_modules/cross-spawn": {
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
@@ -3428,6 +3507,16 @@
"node": ">= 8"
}
},
+ "node_modules/css-line-break": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
+ "integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "utrie": "^1.0.2"
+ }
+ },
"node_modules/csstype": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
@@ -3768,6 +3857,16 @@
"node": ">=0.10.0"
}
},
+ "node_modules/dompurify": {
+ "version": "3.2.7",
+ "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.2.7.tgz",
+ "integrity": "sha512-WhL/YuveyGXJaerVlMYGWhvQswa7myDG17P7Vu65EWC05o8vfeNbvNf4d/BOvH99+ZW+LlQsc1GDKMa1vNK6dw==",
+ "license": "(MPL-2.0 OR Apache-2.0)",
+ "optional": true,
+ "optionalDependencies": {
+ "@types/trusted-types": "^2.0.7"
+ }
+ },
"node_modules/dotenv": {
"version": "16.6.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz",
@@ -4687,6 +4786,17 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/fast-png": {
+ "version": "6.4.0",
+ "resolved": "https://registry.npmjs.org/fast-png/-/fast-png-6.4.0.tgz",
+ "integrity": "sha512-kAqZq1TlgBjZcLr5mcN6NP5Rv4V2f22z00c3g8vRrwkcqjerx7BEhPbOnWCPqaHUl2XWQBJQvOT/FQhdMT7X/Q==",
+ "license": "MIT",
+ "dependencies": {
+ "@types/pako": "^2.0.3",
+ "iobuffer": "^5.3.2",
+ "pako": "^2.1.0"
+ }
+ },
"node_modules/fastq": {
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.19.1.tgz",
@@ -4697,6 +4807,12 @@
"reusify": "^1.0.4"
}
},
+ "node_modules/fflate": {
+ "version": "0.8.2",
+ "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
+ "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==",
+ "license": "MIT"
+ },
"node_modules/file-entry-cache": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz",
@@ -5171,6 +5287,20 @@
"node": ">= 0.4"
}
},
+ "node_modules/html2canvas": {
+ "version": "1.4.1",
+ "resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
+ "integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "css-line-break": "^2.1.0",
+ "text-segmentation": "^1.0.3"
+ },
+ "engines": {
+ "node": ">=8.0.0"
+ }
+ },
"node_modules/http-cache-semantics": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.2.0.tgz",
@@ -5362,6 +5492,12 @@
"node": ">=12"
}
},
+ "node_modules/iobuffer": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/iobuffer/-/iobuffer-5.4.0.tgz",
+ "integrity": "sha512-DRebOWuqDvxunfkNJAlc3IzWIPD5xVxwUNbHr7xKB8E6aLJxIPfNX3CoMJghcFjpv6RWQsrcJbghtEwSPoJqMA==",
+ "license": "MIT"
+ },
"node_modules/ip-address": {
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.0.1.tgz",
@@ -5892,6 +6028,23 @@
"json5": "lib/cli.js"
}
},
+ "node_modules/jspdf": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/jspdf/-/jspdf-3.0.3.tgz",
+ "integrity": "sha512-eURjAyz5iX1H8BOYAfzvdPfIKK53V7mCpBTe7Kb16PaM8JSXEcUQNBQaiWMI8wY5RvNOPj4GccMjTlfwRBd+oQ==",
+ "license": "MIT",
+ "dependencies": {
+ "@babel/runtime": "^7.26.9",
+ "fast-png": "^6.2.0",
+ "fflate": "^0.8.1"
+ },
+ "optionalDependencies": {
+ "canvg": "^3.0.11",
+ "core-js": "^3.6.0",
+ "dompurify": "^3.2.4",
+ "html2canvas": "^1.0.0-rc.5"
+ }
+ },
"node_modules/jsx-ast-utils": {
"version": "3.3.5",
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz",
@@ -6954,6 +7107,12 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/pako": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz",
+ "integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==",
+ "license": "(MIT AND Zlib)"
+ },
"node_modules/parent-module": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
@@ -7016,6 +7175,13 @@
"integrity": "sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==",
"license": "MIT"
},
+ "node_modules/performance-now": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
+ "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==",
+ "license": "MIT",
+ "optional": true
+ },
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
@@ -7265,6 +7431,16 @@
],
"license": "MIT"
},
+ "node_modules/raf": {
+ "version": "3.4.1",
+ "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz",
+ "integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "performance-now": "^2.1.0"
+ }
+ },
"node_modules/rc": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",
@@ -7441,6 +7617,13 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/regenerator-runtime": {
+ "version": "0.13.11",
+ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
+ "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==",
+ "license": "MIT",
+ "optional": true
+ },
"node_modules/regexp.prototype.flags": {
"version": "1.5.4",
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz",
@@ -7530,6 +7713,16 @@
"node": ">=0.10.0"
}
},
+ "node_modules/rgbcolor": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/rgbcolor/-/rgbcolor-1.0.1.tgz",
+ "integrity": "sha512-9aZLIrhRaD97sgVhtJOW6ckOEh6/GnvQtdVNfdZ6s67+3/XwLS9lBcQYzEEhYVeUowN7pRzMLsyGhK2i/xvWbw==",
+ "license": "MIT OR SEE LICENSE IN FEEL-FREE.md",
+ "optional": true,
+ "engines": {
+ "node": ">= 0.8.15"
+ }
+ },
"node_modules/rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
@@ -8051,6 +8244,16 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/stackblur-canvas": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/stackblur-canvas/-/stackblur-canvas-2.7.0.tgz",
+ "integrity": "sha512-yf7OENo23AGJhBriGx0QivY5JP6Y1HbrrDI6WLt6C5auYZXlQrheoY8hD4ibekFKz1HOfE48Ww8kMWMnJD/zcQ==",
+ "license": "MIT",
+ "optional": true,
+ "engines": {
+ "node": ">=0.1.14"
+ }
+ },
"node_modules/stop-iteration-iterator": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.1.0.tgz",
@@ -8294,6 +8497,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/svg-pathdata": {
+ "version": "6.0.3",
+ "resolved": "https://registry.npmjs.org/svg-pathdata/-/svg-pathdata-6.0.3.tgz",
+ "integrity": "sha512-qsjeeq5YjBZ5eMdFuUa4ZosMLxgr5RZ+F+Y1OrDhuOCEInRMA3x74XdBtggJcj9kOeInz0WE+LgCPDkZFlBYJw==",
+ "license": "MIT",
+ "optional": true,
+ "engines": {
+ "node": ">=12.0.0"
+ }
+ },
"node_modules/synckit": {
"version": "0.11.11",
"resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.11.tgz",
@@ -8452,6 +8665,16 @@
"node": ">=18"
}
},
+ "node_modules/text-segmentation": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
+ "integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "utrie": "^1.0.2"
+ }
+ },
"node_modules/tiny-invariant": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.3.tgz",
@@ -8800,6 +9023,16 @@
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
"license": "MIT"
},
+ "node_modules/utrie": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
+ "integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
+ "license": "MIT",
+ "optional": true,
+ "dependencies": {
+ "base64-arraybuffer": "^1.0.2"
+ }
+ },
"node_modules/victory-vendor": {
"version": "37.3.6",
"resolved": "https://registry.npmjs.org/victory-vendor/-/victory-vendor-37.3.6.tgz",
diff --git a/package.json b/package.json
index 56587e3..1299627 100644
--- a/package.json
+++ b/package.json
@@ -20,8 +20,10 @@
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@prisma/client": "^6.16.1",
+ "@types/jspdf": "^1.3.3",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
+ "jspdf": "^3.0.3",
"next": "15.5.3",
"prisma": "^6.16.1",
"react": "19.1.0",
diff --git a/services/jira-summary.ts b/services/jira-summary.ts
new file mode 100644
index 0000000..5f6a052
--- /dev/null
+++ b/services/jira-summary.ts
@@ -0,0 +1,180 @@
+import type { JiraConfig } from './jira';
+import { Task } from '@/lib/types';
+
+export interface JiraWeeklyMetrics {
+ totalJiraTasks: number;
+ completedJiraTasks: number;
+ totalStoryPoints: number; // Estimation basée sur le type de ticket
+ projectsContributed: string[];
+ ticketTypes: { [type: string]: number };
+ jiraLinks: Array<{
+ key: string;
+ title: string;
+ status: string;
+ type: string;
+ url: string;
+ estimatedPoints: number;
+ }>;
+}
+
+export class JiraSummaryService {
+ /**
+ * Enrichit les tâches hebdomadaires avec des métriques Jira
+ */
+ static async getJiraWeeklyMetrics(
+ weeklyTasks: Task[],
+ jiraConfig?: JiraConfig
+ ): Promise
{
+
+ if (!jiraConfig?.baseUrl || !jiraConfig?.email || !jiraConfig?.apiToken) {
+ return null;
+ }
+
+ const jiraTasks = weeklyTasks.filter(task =>
+ task.source === 'jira' && task.jiraKey && task.jiraProject
+ );
+
+ if (jiraTasks.length === 0) {
+ return {
+ totalJiraTasks: 0,
+ completedJiraTasks: 0,
+ totalStoryPoints: 0,
+ projectsContributed: [],
+ ticketTypes: {},
+ jiraLinks: []
+ };
+ }
+
+ // Calculer les métriques basiques
+ const completedJiraTasks = jiraTasks.filter(task => task.status === 'done');
+ const projectsContributed = [...new Set(jiraTasks.map(task => task.jiraProject).filter((project): project is string => Boolean(project)))];
+
+ // Analyser les types de tickets
+ const ticketTypes: { [type: string]: number } = {};
+ jiraTasks.forEach(task => {
+ const type = task.jiraType || 'Unknown';
+ ticketTypes[type] = (ticketTypes[type] || 0) + 1;
+ });
+
+ // Estimer les story points basés sur le type de ticket
+ const estimateStoryPoints = (type: string): number => {
+ const typeMapping: { [key: string]: number } = {
+ 'Story': 3,
+ 'Task': 2,
+ 'Bug': 1,
+ 'Epic': 8,
+ 'Sub-task': 1,
+ 'Improvement': 2,
+ 'New Feature': 5,
+ 'défaut': 1, // French
+ 'amélioration': 2, // French
+ 'nouvelle fonctionnalité': 5, // French
+ };
+
+ return typeMapping[type] || typeMapping[type?.toLowerCase()] || 2; // Défaut: 2 points
+ };
+
+ const totalStoryPoints = jiraTasks.reduce((sum, task) => {
+ return sum + estimateStoryPoints(task.jiraType || '');
+ }, 0);
+
+ // Créer les liens Jira
+ const jiraLinks = jiraTasks.map(task => ({
+ key: task.jiraKey || '',
+ title: task.title,
+ status: task.status,
+ type: task.jiraType || 'Unknown',
+ url: `${jiraConfig.baseUrl.replace('/rest/api/3', '')}/browse/${task.jiraKey}`,
+ estimatedPoints: estimateStoryPoints(task.jiraType || '')
+ }));
+
+ return {
+ totalJiraTasks: jiraTasks.length,
+ completedJiraTasks: completedJiraTasks.length,
+ totalStoryPoints,
+ projectsContributed,
+ ticketTypes,
+ jiraLinks
+ };
+ }
+
+ /**
+ * Récupère la configuration Jira depuis les préférences utilisateur
+ */
+ static async getJiraConfig(): Promise {
+ try {
+ // Import dynamique pour éviter les cycles de dépendance
+ const { userPreferencesService } = await import('./user-preferences');
+ const preferences = await userPreferencesService.getAllPreferences();
+
+ if (!preferences.jiraConfig?.baseUrl ||
+ !preferences.jiraConfig?.email ||
+ !preferences.jiraConfig?.apiToken) {
+ return null;
+ }
+
+ return {
+ baseUrl: preferences.jiraConfig.baseUrl,
+ email: preferences.jiraConfig.email,
+ apiToken: preferences.jiraConfig.apiToken,
+ projectKey: preferences.jiraConfig.projectKey,
+ ignoredProjects: preferences.jiraConfig.ignoredProjects
+ };
+ } catch (error) {
+ console.error('Erreur lors de la récupération de la config Jira:', error);
+ return null;
+ }
+ }
+
+ /**
+ * Génère des insights business basés sur les métriques Jira
+ */
+ static generateBusinessInsights(jiraMetrics: JiraWeeklyMetrics): string[] {
+ const insights: string[] = [];
+
+ if (jiraMetrics.totalJiraTasks === 0) {
+ insights.push("Aucune tâche Jira cette semaine. Concentré sur des tâches internes ?");
+ return insights;
+ }
+
+ // Insights sur la completion
+ const completionRate = (jiraMetrics.completedJiraTasks / jiraMetrics.totalJiraTasks) * 100;
+ if (completionRate >= 80) {
+ insights.push(`🎯 Excellent taux de completion Jira: ${completionRate.toFixed(0)}%`);
+ } else if (completionRate < 50) {
+ insights.push(`⚠️ Taux de completion Jira faible: ${completionRate.toFixed(0)}%. Revoir les estimations ?`);
+ }
+
+ // Insights sur les story points
+ if (jiraMetrics.totalStoryPoints > 0) {
+ insights.push(`📊 Estimation: ${jiraMetrics.totalStoryPoints} story points traités cette semaine`);
+
+ const avgPointsPerTask = jiraMetrics.totalStoryPoints / jiraMetrics.totalJiraTasks;
+ if (avgPointsPerTask > 4) {
+ insights.push(`🏋️ Travail sur des tâches complexes (${avgPointsPerTask.toFixed(1)} pts/tâche en moyenne)`);
+ }
+ }
+
+ // Insights sur les projets
+ if (jiraMetrics.projectsContributed.length > 1) {
+ insights.push(`🤝 Contribution multi-projets: ${jiraMetrics.projectsContributed.join(', ')}`);
+ } else if (jiraMetrics.projectsContributed.length === 1) {
+ insights.push(`🎯 Focus sur le projet ${jiraMetrics.projectsContributed[0]}`);
+ }
+
+ // Insights sur les types de tickets
+ const bugCount = jiraMetrics.ticketTypes['Bug'] || jiraMetrics.ticketTypes['défaut'] || 0;
+ const totalTickets = Object.values(jiraMetrics.ticketTypes).reduce((sum, count) => sum + count, 0);
+
+ if (bugCount > 0) {
+ const bugRatio = (bugCount / totalTickets) * 100;
+ if (bugRatio > 50) {
+ insights.push(`🐛 Semaine focalisée sur la correction de bugs (${bugRatio.toFixed(0)}%)`);
+ } else if (bugRatio < 20) {
+ insights.push(`✨ Semaine productive avec peu de bugs (${bugRatio.toFixed(0)}%)`);
+ }
+ }
+
+ return insights;
+ }
+}
diff --git a/services/pdf-export.ts b/services/pdf-export.ts
new file mode 100644
index 0000000..955c42f
--- /dev/null
+++ b/services/pdf-export.ts
@@ -0,0 +1,193 @@
+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 {
+ 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)}%`;
+ }
+}
+
diff --git a/services/task-categorization.ts b/services/task-categorization.ts
new file mode 100644
index 0000000..b926740
--- /dev/null
+++ b/services/task-categorization.ts
@@ -0,0 +1,185 @@
+export interface PredefinedCategory {
+ name: string;
+ color: string;
+ keywords: string[];
+ icon: string;
+}
+
+export const PREDEFINED_CATEGORIES: PredefinedCategory[] = [
+ {
+ name: 'Dev',
+ color: '#3b82f6', // Blue
+ icon: '💻',
+ keywords: [
+ 'code', 'coding', 'development', 'develop', 'dev', 'programming', 'program',
+ 'bug', 'fix', 'debug', 'feature', 'implement', 'refactor', 'review',
+ 'api', 'database', 'db', 'frontend', 'backend', 'ui', 'ux',
+ 'component', 'service', 'function', 'method', 'class',
+ 'git', 'commit', 'merge', 'pull request', 'pr', 'deploy', 'deployment',
+ 'test', 'testing', 'unit test', 'integration'
+ ]
+ },
+ {
+ name: 'Meeting',
+ color: '#8b5cf6', // Purple
+ icon: '🤝',
+ keywords: [
+ 'meeting', 'réunion', 'call', 'standup', 'daily', 'retrospective', 'retro',
+ 'planning', 'demo', 'presentation', 'sync', 'catch up', 'catchup',
+ 'interview', 'discussion', 'brainstorm', 'workshop', 'session',
+ 'one on one', '1on1', 'review meeting', 'sprint planning'
+ ]
+ },
+ {
+ name: 'Admin',
+ color: '#6b7280', // Gray
+ icon: '📋',
+ keywords: [
+ 'admin', 'administration', 'paperwork', 'documentation', 'doc', 'docs',
+ 'report', 'reporting', 'timesheet', 'expense', 'invoice',
+ 'email', 'mail', 'communication', 'update', 'status',
+ 'config', 'configuration', 'setup', 'installation', 'maintenance',
+ 'backup', 'security', 'permission', 'user management'
+ ]
+ },
+ {
+ name: 'Learning',
+ color: '#10b981', // Green
+ icon: '📚',
+ keywords: [
+ 'learning', 'learn', 'study', 'training', 'course', 'tutorial',
+ 'research', 'reading', 'documentation', 'knowledge', 'skill',
+ 'certification', 'workshop', 'seminar', 'conference',
+ 'practice', 'exercise', 'experiment', 'exploration', 'investigate'
+ ]
+ }
+];
+
+export class TaskCategorizationService {
+ /**
+ * Suggère une catégorie basée sur le titre et la description d'une tâche
+ */
+ static suggestCategory(title: string, description?: string): PredefinedCategory | null {
+ const text = `${title} ${description || ''}`.toLowerCase();
+
+ // Compte les matches pour chaque catégorie
+ const categoryScores = PREDEFINED_CATEGORIES.map(category => {
+ const matches = category.keywords.filter(keyword =>
+ text.includes(keyword.toLowerCase())
+ ).length;
+
+ return {
+ category,
+ score: matches
+ };
+ });
+
+ // Trouve la meilleure catégorie
+ const bestMatch = categoryScores.reduce((best, current) =>
+ current.score > best.score ? current : best
+ );
+
+ // Retourne la catégorie seulement s'il y a au moins un match
+ return bestMatch.score > 0 ? bestMatch.category : null;
+ }
+
+ /**
+ * Suggère plusieurs catégories avec leur score de confiance
+ */
+ static suggestCategoriesWithScore(title: string, description?: string): Array<{
+ category: PredefinedCategory;
+ score: number;
+ confidence: number;
+ }> {
+ const text = `${title} ${description || ''}`.toLowerCase();
+
+ const categoryScores = PREDEFINED_CATEGORIES.map(category => {
+ const matches = category.keywords.filter(keyword =>
+ text.includes(keyword.toLowerCase())
+ );
+
+ const score = matches.length;
+ const confidence = Math.min((score / 3) * 100, 100); // Max 100% de confiance avec 3+ mots-clés
+
+ return {
+ category,
+ score,
+ confidence
+ };
+ });
+
+ return categoryScores
+ .filter(item => item.score > 0)
+ .sort((a, b) => b.score - a.score);
+ }
+
+ /**
+ * Analyse les activités et retourne la répartition par catégorie
+ */
+ static analyzeActivitiesByCategory(activities: Array<{ title: string; description?: string }>): {
+ [categoryName: string]: {
+ count: number;
+ percentage: number;
+ color: string;
+ icon: string;
+ }
+ } {
+ const categoryCounts: { [key: string]: number } = {};
+ const uncategorized = { count: 0 };
+
+ // Initialiser les compteurs
+ PREDEFINED_CATEGORIES.forEach(cat => {
+ categoryCounts[cat.name] = 0;
+ });
+
+ // Analyser chaque activité
+ activities.forEach(activity => {
+ const suggestedCategory = this.suggestCategory(activity.title, activity.description);
+
+ if (suggestedCategory) {
+ categoryCounts[suggestedCategory.name]++;
+ } else {
+ uncategorized.count++;
+ }
+ });
+
+ const total = activities.length;
+ const result: { [categoryName: string]: { count: number; percentage: number; color: string; icon: string } } = {};
+
+ // Ajouter les catégories prédéfinies
+ PREDEFINED_CATEGORIES.forEach(category => {
+ const count = categoryCounts[category.name];
+ result[category.name] = {
+ count,
+ percentage: total > 0 ? (count / total) * 100 : 0,
+ color: category.color,
+ icon: category.icon
+ };
+ });
+
+ // Ajouter "Autre" si nécessaire
+ if (uncategorized.count > 0) {
+ result['Autre'] = {
+ count: uncategorized.count,
+ percentage: total > 0 ? (uncategorized.count / total) * 100 : 0,
+ color: '#d1d5db',
+ icon: '❓'
+ };
+ }
+
+ return result;
+ }
+
+ /**
+ * Retourne les tags suggérés pour une tâche
+ */
+ static getSuggestedTags(title: string, description?: string): string[] {
+ const suggestions = this.suggestCategoriesWithScore(title, description);
+
+ return suggestions
+ .filter(s => s.confidence >= 30) // Seulement les suggestions avec 30%+ de confiance
+ .slice(0, 2) // Maximum 2 suggestions
+ .map(s => s.category.name);
+ }
+}
+
diff --git a/services/weekly-summary.ts b/services/weekly-summary.ts
index a3fa4bb..8e7d64d 100644
--- a/services/weekly-summary.ts
+++ b/services/weekly-summary.ts
@@ -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 {
+ static async getWeeklySummary(periodDays: number = 7): Promise {
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 {
+ 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 {
+ // 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
*/
diff --git a/src/app/api/weekly-summary/route.ts b/src/app/api/weekly-summary/route.ts
new file mode 100644
index 0000000..5270e8a
--- /dev/null
+++ b/src/app/api/weekly-summary/route.ts
@@ -0,0 +1,36 @@
+import { NextRequest, NextResponse } from 'next/server';
+import { WeeklySummaryService } from '@/services/weekly-summary';
+
+export async function GET(request: NextRequest) {
+ try {
+ const { searchParams } = new URL(request.url);
+ const periodParam = searchParams.get('period');
+
+ // Valider le paramètre de période
+ let periodDays = 7; // Défaut: 7 jours
+ if (periodParam) {
+ const parsedPeriod = parseInt(periodParam, 10);
+ if (!isNaN(parsedPeriod) && parsedPeriod > 0 && parsedPeriod <= 365) {
+ periodDays = parsedPeriod;
+ }
+ }
+
+ console.log(`📊 API weekly-summary appelée avec période: ${periodDays} jours`);
+
+ const summary = await WeeklySummaryService.getWeeklySummary(periodDays);
+
+ return NextResponse.json(summary, {
+ headers: {
+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
+ 'Pragma': 'no-cache',
+ 'Expires': '0'
+ }
+ });
+ } catch (error) {
+ console.error('Erreur lors de la génération du résumé hebdomadaire:', error);
+ return NextResponse.json(
+ { error: 'Erreur lors de la génération du résumé' },
+ { status: 500 }
+ );
+ }
+}