feat(工时): 增加通用工时汇总引擎

This commit is contained in:
Script Generator
2026-06-25 13:59:09 +08:00
parent 978bc7aff1
commit 168c748835
2 changed files with 73 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
export interface WorkEffortItem {
estimateHours: number;
actualHours: number;
progress: number;
}
export interface WorkEffortSummary {
estimateHours: number;
actualHours: number;
progress: number;
}
export function roundHalfHour(hours: number): number {
if (!Number.isFinite(hours) || hours <= 0) return 0;
return Math.round(hours * 2) / 2;
}
export function aggregateWorkEffort(items: WorkEffortItem[]): WorkEffortSummary {
if (items.length === 0) return { estimateHours: 0, actualHours: 0, progress: 0 };
const estimateHours = roundHalfHour(items.reduce((sum, item) => sum + Math.max(0, item.estimateHours || 0), 0));
const actualHours = roundHalfHour(items.reduce((sum, item) => sum + Math.max(0, item.actualHours || 0), 0));
if (estimateHours <= 0) {
return {
estimateHours,
actualHours,
progress: Math.round(items.reduce((sum, item) => sum + item.progress, 0) / items.length),
};
}
const weightedProgress = items.reduce((sum, item) => {
const estimate = Math.max(0, item.estimateHours || 0);
return sum + estimate * item.progress;
}, 0);
return {
estimateHours,
actualHours,
progress: Math.round(weightedProgress / estimateHours),
};
}