feat(algo): slotsPerDay parameter for top-N selection
This commit is contained in:
1 parent
790ea72987
commit
625f9c7037
2 files changed
+39
-2
No files matched your search
+6
-2
@@ -77,7 +77,8 @@ function scoreCandidate(employee, isoDate, allHistory, randomFn) {
|
||||
}
|
||||
|
||||
// Returns { assignments: [{ date, employeeId, manual: false }], skippedDates: [] }
|
||||
export function generatePlan(workdays, employees, history, randomFn = Math.random) {
|
||||
// slotsPerDay controls how many top-scored candidates are picked per day (default 1).
|
||||
export function generatePlan(workdays, employees, history, randomFn = Math.random, slotsPerDay = 1) {
|
||||
const monthAssignments = [];
|
||||
const skippedDates = [];
|
||||
|
||||
@@ -91,7 +92,10 @@ export function generatePlan(workdays, employees, history, randomFn = Math.rando
|
||||
.map(e => ({ employee: e, score: scoreCandidate(e, date, history, randomFn) }))
|
||||
.sort((a, b) => b.score - a.score);
|
||||
|
||||
monthAssignments.push({ date, employeeId: scored[0].employee.id, manual: false });
|
||||
const take = Math.min(slotsPerDay, scored.length);
|
||||
for (let i = 0; i < take; i++) {
|
||||
monthAssignments.push({ date, employeeId: scored[i].employee.id, manual: false });
|
||||
}
|
||||
}
|
||||
|
||||
return { assignments: monthAssignments, skippedDates };
|
||||
|
||||
Reference in new issue
Block a user