MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / calculateProjectStats

Method calculateProjectStats

src/views/StatsView.ts:732–819  ·  view source on GitHub ↗
(tasks: TaskInfo[])

Source from the content-addressed store, hash-verified

730 }
731
732 private calculateProjectStats(tasks: TaskInfo[]): ProjectStats[] {
733 const projectMap = new Map<
734 string,
735 {
736 tasks: TaskInfo[];
737 totalTime: number;
738 totalTimeEstimate: number; // Add this
739 completedCount: number;
740 lastActivity: string | undefined;
741 }
742 >();
743
744 // Group tasks by project - follow FilterService pattern exactly
745 for (const task of tasks) {
746 const timeSpent = calculateTotalTimeSpent(task.timeEntries || []);
747 const timeEstimate = task.timeEstimate || 0;
748 const isCompleted = this.plugin.statusManager.isCompletedStatus(task.status);
749
750 // Get last activity date
751 let lastActivity: string | undefined;
752 if (task.timeEntries && task.timeEntries.length > 0) {
753 const sortedEntries = [...task.timeEntries].sort(
754 (a, b) => new Date(b.startTime).getTime() - new Date(a.startTime).getTime()
755 );
756 lastActivity = sortedEntries[0].startTime;
757 } else if (task.completedDate) {
758 lastActivity = task.completedDate;
759 } else if (task.dateModified) {
760 lastActivity = task.dateModified;
761 }
762
763 // Handle projects
764 const taskProjects = this.getTaskProjects(task);
765
766 for (const consolidatedProject of taskProjects) {
767 if (!projectMap.has(consolidatedProject)) {
768 projectMap.set(consolidatedProject, {
769 tasks: [],
770 totalTime: 0,
771 totalTimeEstimate: 0, // Add this
772 completedCount: 0,
773 lastActivity: undefined,
774 });
775 }
776
777 const projectData = projectMap.get(consolidatedProject);
778 if (!projectData) continue;
779
780 projectData.tasks.push(task);
781 projectData.totalTime += timeSpent;
782 projectData.totalTimeEstimate += timeEstimate; // Add this
783 if (isCompleted) projectData.completedCount++;
784
785 // Update last activity if this is more recent
786 if (
787 lastActivity &&
788 (!projectData.lastActivity ||
789 new Date(lastActivity) > new Date(projectData.lastActivity))

Callers 2

updateProjectStatsMethod · 0.95

Calls 7

getTaskProjectsMethod · 0.95
calculateTotalTimeSpentFunction · 0.90
hasMethod · 0.80
isCompletedStatusMethod · 0.65
setMethod · 0.65
getMethod · 0.65
translateMethod · 0.65

Tested by

no test coverage detected