Fixed calculator core
This commit is contained in:
parent
2b8baa0c3c
commit
62c1917b80
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "LiteRyzJS/Project",
|
"name": "LiteRyzJS/Project",
|
||||||
"version": "0.2.0.256",
|
"version": "0.2.0.508",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"css-loader": "^7.1.2",
|
"css-loader": "^7.1.2",
|
||||||
"sass": "^1.77.8",
|
"sass": "^1.77.8",
|
||||||
|
@ -9,7 +9,7 @@ class Project {
|
|||||||
const a = this;
|
const a = this;
|
||||||
const _options = Object.assign(a.DefaultOptions, options);
|
const _options = Object.assign(a.DefaultOptions, options);
|
||||||
|
|
||||||
a.Debug = false;
|
a.Debug = true;
|
||||||
a.Project = _options;
|
a.Project = _options;
|
||||||
a.Tasks = [];
|
a.Tasks = [];
|
||||||
}
|
}
|
||||||
@ -190,19 +190,18 @@ class Project {
|
|||||||
a.Sort();
|
a.Sort();
|
||||||
|
|
||||||
// Get flat references
|
// Get flat references
|
||||||
let result = a.Tasks.flatten("Tasks");
|
let allTasks = a.Tasks.flatten("Tasks");
|
||||||
|
|
||||||
// Reset calculated values
|
// Reset calculated values
|
||||||
for (var i=0; i<result.length; i++) {
|
for (var i=0; i<allTasks.length; i++) {
|
||||||
result[i].Order = (i + 1);
|
allTasks[i].Order = (i + 1);
|
||||||
result[i].StartDate = null;
|
allTasks[i].StartDate = null;
|
||||||
result[i].FinishDate = null;
|
allTasks[i].FinishDate = null;
|
||||||
result[i].CalcWorkHours = null;
|
allTasks[i].CalcWorkHours = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maximum 128 rounds
|
for (var x=0; x<16; x++) {
|
||||||
for (var x=0; x<128; x++) {
|
let pendingCount = allTasks.countMany(
|
||||||
let pendingCount = result.copy().countMany(
|
|
||||||
{ propName: "StartDate", value: null },
|
{ propName: "StartDate", value: null },
|
||||||
{ propName: "FinishDate", value: null }
|
{ propName: "FinishDate", value: null }
|
||||||
);
|
);
|
||||||
@ -215,78 +214,11 @@ class Project {
|
|||||||
|
|
||||||
a.#log("Round " + (x + 1));
|
a.#log("Round " + (x + 1));
|
||||||
|
|
||||||
for (var i=0; i<result.length; i++) {
|
a.#recalculateTask(allTasks, a.Tasks);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate work-hours
|
// Calculate work-hours
|
||||||
a.#recalculateWorkHours(result);
|
a.#recalculateWorkHours(allTasks);
|
||||||
|
|
||||||
return isSuccess;
|
return isSuccess;
|
||||||
}
|
}
|
||||||
@ -333,32 +265,73 @@ class Project {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#recalculateCollatedTask(array, index) {
|
#recalculateTask(allTasks, tasks) {
|
||||||
let node2 = array.select("CollatedTaskID", array[index].ID);
|
const a = this;
|
||||||
if (node2.length <= 0) {
|
|
||||||
// No children
|
|
||||||
array[index].Duration = 0;
|
|
||||||
|
|
||||||
return new Date(array[index].StartDate);
|
for (let i=0; i<tasks.length; i++) {
|
||||||
}
|
const task = tasks[i];
|
||||||
|
|
||||||
// Not ready, calculation pending
|
a.#log(task.Name);
|
||||||
if (node2.any("FinishDate", null)) {
|
|
||||||
array[index].Duration = 0;
|
|
||||||
|
|
||||||
return null;
|
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);
|
||||||
|
|
||||||
let node2FinishDate = new Date(array[index].StartDate);
|
a.#log("> Set StartDate from Predecessor");
|
||||||
node2.forEach(e => {
|
}
|
||||||
if (e.FinishDate > node2FinishDate) {
|
}
|
||||||
node2FinishDate = e.FinishDate;
|
} 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");
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
array[index].Progress = Math.average(node2.toList("Progress"));
|
// if (task.IsCollated) {
|
||||||
array[index].FinishDate = new Date(node2FinishDate);
|
if (task.Tasks.length > 0) {
|
||||||
array[index].Duration = Date.diffDays(array[index].StartDate, array[index].FinishDate);
|
a.#recalculateTask(allTasks, task.Tasks);
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
task.FinishDate = Date.addDays(task.StartDate, task.Duration);
|
||||||
|
|
||||||
|
a.#log("> Set FinishDate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#sortNode(node) {
|
#sortNode(node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user