Fixed calculator core

This commit is contained in:
Ray 2024-08-25 22:11:48 +01:00
parent 2b8baa0c3c
commit 62c1917b80
2 changed files with 73 additions and 100 deletions

View File

@ -1,6 +1,6 @@
{
"name": "LiteRyzJS/Project",
"version": "0.2.0.256",
"version": "0.2.0.508",
"devDependencies": {
"css-loader": "^7.1.2",
"sass": "^1.77.8",

View File

@ -9,7 +9,7 @@ class Project {
const a = this;
const _options = Object.assign(a.DefaultOptions, options);
a.Debug = false;
a.Debug = true;
a.Project = _options;
a.Tasks = [];
}
@ -190,19 +190,18 @@ class Project {
a.Sort();
// Get flat references
let result = a.Tasks.flatten("Tasks");
let allTasks = a.Tasks.flatten("Tasks");
// Reset calculated values
for (var i=0; i<result.length; i++) {
result[i].Order = (i + 1);
result[i].StartDate = null;
result[i].FinishDate = null;
result[i].CalcWorkHours = null;
for (var i=0; i<allTasks.length; i++) {
allTasks[i].Order = (i + 1);
allTasks[i].StartDate = null;
allTasks[i].FinishDate = null;
allTasks[i].CalcWorkHours = null;
}
// Maximum 128 rounds
for (var x=0; x<128; x++) {
let pendingCount = result.copy().countMany(
for (var x=0; x<16; x++) {
let pendingCount = allTasks.countMany(
{ propName: "StartDate", value: null },
{ propName: "FinishDate", value: null }
);
@ -215,78 +214,11 @@ class Project {
a.#log("Round " + (x + 1));
for (var i=0; i<result.length; i++) {
const nodeType = a.GetNodeType(result[i]);
switch (nodeType) {
case 1: // task no-parent/root
result[i].StartDate = Date.addDays(a.Project.StartDate, result[i].StartDelay);
result[i].FinishDate = Date.addDays(result[i].StartDate, result[i].Duration);
break;
case 2: // task no-parent/root, collated/group
result[i].StartDate = Date.addDays(a.Project.StartDate, result[i].StartDelay);
result[i].Progress = 0;
// update finish date, if possible
a.#recalculateCollatedTask(result, i);
break;
case 3: // task with parent
const node3 = result.first("ID", result[i].PredecessorTaskID);
if (node3 != null) {
if (node3.FinishDate != null) {
result[i].StartDate = Date.addDays(node3.FinishDate, result[i].StartDelay);
result[i].FinishDate = Date.addDays(result[i].StartDate, result[i].Duration);
}
}
break;
case 4: // task with parent, collated/group
const node4 = result.first("ID", result[i].PredecessorTaskID);
if (node4 != null) {
if (node4.FinishDate != null) {
result[i].StartDate = Date.addDays(node4.FinishDate, result[i].StartDelay);
result[i].Progress = 0;
// update finish date, if possible
a.#recalculateCollatedTask(result, i);
}
}
break;
case 5: // sub-task
const node5 = result.first("ID", result[i].CollatedTaskID);
if (node5 != null) {
if (node5.StartDate != null) {
result[i].StartDate = Date.addDays(node5.StartDate, result[i].StartDelay);
result[i].FinishDate = Date.addDays(result[i].StartDate, result[i].Duration);
result[i].Level = (node5.Level + 1);
}
}
break;
case 6: // sub-task, collated/group
const node6 = result.first("ID", result[i].CollatedTaskID);
if (node6 != null) {
if (node6.StartDate != null) {
result[i].StartDate = Date.addDays(node6.StartDate, result[i].StartDelay);
result[i].Progress = 0;
result[i].Level = (node6.Level + 1);
// update finish date, if possible
a.#recalculateCollatedTask(result, i);
}
}
break;
default: // orphan
break;
}
}
a.#recalculateTask(allTasks, a.Tasks);
}
// Calculate work-hours
a.#recalculateWorkHours(result);
a.#recalculateWorkHours(allTasks);
return isSuccess;
}
@ -333,32 +265,73 @@ class Project {
}
}
#recalculateCollatedTask(array, index) {
let node2 = array.select("CollatedTaskID", array[index].ID);
if (node2.length <= 0) {
// No children
array[index].Duration = 0;
#recalculateTask(allTasks, tasks) {
const a = this;
return new Date(array[index].StartDate);
for (let i=0; i<tasks.length; i++) {
const task = tasks[i];
a.#log(task.Name);
if (task.PredecessorTaskID != null) {
const parentTask = allTasks.first("ID", task.PredecessorTaskID);
if (parentTask != null) {
if (parentTask.FinishDate != null) {
task.StartDate = Date.addDays(parentTask.FinishDate, task.StartDelay);
a.#log("> Set StartDate from Predecessor");
}
}
} else if (task.CollatedTaskID != null) {
const groupTask = allTasks.first("ID", task.CollatedTaskID);
if (groupTask != null) {
if (groupTask.StartDate != null) {
task.StartDate = Date.addDays(groupTask.StartDate, task.StartDelay);
a.#log("> Set StartDate from Group");
}
}
} else {
task.StartDate = Date.addDays(a.Project.StartDate, task.StartDelay);
a.#log("> Set StartDate from Project");
}
// Not ready, calculation pending
if (node2.any("FinishDate", null)) {
array[index].Duration = 0;
// if (task.IsCollated) {
if (task.Tasks.length > 0) {
a.#recalculateTask(allTasks, task.Tasks);
return null;
a.#log("> Calc inner");
}
// }
if (task.StartDate != null) {
if (task.IsCollated) {
const childTasks = task.Tasks.select("CollatedTaskID", task.ID);
if (childTasks.length <= 0) {
task.FinishDate = task.StartDate;
task.Duration = 0;
a.#log("> Set FinishDate from Group (0)");
} else {
if (!childTasks.any("FinishDate", null)) {
task.FinishDate = childTasks.orderByDesc("FinishDate")[0].FinishDate;
task.Duration = Date.diffDays(task.StartDate, task.FinishDate);
a.#log("> Set FinishDate from Group");
}
}
let node2FinishDate = new Date(array[index].StartDate);
node2.forEach(e => {
if (e.FinishDate > node2FinishDate) {
node2FinishDate = e.FinishDate;
}
});
} else {
task.FinishDate = Date.addDays(task.StartDate, task.Duration);
array[index].Progress = Math.average(node2.toList("Progress"));
array[index].FinishDate = new Date(node2FinishDate);
array[index].Duration = Date.diffDays(array[index].StartDate, array[index].FinishDate);
a.#log("> Set FinishDate");
}
}
}
}
#sortNode(node) {