assignment-user-matcher 1.16.1 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +290 -8
  2. package/dist/escalation/policy.d.ts +11 -0
  3. package/dist/escalation/policy.d.ts.map +1 -1
  4. package/dist/escalation/policy.js +22 -1
  5. package/dist/forecasting/backtest.d.ts +52 -0
  6. package/dist/forecasting/backtest.d.ts.map +1 -0
  7. package/dist/forecasting/backtest.js +195 -0
  8. package/dist/forecasting/calendar.d.ts +44 -0
  9. package/dist/forecasting/calendar.d.ts.map +1 -0
  10. package/dist/forecasting/calendar.js +85 -0
  11. package/dist/forecasting/cover.d.ts +69 -0
  12. package/dist/forecasting/cover.d.ts.map +1 -0
  13. package/dist/forecasting/cover.js +103 -0
  14. package/dist/forecasting/days.d.ts +17 -0
  15. package/dist/forecasting/days.d.ts.map +1 -0
  16. package/dist/forecasting/days.js +35 -0
  17. package/dist/forecasting/distributions.d.ts +31 -0
  18. package/dist/forecasting/distributions.d.ts.map +1 -0
  19. package/dist/forecasting/distributions.js +154 -0
  20. package/dist/forecasting/effects.d.ts +88 -0
  21. package/dist/forecasting/effects.d.ts.map +1 -0
  22. package/dist/forecasting/effects.js +303 -0
  23. package/dist/forecasting/erlang.d.ts +31 -0
  24. package/dist/forecasting/erlang.d.ts.map +1 -0
  25. package/dist/forecasting/erlang.js +86 -0
  26. package/dist/forecasting/forecast.d.ts +7 -0
  27. package/dist/forecasting/forecast.d.ts.map +1 -0
  28. package/dist/forecasting/forecast.js +221 -0
  29. package/dist/forecasting/index.d.ts +18 -0
  30. package/dist/forecasting/index.d.ts.map +1 -0
  31. package/dist/forecasting/index.js +54 -0
  32. package/dist/forecasting/model.d.ts +145 -0
  33. package/dist/forecasting/model.d.ts.map +1 -0
  34. package/dist/forecasting/model.js +583 -0
  35. package/dist/forecasting/nowcast.d.ts +26 -0
  36. package/dist/forecasting/nowcast.d.ts.map +1 -0
  37. package/dist/forecasting/nowcast.js +92 -0
  38. package/dist/forecasting/simulation.d.ts +91 -0
  39. package/dist/forecasting/simulation.d.ts.map +1 -0
  40. package/dist/forecasting/simulation.js +478 -0
  41. package/dist/forecasting/spikes.d.ts +6 -0
  42. package/dist/forecasting/spikes.d.ts.map +1 -0
  43. package/dist/forecasting/spikes.js +73 -0
  44. package/dist/forecasting/staffing.d.ts +64 -0
  45. package/dist/forecasting/staffing.d.ts.map +1 -0
  46. package/dist/forecasting/staffing.js +765 -0
  47. package/dist/forecasting/stats.d.ts +11 -0
  48. package/dist/forecasting/stats.d.ts.map +1 -0
  49. package/dist/forecasting/stats.js +45 -0
  50. package/dist/forecasting/types.d.ts +299 -0
  51. package/dist/forecasting/types.d.ts.map +1 -0
  52. package/dist/forecasting/types.js +8 -0
  53. package/dist/index.d.ts +3 -2
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +8 -1
  56. package/dist/learning/auto-weights.d.ts +1 -5
  57. package/dist/learning/auto-weights.d.ts.map +1 -1
  58. package/dist/learning/auto-weights.js +0 -3
  59. package/dist/lua/book-slot.lua +84 -0
  60. package/dist/lua/claim-queued.lua +47 -0
  61. package/dist/managers/DecisionTraceManager.d.ts +15 -0
  62. package/dist/managers/DecisionTraceManager.d.ts.map +1 -1
  63. package/dist/managers/DecisionTraceManager.js +117 -11
  64. package/dist/managers/LearningManager.d.ts +12 -0
  65. package/dist/managers/LearningManager.d.ts.map +1 -1
  66. package/dist/managers/LearningManager.js +21 -7
  67. package/dist/managers/ReliabilityManager.d.ts +1 -2
  68. package/dist/managers/ReliabilityManager.d.ts.map +1 -1
  69. package/dist/managers/ReliabilityManager.js +1 -1
  70. package/dist/managers/TelemetryManager.d.ts.map +1 -1
  71. package/dist/managers/TelemetryManager.js +9 -3
  72. package/dist/managers/WorkflowManager.d.ts.map +1 -1
  73. package/dist/managers/WorkflowManager.js +3 -4
  74. package/dist/matcher.class.d.ts +319 -4
  75. package/dist/matcher.class.d.ts.map +1 -1
  76. package/dist/matcher.class.js +1428 -102
  77. package/dist/queries/lane-stats.d.ts +51 -0
  78. package/dist/queries/lane-stats.d.ts.map +1 -0
  79. package/dist/queries/lane-stats.js +78 -0
  80. package/dist/schedule/recurrence.d.ts +11 -0
  81. package/dist/schedule/recurrence.d.ts.map +1 -1
  82. package/dist/schedule/recurrence.js +19 -2
  83. package/dist/schedule/slot.d.ts +60 -0
  84. package/dist/schedule/slot.d.ts.map +1 -0
  85. package/dist/schedule/slot.js +86 -0
  86. package/dist/scheduling/constraints/availability.d.ts +2 -14
  87. package/dist/scheduling/constraints/availability.d.ts.map +1 -1
  88. package/dist/scheduling/constraints/availability.js +14 -15
  89. package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
  90. package/dist/scheduling/constraints/employee-scope.js +10 -2
  91. package/dist/scheduling/constraints/support.d.ts +4 -8
  92. package/dist/scheduling/constraints/support.d.ts.map +1 -1
  93. package/dist/scheduling/constraints/support.js +23 -2
  94. package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
  95. package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
  96. package/dist/scheduling/constraints/weekly-rest.js +108 -21
  97. package/dist/scheduling/engine/construction.d.ts.map +1 -1
  98. package/dist/scheduling/engine/construction.js +33 -4
  99. package/dist/scheduling/engine/objective.d.ts +0 -1
  100. package/dist/scheduling/engine/objective.d.ts.map +1 -1
  101. package/dist/scheduling/engine/objective.js +45 -3
  102. package/dist/scheduling/engine/search.d.ts +4 -0
  103. package/dist/scheduling/engine/search.d.ts.map +1 -1
  104. package/dist/scheduling/engine/search.js +2 -1
  105. package/dist/scheduling/engine/state.d.ts +14 -0
  106. package/dist/scheduling/engine/state.d.ts.map +1 -1
  107. package/dist/scheduling/engine/state.js +7 -0
  108. package/dist/scheduling/engine/timeline.d.ts +9 -1
  109. package/dist/scheduling/engine/timeline.d.ts.map +1 -1
  110. package/dist/scheduling/engine/timeline.js +52 -27
  111. package/dist/scheduling/engine/verdicts.d.ts +40 -1
  112. package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
  113. package/dist/scheduling/engine/verdicts.js +177 -17
  114. package/dist/scheduling/index.d.ts +3 -2
  115. package/dist/scheduling/index.d.ts.map +1 -1
  116. package/dist/scheduling/index.js +7 -1
  117. package/dist/scheduling/model.d.ts +2 -3
  118. package/dist/scheduling/model.d.ts.map +1 -1
  119. package/dist/scheduling/model.js +30 -12
  120. package/dist/scheduling/operations.d.ts +174 -2
  121. package/dist/scheduling/operations.d.ts.map +1 -1
  122. package/dist/scheduling/operations.js +513 -15
  123. package/dist/scheduling/preference-report.d.ts +15 -0
  124. package/dist/scheduling/preference-report.d.ts.map +1 -0
  125. package/dist/scheduling/preference-report.js +111 -0
  126. package/dist/scheduling/preferences.d.ts +30 -0
  127. package/dist/scheduling/preferences.d.ts.map +1 -0
  128. package/dist/scheduling/preferences.js +85 -0
  129. package/dist/scheduling/resilience.d.ts +46 -0
  130. package/dist/scheduling/resilience.d.ts.map +1 -0
  131. package/dist/scheduling/resilience.js +45 -0
  132. package/dist/scheduling/scheduler.class.d.ts +12 -1
  133. package/dist/scheduling/scheduler.class.d.ts.map +1 -1
  134. package/dist/scheduling/scheduler.class.js +28 -4
  135. package/dist/scheduling/time.d.ts +28 -6
  136. package/dist/scheduling/time.d.ts.map +1 -1
  137. package/dist/scheduling/time.js +59 -17
  138. package/dist/scheduling/types.d.ts +107 -1
  139. package/dist/scheduling/types.d.ts.map +1 -1
  140. package/dist/scoring/fair-arbitration.d.ts.map +1 -1
  141. package/dist/scoring/fair-arbitration.js +2 -1
  142. package/dist/tracing/decision-trace.d.ts +5 -0
  143. package/dist/tracing/decision-trace.d.ts.map +1 -1
  144. package/dist/tracing/decision-trace.js +3 -0
  145. package/dist/types/matcher.d.ts +369 -2
  146. package/dist/types/matcher.d.ts.map +1 -1
  147. package/dist/updates/assignment-update.d.ts +93 -0
  148. package/dist/updates/assignment-update.d.ts.map +1 -0
  149. package/dist/updates/assignment-update.js +91 -0
  150. package/dist/utils/keys.d.ts +10 -0
  151. package/dist/utils/keys.d.ts.map +1 -1
  152. package/dist/utils/keys.js +43 -0
  153. package/package.json +15 -2
@@ -1 +1 @@
1
- {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/scheduling/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EACR,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,aAAa,EACb,mBAAmB,EAEnB,oBAAoB,EACvB,MAAM,SAAS,CAAC;AA6BjB,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,qEAAqE;IACrE,gBAAgB,EAAE,OAAO,CAAC;IAC1B,oDAAoD;IACpD,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAClC,wEAAwE;IACxE,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,QAAQ,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC,CAAC;IACnE;;;;;OAKG;IACH,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,uGAAuG;IACvG,aAAa,EAAE,oBAAoB,EAAE,CAAC;CACzC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,gBAAgB,CAwErG;AAMD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,aAAa,EACpB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,EACvB,MAAM,GAAE,mBAAmB,EAAO,GACnC,WAAW,EAAE,CAUf;AAMD,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAA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OG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,aAAa,GAAG,mBAAmB,CAqE/E"}
@@ -19,7 +19,7 @@
19
19
  * attempted.
20
20
  */
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = void 0;
22
+ exports.diagnoseInfeasibility = exports.checkSwap = exports.rankSwapPartners = exports.assessShiftResilience = exports.rankShiftsFor = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = void 0;
23
23
  const support_1 = require("./constraints/support");
24
24
  const min_staffing_1 = require("./constraints/min-staffing");
25
25
  const hour_budget_1 = require("./constraints/hour-budget");
@@ -27,18 +27,19 @@ const objective_1 = require("./engine/objective");
27
27
  const model_1 = require("./model");
28
28
  const propagation_1 = require("./engine/propagation");
29
29
  const state_1 = require("./engine/state");
30
- const construction_1 = require("./engine/construction");
31
30
  const verdicts_1 = require("./engine/verdicts");
32
31
  const scheduler_class_1 = require("./scheduler.class");
33
32
  const availability_1 = require("./constraints/availability");
34
33
  const cost_1 = require("./cost");
35
34
  const contract_hours_1 = require("./contract-hours");
35
+ const preference_report_1 = require("./preference-report");
36
36
  const sites_1 = require("./sites");
37
37
  const rest_days_1 = require("./constraints/rest-days");
38
38
  const notice_1 = require("./constraints/notice");
39
39
  const protections_1 = require("./constraints/protections");
40
40
  const overtime_1 = require("./constraints/overtime");
41
41
  const time_1 = require("./time");
42
+ const resilience_1 = require("./resilience");
42
43
  /** Soft-ranking weight for travel minutes in `rankCandidates`. */
43
44
  const TRAVEL_MINUTE_WEIGHT = 1;
44
45
  /** Soft-ranking weight per hour a candidate would be pushed over their contracted period total. */
@@ -86,14 +87,10 @@ function checkCompliance(input, roster) {
86
87
  (0, state_1.assign)(state, entry.employeeId, entry.shiftInstanceId, entry.reasons ?? []);
87
88
  }
88
89
  // The same two passes the solver runs when it assembles its result.
89
- const verdicts = [];
90
- for (const [instanceId, employees] of state.assignments) {
91
- for (const employeeId of employees) {
92
- const pair = { employeeId, shiftInstanceId: instanceId };
93
- verdicts.push({ pair, verdicts: (0, verdicts_1.verdictsFor)(state, pair) });
94
- }
95
- }
96
- violations.push(...(0, verdicts_1.collectPairViolations)(state), ...(0, verdicts_1.collectAggregateViolations)(state));
90
+ // Each pair is judged once: the verdicts are reported as they are, and
91
+ // their failures are the pair-level violations.
92
+ const verdicts = (0, verdicts_1.collectPairVerdicts)(state);
93
+ violations.push(...(0, verdicts_1.pairViolationsFrom)(verdicts), ...(0, verdicts_1.collectAggregateViolations)(state));
97
94
  const staffing = (0, min_staffing_1.staffingViolations)(ctx, state, 'medium');
98
95
  violations.push(...staffing, ...(0, hour_budget_1.minHourViolations)(ctx, state, ctx.constraints.find((c) => c.id === 'hour-budget')?.weight ?? objective_1.MIN_HOURS_WEIGHT));
99
96
  // The same ledger pass the solver runs at result assembly — one judgement
@@ -113,6 +110,7 @@ function checkCompliance(input, roster) {
113
110
  verdicts,
114
111
  ledger,
115
112
  contractHours: (0, contract_hours_1.contractHoursSummary)(state),
113
+ preferences: (0, preference_report_1.preferenceReport)(state),
116
114
  };
117
115
  }
118
116
  exports.checkCompliance = checkCompliance;
@@ -205,23 +203,276 @@ function rankCandidates(input, shiftInstanceId, roster, disruption) {
205
203
  }
206
204
  }
207
205
  const excluded = disruption && 'employeeId' in disruption ? disruption.employeeId : undefined;
206
+ return sortCandidates(ctx, scoreCandidates(state, inst, (employeeId) => employeeId === excluded));
207
+ }
208
+ exports.rankCandidates = rankCandidates;
209
+ /**
210
+ * One person against many shifts: `rankCandidates` turned on its side.
211
+ *
212
+ * The question a worker's phone asks of a list of open shifts is "which of
213
+ * these could *I* take?" Answering it with `rankCandidates` per shift built the
214
+ * model and scored the whole team once per posting, to read one row of each.
215
+ * This builds the model once and scores only that person — through the same
216
+ * `scoreCandidates` judgement, so each answer is exactly the row the
217
+ * team-wide ranking gives them (a candidate is scored independently of the
218
+ * others, so leaving the others out changes nothing about theirs).
219
+ *
220
+ * Returns candidates in the order `shiftInstanceIds` names them, leaving out
221
+ * ids that name no shift and shifts the person already holds — the same
222
+ * people `rankCandidates` leaves out. An unknown employee gets `[]`.
223
+ */
224
+ function rankShiftsFor(input, employeeId, shiftInstanceIds, roster) {
225
+ const ctx = (0, model_1.buildModel)(input);
226
+ if (!ctx.employeeById.has(employeeId))
227
+ return [];
228
+ const state = stateFor(ctx, roster);
229
+ const out = [];
230
+ for (const shiftInstanceId of shiftInstanceIds) {
231
+ const inst = ctx.instanceById.get(shiftInstanceId);
232
+ if (!inst)
233
+ continue;
234
+ out.push(...scoreCandidates(state, inst, (id) => id !== employeeId));
235
+ }
236
+ return out;
237
+ }
238
+ exports.rankShiftsFor = rankShiftsFor;
239
+ /**
240
+ * The capacity radar's question for every shift in a window: is it short, and
241
+ * who could legally step in if someone drops out?
242
+ *
243
+ * One model build and one working state serve the whole window, as in
244
+ * `rankShiftsFor`. Backups come from `scoreCandidates` — the judgement
245
+ * `rankCandidates` and `rankSwapPartners` use — so the radar and a cover offer
246
+ * can never disagree about who could take a shift.
247
+ *
248
+ * A rostered person the time-off rule refuses on the shift (declared time off,
249
+ * an `absences` span or an external commitment) is reported in `absent`, not
250
+ * counted in `assigned`, and is taken off the working state *before* anyone is
251
+ * judged: they are genuinely off, so they hold no seat on a capped shift and
252
+ * their hours count against nobody. The state is local to the call.
253
+ *
254
+ * Backups are judged with one seat vacated where a crew cap binds (see
255
+ * `backupsFor`): a backup replaces a dropout, and a full shift asked with
256
+ * everyone still on it has room for nobody. `assigned` and `shortBy` are
257
+ * always the real roster.
258
+ *
259
+ * `need` is the folded `minEmployees`: a caller raises it with a
260
+ * `demandOverrides` entry on the input, never through an option here.
261
+ *
262
+ * Profiling-free: declared facts (roster, time off, qualifications, rules) and
263
+ * the caller's aggregate expected-dropout number — nothing behavioural.
264
+ */
265
+ function assessShiftResilience(input, roster, options = {}) {
266
+ const ctx = (0, model_1.buildModel)(input);
267
+ const state = stateFor(ctx, roster);
268
+ const wanted = options.shiftInstanceIds ? new Set(options.shiftInstanceIds) : null;
269
+ const topBackups = options.topBackups ?? 5;
270
+ const instances = ctx.instances
271
+ .filter((inst) => !wanted || wanted.has(inst.id))
272
+ .sort((a, b) => a.date.localeCompare(b.date) || a.startMinute - b.startMinute || a.id.localeCompare(b.id));
273
+ // Absence is the time-off rule's own judgement, asked of the registered
274
+ // constraint: declared time off (overnight spill-over included),
275
+ // `input.absences` spans and external commitments, exactly as the solver
276
+ // and `checkCompliance` block them. Its answer reads only static blocked
277
+ // intervals, so asking it of an assigned pair is sound.
278
+ const timeOffRule = ctx.constraints.find((c) => c.id === 'time-off');
279
+ const isAbsent = (employeeId, shiftInstanceId) => timeOffRule !== undefined && timeOffRule.delta(state, { employeeId, shiftInstanceId }) > 0;
280
+ // Who holds what, as the working state saw it (unknown ids and duplicate
281
+ // rows fall away exactly as `stateFor` drops them). Absentees leave the
282
+ // state before any judgement, across the whole roster — an absentee on a
283
+ // shift outside the window still frees the seat and hours they held.
284
+ const assignedBy = new Map();
285
+ const absentBy = new Map();
286
+ const bucket = (map, key, empty) => {
287
+ let value = map.get(key);
288
+ if (value === undefined)
289
+ map.set(key, (value = empty()));
290
+ return value;
291
+ };
292
+ for (const pair of roster) {
293
+ if (!state.isAssigned(pair.employeeId, pair.shiftInstanceId))
294
+ continue;
295
+ if (isAbsent(pair.employeeId, pair.shiftInstanceId)) {
296
+ (0, state_1.unassign)(state, pair.employeeId, pair.shiftInstanceId);
297
+ bucket(absentBy, pair.shiftInstanceId, () => []).push(pair.employeeId);
298
+ }
299
+ else {
300
+ bucket(assignedBy, pair.shiftInstanceId, () => new Set()).add(pair.employeeId);
301
+ }
302
+ }
303
+ return instances.map((inst) => {
304
+ const assignedIds = [...(assignedBy.get(inst.id) ?? [])].sort();
305
+ const absent = absentBy.get(inst.id) ?? [];
306
+ // Absentees are off the state now, so skip them by name: their own time
307
+ // off already refuses them, and a person rostered on the shift is never
308
+ // their own cover.
309
+ const onShift = new Set([...assignedIds, ...absent]);
310
+ const { eligible, bySkill } = backupsFor(state, inst, assignedIds, onShift);
311
+ const skills = Object.entries(inst.tagRequirements).map(([tag, requirement]) => {
312
+ const held = assignedIds.filter((id) => tagsHeldOn(ctx, id, inst).includes(tag)).length;
313
+ return {
314
+ tag,
315
+ required: requirement.min,
316
+ held,
317
+ shortBy: Math.max(0, requirement.min - held),
318
+ backups: bySkill(tag),
319
+ };
320
+ });
321
+ const need = inst.minEmployees;
322
+ const shortBy = Math.max(0, need - assignedIds.length);
323
+ const expectedDropouts = options.expectedDropouts?.[inst.id] ?? 0;
324
+ // Over its maximum, the shift needs no cover: dropouts only bring it
325
+ // back towards its cap, and one vacated seat still leaves it full, so
326
+ // `backups` is 0 by construction. Tier it by shortfall alone (cover
327
+ // judged unlimited); a skill it is still short of is a composition
328
+ // problem, reported as `short-skill`, never as `no-backups`.
329
+ const overstaffed = inst.maxEmployees !== undefined && assignedIds.length > inst.maxEmployees;
330
+ const { tier, reasons } = overstaffed
331
+ ? (0, resilience_1.resilienceTier)({
332
+ shortBy,
333
+ backups: Infinity,
334
+ expectedDropouts: 0,
335
+ skills: skills.map((s) => ({ ...s, backups: Infinity })),
336
+ })
337
+ : (0, resilience_1.resilienceTier)({
338
+ shortBy,
339
+ backups: eligible.length,
340
+ expectedDropouts,
341
+ assigned: assignedIds.length,
342
+ skills,
343
+ });
344
+ return {
345
+ shiftInstanceId: inst.id,
346
+ date: inst.date,
347
+ startMinute: inst.startMinute,
348
+ endMinute: inst.endMinute,
349
+ siteId: inst.siteId,
350
+ need,
351
+ assigned: assignedIds.length,
352
+ absent,
353
+ shortBy,
354
+ expectedDropouts,
355
+ backups: eligible.length,
356
+ skills,
357
+ topBackups: eligible.slice(0, topBackups),
358
+ tier,
359
+ reasons,
360
+ };
361
+ });
362
+ }
363
+ exports.assessShiftResilience = assessShiftResilience;
364
+ /**
365
+ * Who could step in on `inst` if one rostered person dropped out.
366
+ *
367
+ * A backup replaces somebody, so the question is asked with **one seat
368
+ * vacated** — the same move `rankSwapPartners` makes for a hand-over. Asked
369
+ * with everyone still on it, a shift at its `maxEmployees` reads "already has
370
+ * its maximum" for everybody and every full shift looks like a call to the
371
+ * agency.
372
+ *
373
+ * A seat is vacated only when a crew cap actually binds: headcount at or over
374
+ * `maxEmployees`, or a `tagMaximums` tag at or over its cap. Otherwise the
375
+ * rostered team is judged as it stands — vacating would change nothing a
376
+ * pair rule reads (removing a person only lowers counts), so a shift below its
377
+ * caps gives exactly the answer it always gave.
378
+ *
379
+ * Who is vacated does not matter for headcount; it does for a capped tag: a
380
+ * forklift driver can replace the forklift driver on a shift capped at one,
381
+ * not the picker beside him. So the rostered people are grouped by which
382
+ * binding-capped and required tags they hold, one representative per group
383
+ * (the last id in sorted order) is vacated in turn, and a candidate counts if
384
+ * they could replace *somebody* — the union. A skill's backups are counted
385
+ * only against representatives holding that skill (all of them when nobody
386
+ * holds it), so "could replace a dropout" stays honest per skill. Every
387
+ * vacated pair is restored before the next, as in `tradeFits`, so person
388
+ * caching stays valid and the state leaves as it came.
389
+ *
390
+ * Cost: one full `scoreCandidates` pass per signature group, so a capped
391
+ * shift costs (distinct capped/required-tag combinations among its people)
392
+ * passes instead of one — usually one or two, at most one per rostered person.
393
+ *
394
+ * Only `group-composition` reads the crew per pair; `hour-budget`, the other
395
+ * crew-listed rule, reads the candidate's own minutes, which vacating somebody
396
+ * else never moves. Rows come from the first representative that finds the
397
+ * candidate eligible.
398
+ */
399
+ function backupsFor(state, inst, assignedIds, onShift) {
400
+ const ctx = state.ctx;
401
+ // A person dropping out is never covered by themselves: another employee
402
+ // record of anyone rostered (or absent) on the shift is skipped, in both
403
+ // branches. With their seat vacated that record would otherwise read free.
404
+ const personOf = (id) => ctx.personIdOf.get(id) ?? id;
405
+ const onShiftPeople = new Set([...onShift].map(personOf));
406
+ const skip = (id) => onShift.has(id) || onShiftPeople.has(personOf(id));
407
+ const holds = (id, tag) => ctx.holdsTagOn(id, tag, inst.date);
408
+ const cappedTags = Object.entries(inst.tagMaximums)
409
+ .filter(([tag, max]) => assignedIds.filter((id) => holds(id, tag)).length >= max)
410
+ .map(([tag]) => tag);
411
+ const full = inst.maxEmployees !== undefined && assignedIds.length >= inst.maxEmployees;
412
+ if (assignedIds.length === 0 || (!full && cappedTags.length === 0)) {
413
+ const eligible = sortCandidates(ctx, scoreCandidates(state, inst, skip).filter((c) => c.eligible));
414
+ return { eligible, bySkill: (tag) => eligible.filter((c) => c.tagsHeld.includes(tag)).length };
415
+ }
416
+ // Capped tags are read as `group-composition` reads them; required skills
417
+ // as `held` counts them (at the requirement's level).
418
+ const holdsSkill = (id, tag) => tagsHeldOn(ctx, id, inst).includes(tag);
419
+ const skillTags = Object.keys(inst.tagRequirements).sort();
420
+ const reps = new Map();
421
+ for (const id of assignedIds) {
422
+ const signature = [...cappedTags.map((tag) => holds(id, tag)), ...skillTags.map((tag) => holdsSkill(id, tag))];
423
+ reps.set(signature.map((bit) => (bit ? 1 : 0)).join(''), id);
424
+ }
425
+ const rows = new Map();
426
+ const eligibleBy = new Map();
427
+ for (const rep of [...reps.values()].sort()) {
428
+ (0, state_1.unassign)(state, rep, inst.id);
429
+ const found = new Set();
430
+ for (const c of scoreCandidates(state, inst, skip)) {
431
+ if (!c.eligible)
432
+ continue;
433
+ found.add(c.employeeId);
434
+ if (!rows.has(c.employeeId))
435
+ rows.set(c.employeeId, c);
436
+ }
437
+ (0, state_1.assign)(state, rep, inst.id, []);
438
+ eligibleBy.set(rep, found);
439
+ }
440
+ const eligible = sortCandidates(ctx, [...rows.values()]);
441
+ const bySkill = (tag) => {
442
+ const holders = [...eligibleBy.keys()].filter((rep) => holdsSkill(rep, tag));
443
+ const from = holders.length > 0 ? holders : [...eligibleBy.keys()];
444
+ const ids = new Set(from.flatMap((rep) => [...eligibleBy.get(rep)]));
445
+ return eligible.filter((c) => ids.has(c.employeeId) && c.tagsHeld.includes(tag)).length;
446
+ };
447
+ return { eligible, bySkill };
448
+ }
449
+ /**
450
+ * Score every employee not already on `inst` against the current state.
451
+ *
452
+ * Shared by `rankCandidates` and `rankSwapPartners` so the hand-over list a
453
+ * worker sees and the cover list a supervisor sees are the same judgement —
454
+ * a second copy of this loop is how the two would start disagreeing.
455
+ */
456
+ function scoreCandidates(state, inst, skip) {
457
+ const ctx = state.ctx;
458
+ const shiftInstanceId = inst.id;
208
459
  const extraLoad = extraShiftCounts(state);
209
460
  const meanExtra = average([...extraLoad.values()]);
210
461
  const candidates = [];
211
462
  for (const employee of ctx.employees) {
212
- if (employee.id === excluded)
463
+ if (skip(employee.id))
213
464
  continue;
214
465
  if (state.isAssigned(employee.id, shiftInstanceId))
215
466
  continue;
216
467
  const pair = { employeeId: employee.id, shiftInstanceId };
217
468
  const verdicts = (0, verdicts_1.verdictsFor)(state, pair);
218
469
  const blockers = verdicts.filter((v) => !v.pass && v.severity === 'hard');
219
- const eligible = blockers.length === 0 && (0, construction_1.hardCompliant)(ctx, state, employee.id, shiftInstanceId);
470
+ const eligible = blockers.length === 0 && !(0, verdicts_1.anyHardDeltaGiven)(state, pair, verdicts);
220
471
  // Marginal against what this person already holds: the same shift is
221
472
  // dearer in the hands of someone past their overtime threshold.
222
473
  const costCents = (0, cost_1.marginalCostCents)(inst, employee, state.minutesByEmployee.get(employee.id) ?? 0, (0, support_1.rulesFor)(ctx, employee.id).engagement);
223
474
  const fairnessDebt = meanExtra - (extraLoad.get(employee.id) ?? 0);
224
- const preference = (0, availability_1.preferenceScore)(ctx.clock, employee.availability, inst);
475
+ const preference = (0, availability_1.preferenceScore)(ctx.clock, ctx.preferenceRules.get(employee.id), inst);
225
476
  const originSiteId = originSiteFor(state, employee.id, inst);
226
477
  const travelMinutes = originSiteId !== undefined && inst.siteId !== undefined
227
478
  ? (0, sites_1.travelMinutesBetween)(ctx.siteIndex, originSiteId, inst.siteId)
@@ -251,6 +502,7 @@ function rankCandidates(input, shiftInstanceId, roster, disruption) {
251
502
  travelMinutes,
252
503
  distanceKm,
253
504
  isHomeSite,
505
+ tagsHeld: tagsHeldOn(ctx, employee.id, inst),
254
506
  // Ineligible candidates sort to the bottom but stay visible.
255
507
  rank: eligible
256
508
  ? costCents / 100 -
@@ -262,6 +514,9 @@ function rankCandidates(input, shiftInstanceId, roster, disruption) {
262
514
  rationale: rationaleFor(eligible, blockers, costCents, fairnessDebt, preference, travelMinutes, distanceKm, originSiteId, isHomeSite, contractDeltaMinutes),
263
515
  });
264
516
  }
517
+ return candidates;
518
+ }
519
+ function sortCandidates(ctx, candidates) {
265
520
  /*
266
521
  * Rank, then seniority, then id.
267
522
  *
@@ -287,7 +542,125 @@ function rankCandidates(input, shiftInstanceId, roster, disruption) {
287
542
  (ctx.employeeById.get(b.employeeId)?.seniority ?? 0) - (ctx.employeeById.get(a.employeeId)?.seniority ?? 0) ||
288
543
  (a.employeeId < b.employeeId ? -1 : 1));
289
544
  }
290
- exports.rankCandidates = rankCandidates;
545
+ /**
546
+ * Who could take a shift off the person holding it, and what they could swap.
547
+ *
548
+ * `rankCandidates` answers "who can fill this gap?" — a gap nobody is in. A
549
+ * hand-over is asked about a shift somebody *is* in, so the proposer is taken
550
+ * off it first; asked with them still on it, a full shift reads "no room" for
551
+ * everybody.
552
+ *
553
+ * A trade is judged with **both** people off the shift they are giving up,
554
+ * in both directions, on one model build. Rules that span a whole shift or
555
+ * period (tag counts and ratios, aggregates) are not judged here: the host
556
+ * re-checks the full roster before applying, and this list is the prefilter
557
+ * that keeps a worker from asking a question whose answer is always no.
558
+ *
559
+ * Ordering is `rankCandidates`' own, so it stays inside the same
560
+ * profiling-free boundary.
561
+ */
562
+ function rankSwapPartners(input, shiftInstanceId, fromEmployeeId, roster, options = {}) {
563
+ const ctx = (0, model_1.buildModel)(input);
564
+ const inst = ctx.instanceById.get(shiftInstanceId);
565
+ if (!inst)
566
+ return [];
567
+ const state = stateFor(ctx, roster);
568
+ (0, state_1.unassign)(state, fromEmployeeId, shiftInstanceId);
569
+ const partners = sortCandidates(ctx, scoreCandidates(state, inst, (employeeId) => employeeId === fromEmployeeId));
570
+ if (!options.trades)
571
+ return partners;
572
+ const proposerHolds = new Set(state.byEmployee.get(fromEmployeeId) ?? []);
573
+ for (const partner of partners) {
574
+ const held = [...(state.byEmployee.get(partner.employeeId) ?? [])]
575
+ .map((id) => ctx.instanceById.get(id))
576
+ .filter((theirs) => theirs.id !== shiftInstanceId && !proposerHolds.has(theirs.id))
577
+ .filter((theirs) => options.tradesFrom === undefined || theirs.date >= options.tradesFrom)
578
+ .sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : a.id < b.id ? -1 : 1));
579
+ partner.trades = held
580
+ .filter((theirs) => tradeFits(state, fromEmployeeId, shiftInstanceId, partner.employeeId, theirs.id).fits)
581
+ .map((theirs) => ({ shiftInstanceId: theirs.id }));
582
+ }
583
+ return partners;
584
+ }
585
+ exports.rankSwapPartners = rankSwapPartners;
586
+ /**
587
+ * Judge one proposed hand-over or trade, the same way `rankSwapPartners`
588
+ * judges each entry on its list.
589
+ *
590
+ * `toShiftInstanceId` null is a give-away. Either person not holding the shift
591
+ * named is an `input` blocker rather than a pass: a trade of shifts neither
592
+ * holds is not a trade.
593
+ */
594
+ function checkSwap(input, swap, roster) {
595
+ const ctx = (0, model_1.buildModel)(input);
596
+ const state = stateFor(ctx, roster);
597
+ const notHeld = (employeeId, shiftInstanceId) => ({
598
+ employeeId,
599
+ ruleId: 'input',
600
+ pass: false,
601
+ severity: 'hard',
602
+ message: `${employeeId} is not on ${shiftInstanceId}`,
603
+ });
604
+ if (!state.isAssigned(swap.fromEmployeeId, swap.fromShiftInstanceId)) {
605
+ return { fits: false, blockers: [notHeld(swap.fromEmployeeId, swap.fromShiftInstanceId)] };
606
+ }
607
+ if (swap.toShiftInstanceId && !state.isAssigned(swap.toEmployeeId, swap.toShiftInstanceId)) {
608
+ return { fits: false, blockers: [notHeld(swap.toEmployeeId, swap.toShiftInstanceId)] };
609
+ }
610
+ return tradeFits(state, swap.fromEmployeeId, swap.fromShiftInstanceId, swap.toEmployeeId, swap.toShiftInstanceId);
611
+ }
612
+ exports.checkSwap = checkSwap;
613
+ function stateFor(ctx, roster) {
614
+ const state = (0, state_1.createState)(ctx);
615
+ for (const entry of roster) {
616
+ if (ctx.instanceById.has(entry.shiftInstanceId) && ctx.employeeById.has(entry.employeeId)) {
617
+ (0, state_1.assign)(state, entry.employeeId, entry.shiftInstanceId, []);
618
+ }
619
+ }
620
+ return state;
621
+ }
622
+ /**
623
+ * Both moves of a swap, judged with both people off what they give up.
624
+ *
625
+ * Leaves `state` exactly as it found it: the vacated pairs go back on, so a
626
+ * caller can judge many trades against one build.
627
+ */
628
+ function tradeFits(state, fromEmployeeId, fromShiftInstanceId, toEmployeeId, toShiftInstanceId) {
629
+ const restore = [];
630
+ for (const [employeeId, instanceId] of [
631
+ [fromEmployeeId, fromShiftInstanceId],
632
+ ...(toShiftInstanceId ? [[toEmployeeId, toShiftInstanceId]] : []),
633
+ ]) {
634
+ if (state.isAssigned(employeeId, instanceId)) {
635
+ (0, state_1.unassign)(state, employeeId, instanceId);
636
+ restore.push([employeeId, instanceId]);
637
+ }
638
+ }
639
+ const blockers = [];
640
+ const judge = (employeeId, instanceId) => {
641
+ const pair = { employeeId, shiftInstanceId: instanceId };
642
+ const verdicts = (0, verdicts_1.verdictsFor)(state, pair);
643
+ const failing = verdicts.filter((v) => !v.pass && v.severity === 'hard');
644
+ blockers.push(...failing.map((v) => ({ ...v, employeeId })));
645
+ // A constraint can refuse without a verdict saying why; the refusal
646
+ // still stands, under a generic reason.
647
+ if (failing.length === 0 && (0, verdicts_1.anyHardDeltaGiven)(state, pair, verdicts)) {
648
+ blockers.push({
649
+ employeeId,
650
+ ruleId: 'hard',
651
+ pass: false,
652
+ severity: 'hard',
653
+ message: `${employeeId} cannot work ${instanceId} under the working-time rules`,
654
+ });
655
+ }
656
+ };
657
+ judge(toEmployeeId, fromShiftInstanceId);
658
+ if (toShiftInstanceId)
659
+ judge(fromEmployeeId, toShiftInstanceId);
660
+ for (const [employeeId, instanceId] of restore)
661
+ (0, state_1.assign)(state, employeeId, instanceId, []);
662
+ return { fits: blockers.length === 0, blockers };
663
+ }
291
664
  function rationaleFor(eligible, blockers, costCents, fairnessDebt, preference, travelMinutes, distanceKm, originSiteId, isHomeSite, contractDeltaMinutes) {
292
665
  if (!eligible)
293
666
  return blockers.map((b) => b.message).join('; ') || 'not eligible';
@@ -441,8 +814,12 @@ function diagnoseInfeasibility(input) {
441
814
  const ctx = (0, model_1.buildModel)(input);
442
815
  const propagation = (0, propagation_1.propagate)(ctx);
443
816
  const findings = [];
817
+ // Judged against an empty roster (history still counts): a rule that
818
+ // refuses somebody here refuses them whatever else the roster holds.
819
+ const empty = (0, state_1.createState)(ctx);
444
820
  for (const inst of ctx.instances) {
445
821
  const eligible = propagation.eligibleByInstance.get(inst.id) ?? [];
822
+ const lawless = inst.minEmployees > 0 && eligible.length > 0 ? nobodyLawful(empty, inst, eligible) : null;
446
823
  if (inst.minEmployees > 0 && eligible.length === 0) {
447
824
  findings.push({
448
825
  kind: 'noEligibleEmployee',
@@ -450,6 +827,17 @@ function diagnoseInfeasibility(input) {
450
827
  message: `no employee is eligible for "${inst.id}"`,
451
828
  });
452
829
  }
830
+ else if (lawless) {
831
+ const top = lawless[0];
832
+ findings.push({
833
+ kind: 'noLawfulEmployee',
834
+ shiftInstanceId: inst.id,
835
+ message: `nobody may lawfully work "${inst.id}"${top ? `: ${top.message}` : ''}`,
836
+ blockers: lawless,
837
+ durationMinutes: inst.durationMinutes,
838
+ workingMinutes: inst.workingMinutes,
839
+ });
840
+ }
453
841
  else if (eligible.length < inst.minEmployees) {
454
842
  findings.push({
455
843
  kind: 'insufficientCapacity',
@@ -488,9 +876,119 @@ function diagnoseInfeasibility(input) {
488
876
  });
489
877
  }
490
878
  }
491
- return { feasible: findings.length === 0, findings };
879
+ return { feasible: findings.length === 0, findings, tagCover: tagCover(ctx) };
492
880
  }
493
881
  exports.diagnoseInfeasibility = diagnoseInfeasibility;
882
+ /**
883
+ * `null` when somebody could lawfully take `inst` on `state`; otherwise every
884
+ * hard blocker among the eligible, grouped by rule, most people first.
885
+ *
886
+ * Stops at the first lawful person, so a shift anyone can work costs a
887
+ * verdict or two. Only a shift nobody can work is judged for everyone — the
888
+ * rarity that is worth explaining.
889
+ */
890
+ function nobodyLawful(state, inst, eligible) {
891
+ for (const employeeId of eligible) {
892
+ if (!(0, verdicts_1.hardBlocked)(state, { employeeId, shiftInstanceId: inst.id }))
893
+ return null;
894
+ }
895
+ const byRule = new Map();
896
+ for (const employeeId of eligible) {
897
+ const pair = { employeeId, shiftInstanceId: inst.id };
898
+ const verdicts = (0, verdicts_1.verdictsFor)(state, pair);
899
+ const failing = verdicts.filter((v) => !v.pass && v.severity === 'hard');
900
+ const seen = new Set();
901
+ for (const v of failing) {
902
+ if (seen.has(v.ruleId))
903
+ continue;
904
+ seen.add(v.ruleId);
905
+ const entry = byRule.get(v.ruleId);
906
+ if (entry)
907
+ entry.employees++;
908
+ else
909
+ byRule.set(v.ruleId, { employees: 1, example: v });
910
+ }
911
+ }
912
+ return [...byRule.entries()]
913
+ .sort((a, b) => b[1].employees - a[1].employees || a[0].localeCompare(b[0]))
914
+ .map(([ruleId, { employees, example }]) => ({
915
+ ruleId,
916
+ employees,
917
+ message: example.message,
918
+ ...(example.actual !== undefined ? { actual: example.actual } : {}),
919
+ ...(example.required !== undefined ? { required: example.required } : {}),
920
+ ...(example.unit !== undefined ? { unit: example.unit } : {}),
921
+ }));
922
+ }
923
+ /** Which of `inst`'s mix requirements the employee holds on its date, at the level asked for. */
924
+ function tagsHeldOn(ctx, employeeId, inst) {
925
+ return Object.entries(inst.tagRequirements)
926
+ .filter(([tag, requirement]) => requirement.level !== undefined
927
+ ? ctx.holdsTagAt(employeeId, tag, inst.date, requirement.level)
928
+ : ctx.holdsTagOn(employeeId, tag, inst.date))
929
+ .map(([tag]) => tag);
930
+ }
931
+ function tagCover(ctx) {
932
+ const demand = new Map();
933
+ const add = (tag, kind, seats, date, level) => {
934
+ if (seats <= 0)
935
+ return;
936
+ const entry = demand.get(tag) ?? { kind, shifts: 0, seats: 0, byDate: new Map() };
937
+ if (kind === 'everyone')
938
+ entry.kind = 'everyone';
939
+ entry.shifts += 1;
940
+ entry.seats += seats;
941
+ const day = entry.byDate.get(date) ?? { seats: 0 };
942
+ day.seats += seats;
943
+ if (level !== undefined)
944
+ day.level = Math.max(day.level ?? 0, level);
945
+ entry.byDate.set(date, day);
946
+ demand.set(tag, entry);
947
+ };
948
+ for (const inst of ctx.instances) {
949
+ for (const [tag, requirement] of Object.entries(inst.tagRequirements)) {
950
+ add(tag, 'mix', requirement.min, inst.date, requirement.level);
951
+ }
952
+ for (const [tag, ratio] of Object.entries(inst.tagRatios))
953
+ add(tag, 'mix', Math.ceil(ratio * inst.minEmployees), inst.date);
954
+ for (const tag of inst.requiredTags)
955
+ add(tag, 'everyone', inst.minEmployees, inst.date);
956
+ }
957
+ const offOn = (employee, date) => employee.timeOff.some((entry) => entry.date === date && entry.shiftInstanceId === undefined) ||
958
+ (employee.contract?.startDate !== undefined && date < employee.contract.startDate) ||
959
+ (employee.contract?.endDate !== undefined && date > employee.contract.endDate);
960
+ const holds = (employeeId, tag, date, level) => level !== undefined ? ctx.holdsTagAt(employeeId, tag, date, level) : ctx.holdsTagOn(employeeId, tag, date);
961
+ const out = [];
962
+ for (const [tag, entry] of demand) {
963
+ const holderIds = new Set();
964
+ const shortDates = [];
965
+ const tightDates = [];
966
+ for (const [date, day] of [...entry.byDate.entries()].sort(([a], [b]) => a.localeCompare(b))) {
967
+ let available = 0;
968
+ for (const employee of ctx.employees) {
969
+ if (!holds(employee.id, tag, date, day.level))
970
+ continue;
971
+ holderIds.add(employee.id);
972
+ if (!offOn(employee, date))
973
+ available += 1;
974
+ }
975
+ if (available < day.seats)
976
+ shortDates.push({ date, needed: day.seats, available });
977
+ else if (available === day.seats)
978
+ tightDates.push(date);
979
+ }
980
+ out.push({
981
+ tag,
982
+ kind: entry.kind,
983
+ shifts: entry.shifts,
984
+ seats: entry.seats,
985
+ holders: holderIds.size,
986
+ shortDates,
987
+ tightDates,
988
+ });
989
+ }
990
+ return out.sort((a, b) => a.tag.localeCompare(b.tag));
991
+ }
494
992
  /** Per tag: how many assignments want it, and on which dates they want it. */
495
993
  function tagDemand(ctx) {
496
994
  const demand = new Map();
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Which stated preferences a finished roster honoured, and why the others
3
+ * were not.
4
+ *
5
+ * Assembled once per result, never in the search loop. Eligibility is the
6
+ * same judgement `rankCandidates` makes: no hard verdict against the pair,
7
+ * and `hardCompliant`. So "nobody else could work it" here and an empty
8
+ * candidate list there are one answer. The one difference is the question
9
+ * asked: here it is whether a person could have taken a place somebody
10
+ * holds, so the holder is taken off the shift for the check and put back.
11
+ */
12
+ import type { EmployeePreferenceReport } from './types';
13
+ import { type InternalState } from './engine/state';
14
+ export declare function preferenceReport(state: InternalState): EmployeePreferenceReport[];
15
+ //# sourceMappingURL=preference-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preference-report.d.ts","sourceRoot":"","sources":["../../src/scheduling/preference-report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAwC,MAAM,SAAS,CAAC;AAC9F,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA2D/E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,aAAa,GAAG,wBAAwB,EAAE,CA4CjF"}