refactor: generatePlan returns {assignments, skippedDates}
This commit is contained in:
1 parent
e4ae866375
commit
790ea72987
3 files changed
+16
-14
No files matched your search
+3
-2
@@ -76,9 +76,10 @@ function scoreCandidate(employee, isoDate, allHistory, randomFn) {
|
||||
return score;
|
||||
}
|
||||
|
||||
// Returns [{ date, employeeId, manual: false }] for each assigned workday
|
||||
// Returns { assignments: [{ date, employeeId, manual: false }], skippedDates: [] }
|
||||
export function generatePlan(workdays, employees, history, randomFn = Math.random) {
|
||||
const monthAssignments = [];
|
||||
const skippedDates = [];
|
||||
|
||||
for (const date of workdays) {
|
||||
const candidates = employees.filter(e =>
|
||||
@@ -93,5 +94,5 @@ export function generatePlan(workdays, employees, history, randomFn = Math.rando
|
||||
monthAssignments.push({ date, employeeId: scored[0].employee.id, manual: false });
|
||||
}
|
||||
|
||||
return monthAssignments;
|
||||
return { assignments: monthAssignments, skippedDates };
|
||||
}
|
||||
+2
-1
@@ -98,7 +98,8 @@ export function renderCalendar() {
|
||||
state.calendar.holidays, state.calendar.companyClosures);
|
||||
const prefix = currentYear + '-' + String(currentMonth).padStart(2,'0');
|
||||
const historyWithoutMonth = state.history.filter(h => !h.date.startsWith(prefix));
|
||||
currentPlan = generatePlan(workdays, state.employees, historyWithoutMonth);
|
||||
const result = generatePlan(workdays, state.employees, historyWithoutMonth);
|
||||
currentPlan = result.assignments;
|
||||
addHistoryEntries(state, currentPlan);
|
||||
saveState();
|
||||
renderGrid(wrapper, exportBtn);
|
||||
|
||||
Reference in new issue
Block a user