Begin refactoring smart schedule calculations.

This commit is contained in:
Patrick Fic
2020-10-08 13:42:56 -07:00
parent 630e8a32ed
commit 020bec3fa2
7 changed files with 185 additions and 74 deletions

View File

@@ -0,0 +1,42 @@
export const CheckJobBucket = (buckets, job) => {
const jobHours =
job.labhrs.aggregate.sum.mod_lb_hrs + job.larhrs.aggregate.sum.mod_lb_hrs;
const matchingBucket = buckets.filter(
(b) => b.gte <= jobHours && b.lt > jobHours
);
return matchingBucket[0] && matchingBucket[0].id;
};
export const CalculateLoad = (currentLoad, buckets, jobsIn, jobsOut) => {
//Add the jobs coming
const newLoad = { ...currentLoad };
jobsIn.forEach((job) => {
const bucketId = CheckJobBucket(buckets, job);
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count + 1;
} else {
console.log(
"[Util Arr Job]Uh oh, this job doesn't fit in a bucket!",
job
);
}
});
jobsOut.forEach((job) => {
const bucketId = CheckJobBucket(buckets, job);
if (bucketId) {
newLoad[bucketId].count = newLoad[bucketId].count - 1;
} else {
console.log(
"[Util Arr Job]Uh oh, this job doesn't fit in a bucket!",
job
);
}
});
console.log("newLoad", newLoad);
return newLoad;
};