fix: manday count

This commit is contained in:
0Xiao0
2026-03-31 17:24:01 +08:00
parent 018c653267
commit a1a52a6a6e
2 changed files with 53 additions and 11 deletions

View File

@ -668,6 +668,31 @@ function renderHTML(nodes, isRoot) {
return html; return html;
} }
function calculateNodeManday(node, coveredByParentWithManday) {
let manday = 0;
let hasManday = false;
if (node.manday) {
let val = parseFloat(node.manday);
if (!isNaN(val) && val > 0) {
// Rule: Divide by number of leaders
let divisor = (node.leaders && node.leaders.length > 0) ? node.leaders.length : 1;
manday = val / divisor;
hasManday = true;
}
}
if (node.isMatch) {
if (coveredByParentWithManday) return 0; // Already counted at a higher level
if (hasManday) return manday; // This node matches and has its own manday, use it and ignore descendants' manday
// Match but no manday on this node, accumulate from matching descendants
return node.children.reduce((acc, child) => acc + calculateNodeManday(child, false), 0);
} else {
// This node doesn't match, check descendants.
// If a parent match already covered this branch, we still pass that info down.
return node.children.reduce((acc, child) => acc + calculateNodeManday(child, coveredByParentWithManday), 0);
}
}
function countNodes(nodes) { function countNodes(nodes) {
return nodes.reduce((sum, n) => sum + 1 + countNodes(n.children), 0); return nodes.reduce((sum, n) => sum + 1 + countNodes(n.children), 0);
} }
@ -685,16 +710,12 @@ function generateSummary(nodes, status, leader) {
let matched = collectMatchedNodes(nodes); let matched = collectMatchedNodes(nodes);
if (matched.length === 0) return ''; if (matched.length === 0) return '';
let totalMandays = 0; let totalMandays = nodes.reduce((sum, n) => sum + calculateNodeManday(n, false), 0);
let completed = 0; let completed = 0;
let ongoing = 0; let ongoing = 0;
let taskNames = []; let taskNames = [];
matched.forEach(r => { matched.forEach(r => {
if (r.manday) {
let num = parseFloat(r.manday);
if (!isNaN(num)) totalMandays += num;
}
if (r.status && (r.status.includes('Completed') || r.status.includes('完成'))) completed++; if (r.status && (r.status.includes('Completed') || r.status.includes('完成'))) completed++;
else if (r.status && (r.status.includes('Ongoing') || r.status.includes('进行中'))) ongoing++; else if (r.status && (r.status.includes('Ongoing') || r.status.includes('进行中'))) ongoing++;

File diff suppressed because one or more lines are too long