assignment-user-matcher 1.16.0 → 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.
- package/README.md +312 -20
- package/dist/escalation/policy.d.ts +11 -0
- package/dist/escalation/policy.d.ts.map +1 -1
- package/dist/escalation/policy.js +22 -1
- package/dist/forecasting/backtest.d.ts +52 -0
- package/dist/forecasting/backtest.d.ts.map +1 -0
- package/dist/forecasting/backtest.js +195 -0
- package/dist/forecasting/calendar.d.ts +44 -0
- package/dist/forecasting/calendar.d.ts.map +1 -0
- package/dist/forecasting/calendar.js +85 -0
- package/dist/forecasting/cover.d.ts +69 -0
- package/dist/forecasting/cover.d.ts.map +1 -0
- package/dist/forecasting/cover.js +103 -0
- package/dist/forecasting/days.d.ts +17 -0
- package/dist/forecasting/days.d.ts.map +1 -0
- package/dist/forecasting/days.js +35 -0
- package/dist/forecasting/distributions.d.ts +31 -0
- package/dist/forecasting/distributions.d.ts.map +1 -0
- package/dist/forecasting/distributions.js +154 -0
- package/dist/forecasting/effects.d.ts +88 -0
- package/dist/forecasting/effects.d.ts.map +1 -0
- package/dist/forecasting/effects.js +303 -0
- package/dist/forecasting/erlang.d.ts +31 -0
- package/dist/forecasting/erlang.d.ts.map +1 -0
- package/dist/forecasting/erlang.js +86 -0
- package/dist/forecasting/forecast.d.ts +7 -0
- package/dist/forecasting/forecast.d.ts.map +1 -0
- package/dist/forecasting/forecast.js +221 -0
- package/dist/forecasting/index.d.ts +18 -0
- package/dist/forecasting/index.d.ts.map +1 -0
- package/dist/forecasting/index.js +54 -0
- package/dist/forecasting/model.d.ts +145 -0
- package/dist/forecasting/model.d.ts.map +1 -0
- package/dist/forecasting/model.js +583 -0
- package/dist/forecasting/nowcast.d.ts +26 -0
- package/dist/forecasting/nowcast.d.ts.map +1 -0
- package/dist/forecasting/nowcast.js +92 -0
- package/dist/forecasting/simulation.d.ts +91 -0
- package/dist/forecasting/simulation.d.ts.map +1 -0
- package/dist/forecasting/simulation.js +478 -0
- package/dist/forecasting/spikes.d.ts +6 -0
- package/dist/forecasting/spikes.d.ts.map +1 -0
- package/dist/forecasting/spikes.js +73 -0
- package/dist/forecasting/staffing.d.ts +64 -0
- package/dist/forecasting/staffing.d.ts.map +1 -0
- package/dist/forecasting/staffing.js +765 -0
- package/dist/forecasting/stats.d.ts +11 -0
- package/dist/forecasting/stats.d.ts.map +1 -0
- package/dist/forecasting/stats.js +45 -0
- package/dist/forecasting/types.d.ts +299 -0
- package/dist/forecasting/types.d.ts.map +1 -0
- package/dist/forecasting/types.js +8 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/learning/auto-weights.d.ts +1 -5
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +0 -3
- package/dist/lua/book-slot.lua +84 -0
- package/dist/lua/claim-queued.lua +47 -0
- package/dist/managers/DecisionTraceManager.d.ts +15 -0
- package/dist/managers/DecisionTraceManager.d.ts.map +1 -1
- package/dist/managers/DecisionTraceManager.js +117 -11
- package/dist/managers/LearningManager.d.ts +12 -0
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +21 -7
- package/dist/managers/ReliabilityManager.d.ts +1 -2
- package/dist/managers/ReliabilityManager.d.ts.map +1 -1
- package/dist/managers/ReliabilityManager.js +1 -1
- package/dist/managers/TelemetryManager.d.ts.map +1 -1
- package/dist/managers/TelemetryManager.js +9 -3
- package/dist/managers/WorkflowManager.d.ts.map +1 -1
- package/dist/managers/WorkflowManager.js +3 -4
- package/dist/matcher.class.d.ts +319 -4
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +1428 -102
- package/dist/queries/lane-stats.d.ts +51 -0
- package/dist/queries/lane-stats.d.ts.map +1 -0
- package/dist/queries/lane-stats.js +78 -0
- package/dist/schedule/recurrence.d.ts +11 -0
- package/dist/schedule/recurrence.d.ts.map +1 -1
- package/dist/schedule/recurrence.js +19 -2
- package/dist/schedule/slot.d.ts +60 -0
- package/dist/schedule/slot.d.ts.map +1 -0
- package/dist/schedule/slot.js +86 -0
- package/dist/scheduling/constraints/availability.d.ts +2 -14
- package/dist/scheduling/constraints/availability.d.ts.map +1 -1
- package/dist/scheduling/constraints/availability.js +14 -15
- package/dist/scheduling/constraints/consecutive.d.ts +10 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -1
- package/dist/scheduling/constraints/consecutive.js +64 -1
- package/dist/scheduling/constraints/contract.d.ts.map +1 -1
- package/dist/scheduling/constraints/contract.js +12 -3
- package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
- package/dist/scheduling/constraints/employee-scope.js +10 -2
- package/dist/scheduling/constraints/group-composition.js +2 -2
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -1
- package/dist/scheduling/constraints/min-staffing.js +51 -8
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -1
- package/dist/scheduling/constraints/rolling-hours.js +29 -4
- package/dist/scheduling/constraints/support.d.ts +4 -8
- package/dist/scheduling/constraints/support.d.ts.map +1 -1
- package/dist/scheduling/constraints/support.js +23 -2
- package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
- package/dist/scheduling/constraints/weekly-rest.js +108 -21
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +56 -7
- package/dist/scheduling/engine/objective.d.ts +0 -1
- package/dist/scheduling/engine/objective.d.ts.map +1 -1
- package/dist/scheduling/engine/objective.js +65 -6
- package/dist/scheduling/engine/search.d.ts +4 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -1
- package/dist/scheduling/engine/search.js +2 -1
- package/dist/scheduling/engine/state.d.ts +14 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -1
- package/dist/scheduling/engine/state.js +7 -0
- package/dist/scheduling/engine/timeline.d.ts +23 -1
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +85 -27
- package/dist/scheduling/engine/verdicts.d.ts +40 -1
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
- package/dist/scheduling/engine/verdicts.js +177 -17
- package/dist/scheduling/index.d.ts +3 -2
- package/dist/scheduling/index.d.ts.map +1 -1
- package/dist/scheduling/index.js +7 -1
- package/dist/scheduling/model.d.ts +8 -4
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +239 -23
- package/dist/scheduling/operations.d.ts +174 -2
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +558 -21
- package/dist/scheduling/preference-report.d.ts +15 -0
- package/dist/scheduling/preference-report.d.ts.map +1 -0
- package/dist/scheduling/preference-report.js +111 -0
- package/dist/scheduling/preferences.d.ts +30 -0
- package/dist/scheduling/preferences.d.ts.map +1 -0
- package/dist/scheduling/preferences.js +85 -0
- package/dist/scheduling/resilience.d.ts +46 -0
- package/dist/scheduling/resilience.d.ts.map +1 -0
- package/dist/scheduling/resilience.js +45 -0
- package/dist/scheduling/scheduler.class.d.ts +12 -1
- package/dist/scheduling/scheduler.class.d.ts.map +1 -1
- package/dist/scheduling/scheduler.class.js +28 -4
- package/dist/scheduling/sites.d.ts +1 -1
- package/dist/scheduling/sites.d.ts.map +1 -1
- package/dist/scheduling/sites.js +34 -1
- package/dist/scheduling/time.d.ts +28 -6
- package/dist/scheduling/time.d.ts.map +1 -1
- package/dist/scheduling/time.js +59 -17
- package/dist/scheduling/types.d.ts +247 -7
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.js +2 -1
- package/dist/tracing/decision-trace.d.ts +5 -0
- package/dist/tracing/decision-trace.d.ts.map +1 -1
- package/dist/tracing/decision-trace.js +3 -0
- package/dist/types/matcher.d.ts +369 -2
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/updates/assignment-update.d.ts +93 -0
- package/dist/updates/assignment-update.d.ts.map +1 -0
- package/dist/updates/assignment-update.js +91 -0
- package/dist/utils/keys.d.ts +10 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +43 -0
- package/package.json +25 -3
package/dist/scheduling/model.js
CHANGED
|
@@ -26,16 +26,21 @@
|
|
|
26
26
|
* modeled properly here.
|
|
27
27
|
*/
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.MINUTES_PER_DAY = exports.
|
|
29
|
+
exports.MINUTES_PER_DAY = exports.buildModel = exports.resolveConstraints = exports.mergeRules = exports.expandTemplate = exports.expandShiftInstances = exports.addDays = exports.daysBetween = exports.availabilityApplies = void 0;
|
|
30
30
|
const types_1 = require("./types");
|
|
31
|
+
const preferences_1 = require("./preferences");
|
|
31
32
|
const constraint_1 = require("./constraints/constraint");
|
|
32
33
|
const employee_scope_1 = require("./constraints/employee-scope");
|
|
34
|
+
const support_1 = require("./constraints/support");
|
|
33
35
|
const min_rest_1 = require("./constraints/min-rest");
|
|
34
36
|
const overtime_1 = require("./constraints/overtime");
|
|
37
|
+
const qualification_1 = require("./constraints/qualification");
|
|
35
38
|
const contract_hours_1 = require("./contract-hours");
|
|
36
39
|
const sites_1 = require("./sites");
|
|
37
40
|
const time_1 = require("./time");
|
|
38
41
|
Object.defineProperty(exports, "MINUTES_PER_DAY", { enumerable: true, get: function () { return time_1.MINUTES_PER_DAY; } });
|
|
42
|
+
var preferences_2 = require("./preferences");
|
|
43
|
+
Object.defineProperty(exports, "availabilityApplies", { enumerable: true, get: function () { return preferences_2.availabilityApplies; } });
|
|
39
44
|
var time_2 = require("./time");
|
|
40
45
|
Object.defineProperty(exports, "daysBetween", { enumerable: true, get: function () { return time_2.daysBetween; } });
|
|
41
46
|
Object.defineProperty(exports, "addDays", { enumerable: true, get: function () { return time_2.addDays; } });
|
|
@@ -59,7 +64,14 @@ function expandShiftInstances(input) {
|
|
|
59
64
|
const publicHolidays = new Set(input.calendar?.publicHolidays ?? []);
|
|
60
65
|
for (const date of publicHolidays)
|
|
61
66
|
(0, time_1.assertIsoDate)(date, 'calendar.publicHolidays');
|
|
62
|
-
|
|
67
|
+
// The same site reading the solve does. Without it this path answered a
|
|
68
|
+
// different `isPublicHoliday` from `buildModel` for the very same input —
|
|
69
|
+
// the second reading path the module's own rules forbid — and skipped the
|
|
70
|
+
// site validation that refuses a mixed-zone roster.
|
|
71
|
+
const siteIndex = (0, sites_1.buildSiteIndex)(input.sites, input.travelSpeedKmh, input.period.timeZone);
|
|
72
|
+
void siteIndex;
|
|
73
|
+
const holidaysBySite = siteHolidayCalendars(input.sites);
|
|
74
|
+
const context = { nightRule: input.rules?.nightWork, publicHolidays, holidaysBySite };
|
|
63
75
|
const instances = [];
|
|
64
76
|
const seen = new Set();
|
|
65
77
|
for (const template of input.shifts) {
|
|
@@ -74,6 +86,33 @@ function expandShiftInstances(input) {
|
|
|
74
86
|
}
|
|
75
87
|
exports.expandShiftInstances = expandShiftInstances;
|
|
76
88
|
/** Expand one template into its dated instances inside the period. */
|
|
89
|
+
/**
|
|
90
|
+
* Per-site holiday calendars, keyed by site.
|
|
91
|
+
*
|
|
92
|
+
* A site that declares its own list replaces the roster's for its shifts; one
|
|
93
|
+
* that declares none inherits it, and a present-but-empty list means the site
|
|
94
|
+
* observes none. One builder because `expandShiftInstances` and `buildModel`
|
|
95
|
+
* both need it and answering differently is the failure the module's own rules
|
|
96
|
+
* name.
|
|
97
|
+
*/
|
|
98
|
+
function siteHolidayCalendars(sites) {
|
|
99
|
+
const out = new Map();
|
|
100
|
+
for (const site of sites ?? []) {
|
|
101
|
+
if (site.publicHolidays !== undefined)
|
|
102
|
+
out.set(site.id, new Set(site.publicHolidays));
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Which holiday calendar applies to a shift: the hosting site's own list where
|
|
108
|
+
* it declares one, otherwise the roster's. Holidays follow the place the work
|
|
109
|
+
* happens, so a shift with no site can only mean the roster calendar.
|
|
110
|
+
*/
|
|
111
|
+
function holidaysFor(siteId, context) {
|
|
112
|
+
if (siteId === undefined)
|
|
113
|
+
return context.publicHolidays;
|
|
114
|
+
return context.holidaysBySite?.get(siteId) ?? context.publicHolidays;
|
|
115
|
+
}
|
|
77
116
|
function expandTemplate(template, clock, periodDays, context) {
|
|
78
117
|
if (!template.id)
|
|
79
118
|
throw new types_1.ScheduleValidationError('Shift template is missing `id`');
|
|
@@ -88,6 +127,23 @@ function expandTemplate(template, clock, periodDays, context) {
|
|
|
88
127
|
throw new types_1.ScheduleValidationError(`Shift template "${template.id}" has maxEmployees below minEmployees`);
|
|
89
128
|
}
|
|
90
129
|
const overrides = validateDemandOverrides(template);
|
|
130
|
+
/*
|
|
131
|
+
* Shape checks run once per template, here, rather than per date inside
|
|
132
|
+
* `resolveDemand`.
|
|
133
|
+
*
|
|
134
|
+
* A template whose dates all fall outside the period produces no
|
|
135
|
+
* occurrences at all, so validation that happened per date never ran for it
|
|
136
|
+
* — bad configuration survived one solve and threw on the next, when the
|
|
137
|
+
* period moved over it.
|
|
138
|
+
*/
|
|
139
|
+
normalizeTagRequirements(template.tagRequirements, template.id);
|
|
140
|
+
normalizeTagRatios(template.tagRatios, template.id);
|
|
141
|
+
normalizeTagMaximums(template.tagMaximums, template.id);
|
|
142
|
+
for (const override of overrides) {
|
|
143
|
+
normalizeTagRequirements(override.tagRequirements, template.id);
|
|
144
|
+
normalizeTagRatios(override.tagRatios, template.id);
|
|
145
|
+
normalizeTagMaximums(override.tagMaximums, template.id);
|
|
146
|
+
}
|
|
91
147
|
const startTod = (0, time_1.parseTimeOfDay)(template.startTime, `shift "${template.id}".startTime`);
|
|
92
148
|
const endTodRaw = (0, time_1.parseTimeOfDay)(template.endTime, `shift "${template.id}".endTime`);
|
|
93
149
|
// Overnight shifts roll the end into the next day explicitly; a same-time
|
|
@@ -168,6 +224,7 @@ function expandTemplate(template, clock, periodDays, context) {
|
|
|
168
224
|
minEmployees: demand.minEmployees,
|
|
169
225
|
maxEmployees: demand.maxEmployees,
|
|
170
226
|
tagRequirements: demand.tagRequirements,
|
|
227
|
+
tagRatios: demand.tagRatios,
|
|
171
228
|
tagMaximums: demand.tagMaximums,
|
|
172
229
|
requiredTags: demand.requiredTags,
|
|
173
230
|
shiftTypeTag: template.shiftTypeTag,
|
|
@@ -177,7 +234,7 @@ function expandTemplate(template, clock, periodDays, context) {
|
|
|
177
234
|
isNightShift: nightMinutes >= nightThreshold,
|
|
178
235
|
weekday: (0, time_1.isoWeekday)(date),
|
|
179
236
|
isSunday: (0, time_1.isoWeekday)(date) === 7,
|
|
180
|
-
isPublicHoliday: context.
|
|
237
|
+
isPublicHoliday: holidaysFor(template.siteId, context).has(date),
|
|
181
238
|
};
|
|
182
239
|
if (demand.label !== undefined)
|
|
183
240
|
instance.demandLabel = demand.label;
|
|
@@ -226,6 +283,105 @@ function validateDemandOverrides(template) {
|
|
|
226
283
|
* peak" plainly means three. Only a maximum the override itself states is held
|
|
227
284
|
* against the resolved minimum — that combination is a shape nobody can staff.
|
|
228
285
|
*/
|
|
286
|
+
/**
|
|
287
|
+
* Days of the period this contract is in force.
|
|
288
|
+
*
|
|
289
|
+
* Both bounds inclusive, clipped to the period, and zero when they do not
|
|
290
|
+
* overlap it at all — somebody whose contract ended in February is owed nothing
|
|
291
|
+
* in March rather than a full month they were not employed for.
|
|
292
|
+
*
|
|
293
|
+
* Arithmetic only: `validateContractDates` runs for every employee, including
|
|
294
|
+
* the ones this is never called for.
|
|
295
|
+
*/
|
|
296
|
+
/**
|
|
297
|
+
* The contract fields that change a roster whether or not a contracted week
|
|
298
|
+
* resolves.
|
|
299
|
+
*
|
|
300
|
+
* Separate from `daysInForce` because that runs only for employees whose
|
|
301
|
+
* weekly minutes resolve — and `contractLimits` string-compares these dates for
|
|
302
|
+
* *everybody*. An unpadded `2026-3-2` sorts after `2026-03-02`, so it pruned
|
|
303
|
+
* every instance and produced an empty roster with no error; a negative
|
|
304
|
+
* opening balance silently lifted a rolling cap. Both were validated for a
|
|
305
|
+
* full-timer and waved through for anybody else.
|
|
306
|
+
*/
|
|
307
|
+
function validateContractDates(employee) {
|
|
308
|
+
const contract = employee.contract;
|
|
309
|
+
if (!contract)
|
|
310
|
+
return;
|
|
311
|
+
if (contract.startDate)
|
|
312
|
+
(0, time_1.assertIsoDate)(contract.startDate, `employee "${employee.id}".contract.startDate`);
|
|
313
|
+
if (contract.endDate)
|
|
314
|
+
(0, time_1.assertIsoDate)(contract.endDate, `employee "${employee.id}".contract.endDate`);
|
|
315
|
+
if (contract.startDate && contract.endDate && contract.startDate > contract.endDate) {
|
|
316
|
+
throw new types_1.ScheduleValidationError(`Employee "${employee.id}" has a contract starting ${contract.startDate}, after it ends ${contract.endDate}`);
|
|
317
|
+
}
|
|
318
|
+
if (contract.openingBalanceMinutes !== undefined) {
|
|
319
|
+
if (!Number.isFinite(contract.openingBalanceMinutes) || contract.openingBalanceMinutes < 0) {
|
|
320
|
+
throw new types_1.ScheduleValidationError(`Employee "${employee.id}".contract.openingBalanceMinutes must be a non-negative number of minutes`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function daysInForce(employee, periodStart, periodDays) {
|
|
325
|
+
const contract = employee.contract;
|
|
326
|
+
const periodEnd = (0, time_1.addDays)(periodStart, periodDays - 1);
|
|
327
|
+
const from = contract?.startDate && contract.startDate > periodStart ? contract.startDate : periodStart;
|
|
328
|
+
const to = contract?.endDate && contract.endDate < periodEnd ? contract.endDate : periodEnd;
|
|
329
|
+
if (from > to)
|
|
330
|
+
return 0;
|
|
331
|
+
return (0, time_1.daysBetween)(from, to) + 1;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Both shapes of `tagRequirements`, resolved to one.
|
|
335
|
+
*
|
|
336
|
+
* A plain number is a count with no grade floor; the object form carries one.
|
|
337
|
+
* Normalising here means no rule downstream sees a union — the alternative,
|
|
338
|
+
* every counting site widening a `typeof` check, is how one of them ends up
|
|
339
|
+
* reading `{ min: 2 }` as `NaN` and quietly requiring nobody.
|
|
340
|
+
*/
|
|
341
|
+
function normalizeTagRequirements(stated, templateId) {
|
|
342
|
+
const out = {};
|
|
343
|
+
for (const [tag, value] of Object.entries(stated ?? {})) {
|
|
344
|
+
const requirement = typeof value === 'number' ? { min: value } : value;
|
|
345
|
+
if (!Number.isInteger(requirement?.min) || requirement.min < 0) {
|
|
346
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagRequirements["${tag}"] needs a non-negative whole minimum`);
|
|
347
|
+
}
|
|
348
|
+
if (requirement.level !== undefined) {
|
|
349
|
+
if (!Number.isFinite(requirement.level) || requirement.level <= 0) {
|
|
350
|
+
// Zero is refused rather than accepted, because it reads as "no
|
|
351
|
+
// floor" and means the opposite: `holds` skips the plain-tag
|
|
352
|
+
// branch the moment a level is present, so `{ min: 1, level: 0 }`
|
|
353
|
+
// silently excludes everybody whose tag carries no grade. Omit
|
|
354
|
+
// the level to count anybody holding the tag.
|
|
355
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagRequirements["${tag}"].level must be a positive number; ` +
|
|
356
|
+
`omit it to count anybody holding the tag`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
out[tag] = requirement.level === undefined ? { min: requirement.min } : { min: requirement.min, level: requirement.level };
|
|
360
|
+
}
|
|
361
|
+
return out;
|
|
362
|
+
}
|
|
363
|
+
/** Ceilings, checked like the minimums beside them. A negative maximum can never be met. */
|
|
364
|
+
function normalizeTagMaximums(stated, templateId) {
|
|
365
|
+
const out = {};
|
|
366
|
+
for (const [tag, max] of Object.entries(stated ?? {})) {
|
|
367
|
+
if (!Number.isInteger(max) || max < 0) {
|
|
368
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagMaximums["${tag}"] needs a non-negative whole maximum`);
|
|
369
|
+
}
|
|
370
|
+
out[tag] = max;
|
|
371
|
+
}
|
|
372
|
+
return out;
|
|
373
|
+
}
|
|
374
|
+
/** Proportions, checked as fractions. A ratio outside 0..1 is not a proportion of anything. */
|
|
375
|
+
function normalizeTagRatios(stated, templateId) {
|
|
376
|
+
const out = {};
|
|
377
|
+
for (const [tag, ratio] of Object.entries(stated ?? {})) {
|
|
378
|
+
if (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio < 0 || ratio > 1) {
|
|
379
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagRatios["${tag}"] must be a fraction between 0 and 1`);
|
|
380
|
+
}
|
|
381
|
+
out[tag] = ratio;
|
|
382
|
+
}
|
|
383
|
+
return out;
|
|
384
|
+
}
|
|
229
385
|
function resolveDemand(template, overrides, date, onPattern) {
|
|
230
386
|
let min = template.minEmployees ?? 1;
|
|
231
387
|
let max = template.maxEmployees;
|
|
@@ -235,8 +391,9 @@ function resolveDemand(template, overrides, date, onPattern) {
|
|
|
235
391
|
const demand = {
|
|
236
392
|
minEmployees: min,
|
|
237
393
|
maxEmployees: max,
|
|
238
|
-
tagRequirements: template.tagRequirements
|
|
239
|
-
|
|
394
|
+
tagRequirements: normalizeTagRequirements(template.tagRequirements, template.id),
|
|
395
|
+
tagRatios: normalizeTagRatios(template.tagRatios, template.id),
|
|
396
|
+
tagMaximums: normalizeTagMaximums(template.tagMaximums, template.id),
|
|
240
397
|
requiredTags: template.requiredTags ?? [],
|
|
241
398
|
};
|
|
242
399
|
const weekday = (0, time_1.isoWeekday)(date);
|
|
@@ -260,10 +417,14 @@ function resolveDemand(template, overrides, date, onPattern) {
|
|
|
260
417
|
}
|
|
261
418
|
if (override.extraEmployees !== undefined)
|
|
262
419
|
extra += override.extraEmployees;
|
|
263
|
-
if (override.tagRequirements !== undefined)
|
|
264
|
-
demand.tagRequirements = override.tagRequirements;
|
|
265
|
-
|
|
266
|
-
|
|
420
|
+
if (override.tagRequirements !== undefined) {
|
|
421
|
+
demand.tagRequirements = normalizeTagRequirements(override.tagRequirements, template.id);
|
|
422
|
+
}
|
|
423
|
+
if (override.tagRatios !== undefined)
|
|
424
|
+
demand.tagRatios = normalizeTagRatios(override.tagRatios, template.id);
|
|
425
|
+
if (override.tagMaximums !== undefined) {
|
|
426
|
+
demand.tagMaximums = normalizeTagMaximums(override.tagMaximums, template.id);
|
|
427
|
+
}
|
|
267
428
|
if (override.requiredTags !== undefined)
|
|
268
429
|
demand.requiredTags = override.requiredTags;
|
|
269
430
|
if (override.runs !== undefined)
|
|
@@ -346,6 +507,7 @@ function spanToMinutes(from, to, clock, field) {
|
|
|
346
507
|
function validateEmployee(employee) {
|
|
347
508
|
if (!employee.id)
|
|
348
509
|
throw new types_1.ScheduleValidationError('Employee is missing `id`');
|
|
510
|
+
validateContractDates(employee);
|
|
349
511
|
for (const [field, value] of [
|
|
350
512
|
['maxHoursForPeriod', employee.maxHoursForPeriod],
|
|
351
513
|
['minHoursForPeriod', employee.minHoursForPeriod],
|
|
@@ -364,6 +526,26 @@ function validateEmployee(employee) {
|
|
|
364
526
|
(0, time_1.assertIsoDate)(rule.fromDate, `employee "${employee.id}" availability.fromDate`);
|
|
365
527
|
if (rule.toDate !== undefined)
|
|
366
528
|
(0, time_1.assertIsoDate)(rule.toDate, `employee "${employee.id}" availability.toDate`);
|
|
529
|
+
if (rule.weight !== undefined && !Number.isFinite(rule.weight)) {
|
|
530
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.weight must be a finite number`);
|
|
531
|
+
}
|
|
532
|
+
if (rule.shiftTypeTags !== undefined &&
|
|
533
|
+
(!Array.isArray(rule.shiftTypeTags) || rule.shiftTypeTags.some((t) => typeof t !== 'string' || !t))) {
|
|
534
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.shiftTypeTags must be non-empty strings`);
|
|
535
|
+
}
|
|
536
|
+
// An empty list matches no shift type, so on an `available` rule it
|
|
537
|
+
// would silently make the person unrosterable. Omit the field instead.
|
|
538
|
+
if (rule.shiftTypeTags?.length === 0) {
|
|
539
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.shiftTypeTags must list at least one shift type (omit it to match every shift)`);
|
|
540
|
+
}
|
|
541
|
+
if (rule.priority !== undefined) {
|
|
542
|
+
if (rule.priority !== 'normal' && rule.priority !== 'important') {
|
|
543
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.priority must be normal or important`);
|
|
544
|
+
}
|
|
545
|
+
if (rule.kind !== 'preferred' && rule.kind !== 'avoid') {
|
|
546
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.priority applies only to preferred and avoid rules`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
367
549
|
}
|
|
368
550
|
for (const q of employee.qualifications ?? []) {
|
|
369
551
|
if (q.validFrom !== undefined)
|
|
@@ -431,6 +613,8 @@ function resolveConstraints(options, rules, objectives, employeeRules) {
|
|
|
431
613
|
if (o.weight !== undefined)
|
|
432
614
|
c.weight = o.weight;
|
|
433
615
|
}
|
|
616
|
+
for (const c of constraints)
|
|
617
|
+
support_1.builtInConstraints.add(c);
|
|
434
618
|
return [...constraints, ...(options?.custom ?? [])];
|
|
435
619
|
}
|
|
436
620
|
exports.resolveConstraints = resolveConstraints;
|
|
@@ -480,14 +664,19 @@ function buildModel(input) {
|
|
|
480
664
|
throw new types_1.ScheduleValidationError('period.endDate must not precede period.startDate');
|
|
481
665
|
const clock = new time_1.PeriodClock(input.period.startDate, periodDays, input.period.timeZone ?? 'UTC');
|
|
482
666
|
const rules = input.rules ?? {};
|
|
483
|
-
const siteIndex = (0, sites_1.buildSiteIndex)(input.sites, input.travelSpeedKmh);
|
|
667
|
+
const siteIndex = (0, sites_1.buildSiteIndex)(input.sites, input.travelSpeedKmh, input.period.timeZone);
|
|
484
668
|
const publicHolidays = new Set(input.calendar?.publicHolidays ?? []);
|
|
485
669
|
for (const date of publicHolidays)
|
|
486
670
|
(0, time_1.assertIsoDate)(date, 'calendar.publicHolidays');
|
|
671
|
+
const holidaysBySite = siteHolidayCalendars(input.sites);
|
|
487
672
|
const instances = [];
|
|
488
673
|
const instanceById = new Map();
|
|
489
674
|
for (const template of input.shifts) {
|
|
490
|
-
for (const inst of expandTemplate(template, clock, periodDays, {
|
|
675
|
+
for (const inst of expandTemplate(template, clock, periodDays, {
|
|
676
|
+
nightRule: rules.nightWork,
|
|
677
|
+
publicHolidays,
|
|
678
|
+
holidaysBySite,
|
|
679
|
+
})) {
|
|
491
680
|
if (instanceById.has(inst.id))
|
|
492
681
|
throw new types_1.ScheduleValidationError(`Duplicate shift instance id "${inst.id}"`);
|
|
493
682
|
instanceById.set(inst.id, inst);
|
|
@@ -516,6 +705,35 @@ function buildModel(input) {
|
|
|
516
705
|
personIdOf.set(employee.id, personId);
|
|
517
706
|
employeesOfPerson.set(personId, [...(employeesOfPerson.get(personId) ?? []), employee.id]);
|
|
518
707
|
}
|
|
708
|
+
// Tag possession is a question about the shift's date, so per-tag minimums
|
|
709
|
+
// and maximums must resolve it the same way `requiredTags` does. Plain tags
|
|
710
|
+
// short-circuit; only a dated qualification needs the scan. The cache keeps
|
|
711
|
+
// the search loop's repeated lookups off that scan — the model is immutable
|
|
712
|
+
// once built, so a memo can never go stale.
|
|
713
|
+
const tagOnCache = new Map();
|
|
714
|
+
/**
|
|
715
|
+
* The graded question. Deliberately not cached: a level floor makes the key
|
|
716
|
+
* space four-dimensional, and graded requirements are rare enough that the
|
|
717
|
+
* scan costs less than the memo would.
|
|
718
|
+
*/
|
|
719
|
+
const holdsTagAt = (employeeId, tag, date, minLevel) => {
|
|
720
|
+
const employee = employeeById.get(employeeId);
|
|
721
|
+
return employee ? (0, qualification_1.holds)(employee, tag, date, minLevel) : false;
|
|
722
|
+
};
|
|
723
|
+
const holdsTagOn = (employeeId, tag, date) => {
|
|
724
|
+
if (employeeTags.get(employeeId)?.has(tag))
|
|
725
|
+
return true;
|
|
726
|
+
const employee = employeeById.get(employeeId);
|
|
727
|
+
if (!employee?.qualifications?.length)
|
|
728
|
+
return false;
|
|
729
|
+
const key = `${employeeId}\0${tag}\0${date}`;
|
|
730
|
+
const cached = tagOnCache.get(key);
|
|
731
|
+
if (cached !== undefined)
|
|
732
|
+
return cached;
|
|
733
|
+
const result = (0, qualification_1.holds)(employee, tag, date);
|
|
734
|
+
tagOnCache.set(key, result);
|
|
735
|
+
return result;
|
|
736
|
+
};
|
|
519
737
|
// The contracted week resolves exactly once, against the rules that apply
|
|
520
738
|
// to the person (a per-person override may carry its own full-time week),
|
|
521
739
|
// and every rule reads the resolved figure from the context.
|
|
@@ -526,7 +744,11 @@ function buildModel(input) {
|
|
|
526
744
|
if (weekly === undefined)
|
|
527
745
|
continue;
|
|
528
746
|
contractedWeeklyMinutes.set(employee.id, weekly);
|
|
529
|
-
|
|
747
|
+
// Days the contract is actually in force inside the period, not the
|
|
748
|
+
// period's own length: somebody who joins on day fifteen is owed a
|
|
749
|
+
// fortnight, and planning them a full month is what made the
|
|
750
|
+
// contract-hours objective load a new starter past everybody else.
|
|
751
|
+
contractedPeriod.set(employee.id, (0, contract_hours_1.contractedPeriodMinutes)(weekly, daysInForce(employee, input.period.startDate, periodDays)));
|
|
530
752
|
}
|
|
531
753
|
const contractHoursWeight = input.objectives?.contractHoursWeight ?? contract_hours_1.DEFAULT_CONTRACT_HOURS_WEIGHT;
|
|
532
754
|
if (!Number.isFinite(contractHoursWeight) || contractHoursWeight < 0) {
|
|
@@ -562,12 +784,16 @@ function buildModel(input) {
|
|
|
562
784
|
? undefined
|
|
563
785
|
: clock.parseDateTime(input.published.publishedAt, 'published.publishedAt');
|
|
564
786
|
const asOfMinute = input.asOf === undefined ? undefined : clock.parseDateTime(input.asOf, 'asOf');
|
|
787
|
+
(0, preferences_1.validatePreferenceObjectives)(input.objectives?.preferences);
|
|
788
|
+
const preferenceRules = (0, preferences_1.resolvePreferenceRules)(input.employees, instances, clock, input.objectives?.preferences);
|
|
565
789
|
return {
|
|
566
790
|
periodStartDate: input.period.startDate,
|
|
567
791
|
periodDays,
|
|
568
792
|
employees: input.employees,
|
|
569
793
|
employeeById,
|
|
570
794
|
employeeTags,
|
|
795
|
+
holdsTagOn,
|
|
796
|
+
holdsTagAt,
|
|
571
797
|
instances,
|
|
572
798
|
instanceById,
|
|
573
799
|
siteIndex,
|
|
@@ -582,6 +808,7 @@ function buildModel(input) {
|
|
|
582
808
|
contractedPeriodMinutes: contractedPeriod,
|
|
583
809
|
contractHoursWeight,
|
|
584
810
|
fillToContract,
|
|
811
|
+
preferenceRules,
|
|
585
812
|
personIdOf,
|
|
586
813
|
employeesOfPerson,
|
|
587
814
|
history: buildHistory(input.history, clock, personIdOf),
|
|
@@ -594,14 +821,3 @@ function buildModel(input) {
|
|
|
594
821
|
};
|
|
595
822
|
}
|
|
596
823
|
exports.buildModel = buildModel;
|
|
597
|
-
/** Whether an availability rule applies to a shift instance. */
|
|
598
|
-
function availabilityApplies(rule, inst) {
|
|
599
|
-
if (rule.daysOfWeek && !rule.daysOfWeek.includes(inst.weekday))
|
|
600
|
-
return false;
|
|
601
|
-
if (rule.fromDate && inst.date < rule.fromDate)
|
|
602
|
-
return false;
|
|
603
|
-
if (rule.toDate && inst.date > rule.toDate)
|
|
604
|
-
return false;
|
|
605
|
-
return true;
|
|
606
|
-
}
|
|
607
|
-
exports.availabilityApplies = availabilityApplies;
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* - `diagnoseInfeasibility` — why the problem cannot be solved, before it is
|
|
18
18
|
* attempted.
|
|
19
19
|
*/
|
|
20
|
-
import type { AssignmentPair, ConstraintViolation, LedgerEntry, RuleVerdict, ScheduleInput, ScheduledAssignment, ContractHoursSummary } from './types';
|
|
20
|
+
import type { AssignmentPair, ConstraintViolation, LedgerEntry, RuleVerdict, ScheduleInput, ScheduledAssignment, ContractHoursSummary, EmployeePreferenceReport } from './types';
|
|
21
|
+
import { type ShiftResilience } from './resilience';
|
|
21
22
|
export interface ComplianceReport {
|
|
22
23
|
compliant: boolean;
|
|
23
24
|
/** Whether all headcount and skill coverage requirements are met. */
|
|
@@ -39,6 +40,8 @@ export interface ComplianceReport {
|
|
|
39
40
|
ledger: LedgerEntry[];
|
|
40
41
|
/** Planned against contracted hours — the same summary the solver reports for the same assignments. */
|
|
41
42
|
contractHours: ContractHoursSummary[];
|
|
43
|
+
/** How each stated preference fared — the same report the solver attaches. */
|
|
44
|
+
preferences: EmployeePreferenceReport[];
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Validate an externally-produced or hand-edited roster.
|
|
@@ -97,6 +100,12 @@ export interface RepairCandidate {
|
|
|
97
100
|
distanceKm?: number;
|
|
98
101
|
/** Whether the shift is at this employee's home site. */
|
|
99
102
|
isHomeSite: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Which of the shift's `tagRequirements` this person holds on its date, at
|
|
105
|
+
* the level asked for — so a list of people can answer "who here is a
|
|
106
|
+
* first-aider". Declared qualifications only; empty when they hold none.
|
|
107
|
+
*/
|
|
108
|
+
tagsHeld: string[];
|
|
100
109
|
}
|
|
101
110
|
export interface RepairResult {
|
|
102
111
|
diff: {
|
|
@@ -138,15 +147,178 @@ export declare function repairSchedule(input: ScheduleInput, disruption: Disrupt
|
|
|
138
147
|
* Annex III point 4(b), which is high-risk with no narrow-task exemption.
|
|
139
148
|
*/
|
|
140
149
|
export declare function rankCandidates(input: ScheduleInput, shiftInstanceId: string, roster: ScheduledAssignment[], disruption?: Disruption): RepairCandidate[];
|
|
150
|
+
/**
|
|
151
|
+
* One person against many shifts: `rankCandidates` turned on its side.
|
|
152
|
+
*
|
|
153
|
+
* The question a worker's phone asks of a list of open shifts is "which of
|
|
154
|
+
* these could *I* take?" Answering it with `rankCandidates` per shift built the
|
|
155
|
+
* model and scored the whole team once per posting, to read one row of each.
|
|
156
|
+
* This builds the model once and scores only that person — through the same
|
|
157
|
+
* `scoreCandidates` judgement, so each answer is exactly the row the
|
|
158
|
+
* team-wide ranking gives them (a candidate is scored independently of the
|
|
159
|
+
* others, so leaving the others out changes nothing about theirs).
|
|
160
|
+
*
|
|
161
|
+
* Returns candidates in the order `shiftInstanceIds` names them, leaving out
|
|
162
|
+
* ids that name no shift and shifts the person already holds — the same
|
|
163
|
+
* people `rankCandidates` leaves out. An unknown employee gets `[]`.
|
|
164
|
+
*/
|
|
165
|
+
export declare function rankShiftsFor(input: ScheduleInput, employeeId: string, shiftInstanceIds: string[], roster: ScheduledAssignment[]): RepairCandidate[];
|
|
166
|
+
export interface ResilienceOptions {
|
|
167
|
+
/** Only these instances; default every instance in the period. */
|
|
168
|
+
shiftInstanceIds?: string[];
|
|
169
|
+
/** Expected dropouts per instance (headcount × absence rate); default 0. */
|
|
170
|
+
expectedDropouts?: Record<string, number>;
|
|
171
|
+
/** How many ranked backups to return per shift; default 5. */
|
|
172
|
+
topBackups?: number;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The capacity radar's question for every shift in a window: is it short, and
|
|
176
|
+
* who could legally step in if someone drops out?
|
|
177
|
+
*
|
|
178
|
+
* One model build and one working state serve the whole window, as in
|
|
179
|
+
* `rankShiftsFor`. Backups come from `scoreCandidates` — the judgement
|
|
180
|
+
* `rankCandidates` and `rankSwapPartners` use — so the radar and a cover offer
|
|
181
|
+
* can never disagree about who could take a shift.
|
|
182
|
+
*
|
|
183
|
+
* A rostered person the time-off rule refuses on the shift (declared time off,
|
|
184
|
+
* an `absences` span or an external commitment) is reported in `absent`, not
|
|
185
|
+
* counted in `assigned`, and is taken off the working state *before* anyone is
|
|
186
|
+
* judged: they are genuinely off, so they hold no seat on a capped shift and
|
|
187
|
+
* their hours count against nobody. The state is local to the call.
|
|
188
|
+
*
|
|
189
|
+
* Backups are judged with one seat vacated where a crew cap binds (see
|
|
190
|
+
* `backupsFor`): a backup replaces a dropout, and a full shift asked with
|
|
191
|
+
* everyone still on it has room for nobody. `assigned` and `shortBy` are
|
|
192
|
+
* always the real roster.
|
|
193
|
+
*
|
|
194
|
+
* `need` is the folded `minEmployees`: a caller raises it with a
|
|
195
|
+
* `demandOverrides` entry on the input, never through an option here.
|
|
196
|
+
*
|
|
197
|
+
* Profiling-free: declared facts (roster, time off, qualifications, rules) and
|
|
198
|
+
* the caller's aggregate expected-dropout number — nothing behavioural.
|
|
199
|
+
*/
|
|
200
|
+
export declare function assessShiftResilience(input: ScheduleInput, roster: ScheduledAssignment[], options?: ResilienceOptions): ShiftResilience[];
|
|
201
|
+
/** One of a partner's shifts the proposer could take in return. */
|
|
202
|
+
export interface SwapTrade {
|
|
203
|
+
shiftInstanceId: string;
|
|
204
|
+
}
|
|
205
|
+
/** A colleague who could take a shift, and — when asked — what they could give back. */
|
|
206
|
+
export interface SwapPartner extends RepairCandidate {
|
|
207
|
+
/**
|
|
208
|
+
* The partner's own shifts that make a lawful trade: the partner may work
|
|
209
|
+
* the proposer's shift **and** the proposer may work this one, with both of
|
|
210
|
+
* them off the shift they are giving up. Present only when requested.
|
|
211
|
+
*/
|
|
212
|
+
trades?: SwapTrade[];
|
|
213
|
+
}
|
|
214
|
+
export interface SwapPartnerOptions {
|
|
215
|
+
/** Also work out which of each partner's shifts would make a lawful trade. */
|
|
216
|
+
trades?: boolean;
|
|
217
|
+
/** Only offer trades dated on or after this ISO date — typically today. */
|
|
218
|
+
tradesFrom?: string;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Who could take a shift off the person holding it, and what they could swap.
|
|
222
|
+
*
|
|
223
|
+
* `rankCandidates` answers "who can fill this gap?" — a gap nobody is in. A
|
|
224
|
+
* hand-over is asked about a shift somebody *is* in, so the proposer is taken
|
|
225
|
+
* off it first; asked with them still on it, a full shift reads "no room" for
|
|
226
|
+
* everybody.
|
|
227
|
+
*
|
|
228
|
+
* A trade is judged with **both** people off the shift they are giving up,
|
|
229
|
+
* in both directions, on one model build. Rules that span a whole shift or
|
|
230
|
+
* period (tag counts and ratios, aggregates) are not judged here: the host
|
|
231
|
+
* re-checks the full roster before applying, and this list is the prefilter
|
|
232
|
+
* that keeps a worker from asking a question whose answer is always no.
|
|
233
|
+
*
|
|
234
|
+
* Ordering is `rankCandidates`' own, so it stays inside the same
|
|
235
|
+
* profiling-free boundary.
|
|
236
|
+
*/
|
|
237
|
+
export declare function rankSwapPartners(input: ScheduleInput, shiftInstanceId: string, fromEmployeeId: string, roster: ScheduledAssignment[], options?: SwapPartnerOptions): SwapPartner[];
|
|
238
|
+
/** Whether one proposed swap is lawful for both people, and who it is not lawful for. */
|
|
239
|
+
export interface SwapCheck {
|
|
240
|
+
fits: boolean;
|
|
241
|
+
/** Failing hard rules, each naming the person it applies to. */
|
|
242
|
+
blockers: Array<RuleVerdict & {
|
|
243
|
+
employeeId: string;
|
|
244
|
+
}>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Judge one proposed hand-over or trade, the same way `rankSwapPartners`
|
|
248
|
+
* judges each entry on its list.
|
|
249
|
+
*
|
|
250
|
+
* `toShiftInstanceId` null is a give-away. Either person not holding the shift
|
|
251
|
+
* named is an `input` blocker rather than a pass: a trade of shifts neither
|
|
252
|
+
* holds is not a trade.
|
|
253
|
+
*/
|
|
254
|
+
export declare function checkSwap(input: ScheduleInput, swap: {
|
|
255
|
+
fromEmployeeId: string;
|
|
256
|
+
fromShiftInstanceId: string;
|
|
257
|
+
toEmployeeId: string;
|
|
258
|
+
toShiftInstanceId: string | null;
|
|
259
|
+
}, roster: ScheduledAssignment[]): SwapCheck;
|
|
141
260
|
export interface InfeasibilityReport {
|
|
142
261
|
feasible: boolean;
|
|
143
262
|
findings: Array<{
|
|
144
|
-
kind: 'noEligibleEmployee' | 'insufficientCapacity' | 'tagCapacity';
|
|
263
|
+
kind: 'noEligibleEmployee' | 'noLawfulEmployee' | 'insufficientCapacity' | 'tagCapacity';
|
|
145
264
|
message: string;
|
|
146
265
|
shiftInstanceId?: string;
|
|
147
266
|
tag?: string;
|
|
148
267
|
shortfall?: number;
|
|
268
|
+
/**
|
|
269
|
+
* `noLawfulEmployee` only: why each person who could otherwise work the
|
|
270
|
+
* shift may not, by rule — most people first — with one of their
|
|
271
|
+
* verdicts as the example. A shift that breaks a rule on its own (a
|
|
272
|
+
* night the clocks go back in, 9 real hours against an 8-hour cap)
|
|
273
|
+
* names that rule for everybody.
|
|
274
|
+
*/
|
|
275
|
+
blockers?: Array<{
|
|
276
|
+
ruleId: string;
|
|
277
|
+
employees: number;
|
|
278
|
+
message: string;
|
|
279
|
+
actual?: number;
|
|
280
|
+
required?: number;
|
|
281
|
+
unit?: RuleVerdict['unit'];
|
|
282
|
+
}>;
|
|
283
|
+
/** `noLawfulEmployee` only: the occurrence's real length and working time, in minutes. */
|
|
284
|
+
durationMinutes?: number;
|
|
285
|
+
workingMinutes?: number;
|
|
286
|
+
}>;
|
|
287
|
+
/**
|
|
288
|
+
* Per skill the roster asks for: demand against the people who hold it,
|
|
289
|
+
* day by day. Informational — it never makes a report infeasible on its
|
|
290
|
+
* own, because a short day is a warning a planner can act on, not proof
|
|
291
|
+
* that no roster exists.
|
|
292
|
+
*/
|
|
293
|
+
tagCover: TagCover[];
|
|
294
|
+
}
|
|
295
|
+
/** One skill's demand against its holders over the period. */
|
|
296
|
+
export interface TagCover {
|
|
297
|
+
tag: string;
|
|
298
|
+
/**
|
|
299
|
+
* `'mix'` — some of the people on a shift must hold it (`tagRequirements`,
|
|
300
|
+
* `tagRatios`); `'everyone'` — every person on it must (`requiredTags`).
|
|
301
|
+
* A tag asked both ways reads as `'everyone'`, the stricter of the two.
|
|
302
|
+
*/
|
|
303
|
+
kind: 'mix' | 'everyone';
|
|
304
|
+
/** Shift occurrences asking for it. */
|
|
305
|
+
shifts: number;
|
|
306
|
+
/** People-shifts it asks for: the sum of each occurrence's count. */
|
|
307
|
+
seats: number;
|
|
308
|
+
/** People holding it on at least one day it is wanted. */
|
|
309
|
+
holders: number;
|
|
310
|
+
/**
|
|
311
|
+
* Days it asks for more holders than are free: holding it that day, not
|
|
312
|
+
* on time off, inside their contract. One person counts once per day, so
|
|
313
|
+
* an early and a late both wanting a key-holder need two.
|
|
314
|
+
*/
|
|
315
|
+
shortDates: Array<{
|
|
316
|
+
date: string;
|
|
317
|
+
needed: number;
|
|
318
|
+
available: number;
|
|
149
319
|
}>;
|
|
320
|
+
/** Days with exactly as many free holders as it asks for: one absence from short. */
|
|
321
|
+
tightDates: string[];
|
|
150
322
|
}
|
|
151
323
|
/**
|
|
152
324
|
* Why the problem cannot be solved, before spending a search budget on it.
|
|
@@ -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,
|
|
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,EACpB,wBAAwB,EAC3B,MAAM,SAAS,CAAC;AA0BjB,OAAO,EAAkB,KAAK,eAAe,EAAwB,MAAM,cAAc,CAAC;AAW1F,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;IACtC,8EAA8E;IAC9E,WAAW,EAAE,w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