assignment-user-matcher 1.15.1 → 1.16.1
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 +372 -8
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/learning/atomic-ingestion.d.ts +11 -0
- package/dist/learning/atomic-ingestion.d.ts.map +1 -0
- package/dist/learning/atomic-ingestion.js +187 -0
- package/dist/learning/auto-weights.d.ts +13 -2
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +203 -35
- package/dist/learning/features.d.ts +5 -3
- package/dist/learning/features.d.ts.map +1 -1
- package/dist/learning/features.js +105 -4
- package/dist/learning/policy.d.ts +57 -0
- package/dist/learning/policy.d.ts.map +1 -0
- package/dist/learning/policy.js +71 -0
- package/dist/managers/LearningManager.d.ts +312 -35
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +1006 -168
- package/dist/matcher.class.d.ts +98 -11
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +247 -40
- 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/cost.d.ts.map +1 -1
- package/dist/scheduling/constraints/cost.js +3 -2
- package/dist/scheduling/constraints/employee-scope.d.ts +5 -0
- package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -0
- package/dist/scheduling/constraints/employee-scope.js +157 -0
- 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/notice.d.ts.map +1 -1
- package/dist/scheduling/constraints/notice.js +8 -5
- package/dist/scheduling/constraints/rest-days.d.ts.map +1 -1
- package/dist/scheduling/constraints/rest-days.js +6 -6
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -1
- package/dist/scheduling/constraints/rolling-hours.js +29 -4
- package/dist/scheduling/cost.d.ts.map +1 -1
- package/dist/scheduling/cost.js +2 -1
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +23 -3
- package/dist/scheduling/engine/objective.d.ts +4 -4
- package/dist/scheduling/engine/objective.d.ts.map +1 -1
- package/dist/scheduling/engine/objective.js +32 -7
- package/dist/scheduling/engine/propagation.js +2 -1
- package/dist/scheduling/engine/search.d.ts +1 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -1
- package/dist/scheduling/engine/search.js +1 -1
- package/dist/scheduling/engine/state.d.ts.map +1 -1
- package/dist/scheduling/engine/state.js +4 -0
- package/dist/scheduling/engine/timeline.d.ts +14 -0
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +33 -0
- package/dist/scheduling/index.d.ts +1 -1
- package/dist/scheduling/index.d.ts.map +1 -1
- package/dist/scheduling/model.d.ts +7 -2
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +254 -42
- package/dist/scheduling/operations.d.ts +4 -0
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +81 -22
- package/dist/scheduling/provenance.d.ts +1 -1
- package/dist/scheduling/provenance.d.ts.map +1 -1
- package/dist/scheduling/provenance.js +16 -2
- package/dist/scheduling/scheduler.class.d.ts +1 -1
- package/dist/scheduling/scheduler.class.d.ts.map +1 -1
- package/dist/scheduling/scheduler.class.js +5 -3
- 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 +2 -0
- package/dist/scheduling/time.d.ts.map +1 -1
- package/dist/scheduling/time.js +26 -1
- package/dist/scheduling/types.d.ts +152 -9
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/types/matcher.d.ts +309 -4
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/utils/keys.d.ts +12 -2
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +35 -2
- package/package.json +12 -2
|
@@ -148,6 +148,20 @@ export declare class PersonTimeline {
|
|
|
148
148
|
* a day so the caller's clock owns DST, not this structure.
|
|
149
149
|
*/
|
|
150
150
|
longestConsecutiveDays(dayIndexOf: (minute: number) => number): number;
|
|
151
|
+
/**
|
|
152
|
+
* The longest run of consecutive weekends any entry falls in.
|
|
153
|
+
*
|
|
154
|
+
* "Every second weekend off" is the most commonly negotiated scheduling
|
|
155
|
+
* term in Europe and the one shape a *count* cannot express: three weekends
|
|
156
|
+
* each is satisfied exactly as well by three in a row as by alternating
|
|
157
|
+
* ones, and the arrangement is the thing people agreed to.
|
|
158
|
+
*
|
|
159
|
+
* Weekends are keyed by the week they belong to, so a Saturday and the
|
|
160
|
+
* Sunday after it are one weekend rather than two — otherwise working an
|
|
161
|
+
* ordinary weekend would breach "every second", which is the opposite of
|
|
162
|
+
* what it asks. A Sunday belongs to the week whose Saturday preceded it.
|
|
163
|
+
*/
|
|
164
|
+
longestConsecutiveWeekends(weekendKeyOf: (minute: number) => number | null): number;
|
|
151
165
|
/**
|
|
152
166
|
* First index that may overlap a window starting at `windowStart`.
|
|
153
167
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,gDAAgD;AAChD,MAAM,WAAW,aAAc,SAAQ,WAAW;IAC9C,0EAA0E;IAC1E,EAAE,EAAE,MAAM,CAAC;IACX,wFAAwF;IACxF,cAAc,EAAE,MAAM,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|
313
|
+
* The longest run of consecutive weekends any entry falls in.
|
|
314
|
+
*
|
|
315
|
+
* "Every second weekend off" is the most commonly negotiated scheduling
|
|
316
|
+
* term in Europe and the one shape a *count* cannot express: three weekends
|
|
317
|
+
* each is satisfied exactly as well by three in a row as by alternating
|
|
318
|
+
* ones, and the arrangement is the thing people agreed to.
|
|
319
|
+
*
|
|
320
|
+
* Weekends are keyed by the week they belong to, so a Saturday and the
|
|
321
|
+
* Sunday after it are one weekend rather than two — otherwise working an
|
|
322
|
+
* ordinary weekend would breach "every second", which is the opposite of
|
|
323
|
+
* what it asks. A Sunday belongs to the week whose Saturday preceded it.
|
|
324
|
+
*/
|
|
325
|
+
longestConsecutiveWeekends(weekendKeyOf) {
|
|
326
|
+
this.ensureClean();
|
|
327
|
+
const weekends = new Set();
|
|
328
|
+
for (const entry of this.entries) {
|
|
329
|
+
const key = weekendKeyOf(entry.start);
|
|
330
|
+
if (key !== null)
|
|
331
|
+
weekends.add(key);
|
|
332
|
+
}
|
|
333
|
+
const sorted = [...weekends].sort((a, b) => a - b);
|
|
334
|
+
let longest = 0;
|
|
335
|
+
let current = 0;
|
|
336
|
+
let previous;
|
|
337
|
+
for (const weekend of sorted) {
|
|
338
|
+
current = previous !== undefined && weekend === previous + 1 ? current + 1 : 1;
|
|
339
|
+
if (current > longest)
|
|
340
|
+
longest = current;
|
|
341
|
+
previous = weekend;
|
|
342
|
+
}
|
|
343
|
+
return longest;
|
|
344
|
+
}
|
|
312
345
|
/**
|
|
313
346
|
* First index that may overlap a window starting at `windowStart`.
|
|
314
347
|
*
|
|
@@ -8,6 +8,6 @@ export { PeriodClock, type MinuteRange, type ClockRange } from './time';
|
|
|
8
8
|
export { expandShiftInstances } from './model';
|
|
9
9
|
export { hours, days, weeklyAverageOver } from './rules';
|
|
10
10
|
export { DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, } from './contract-hours';
|
|
11
|
-
export type { AssignmentPair, AvailabilityRule, BreakRule, ClockRangeConfig, ConsecutiveRule, ConstraintOptions, ConstraintViolation, ContractHoursRule, ContractHoursSummary, DailyRestRule, DutyClassification, DutyQuota, Employee, EmployeeContract, EmployeeCost, EmployeeProtection, EngagementRule, FairnessRule, HistoricalAssignment, LedgerEntry, ModelContext, NightVolumeQuota, NightWorkRule, NoticeRule, ObjectiveWeights, OvertimeRule, Qualification, RestDayRule, RollingAverage, RuleVerdict, ScheduleInput, ScheduleProvenance, ScheduleResult, ScheduledAssignment, SchedulingConstraint, SearchState, Severity, ShiftInstance, ShiftTemplate, ShiftDemandOverride, Site, SiteIndex, TimeOffEntry, WeeklyRestRule, WorkingTimeLimits, WorkingTimeRules, } from './types';
|
|
11
|
+
export type { AssignmentPair, AvailabilityRule, BreakRule, ClockRangeConfig, ConsecutiveRule, ConstraintOptions, ConstraintViolation, ContractHoursRule, ContractHoursSummary, DailyRestRule, DutyClassification, DutyQuota, Employee, EmployeeContract, EmployeeCost, EmployeeProtection, EngagementRule, FairnessRule, HistoricalAssignment, LedgerEntry, ModelContext, NightVolumeQuota, NightWorkRule, NoticeRule, ObjectiveWeights, OvertimeRule, Qualification, RestDayRule, RollingAverage, RuleVerdict, ScheduleInput, ScheduleProvenance, ScheduleResult, ScheduledAssignment, SchedulingConstraint, SearchState, Severity, ShiftInstance, ShiftTemplate, TagRequirement, ShiftDemandOverride, Site, SiteIndex, TimeOffEntry, WeeklyRestRule, WorkingTimeLimits, WorkingTimeRules, } from './types';
|
|
12
12
|
export type { PersonTimeline, TimelineEntry, TimelineIndex } from './engine/timeline';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scheduling/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,E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c,EACd,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACnB,MAAM,SAAS,CAAC;AAIjB,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -38,10 +38,15 @@ export { daysBetween, addDays } from './time';
|
|
|
38
38
|
* refers to.
|
|
39
39
|
*/
|
|
40
40
|
export declare function expandShiftInstances(input: ScheduleInput): ShiftInstance[];
|
|
41
|
-
/** Expand one template into its dated instances inside the period. */
|
|
42
41
|
export declare function expandTemplate(template: ShiftTemplate, clock: PeriodClock, periodDays: number, context: {
|
|
43
42
|
nightRule?: WorkingTimeRules['nightWork'];
|
|
44
43
|
publicHolidays: Set<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Per-site holiday calendars, replacing the roster calendar for shifts
|
|
46
|
+
* at that site. Present but empty means the site observes none — the
|
|
47
|
+
* distinction an `undefined` entry cannot carry.
|
|
48
|
+
*/
|
|
49
|
+
holidaysBySite?: Map<string, Set<string>>;
|
|
45
50
|
}): ShiftInstance[];
|
|
46
51
|
/**
|
|
47
52
|
* Merge the global rule set with one person's overrides.
|
|
@@ -52,7 +57,7 @@ export declare function expandTemplate(template: ShiftTemplate, clock: PeriodClo
|
|
|
52
57
|
*/
|
|
53
58
|
export declare function mergeRules(base: WorkingTimeRules | undefined, override: WorkingTimeRules | undefined): WorkingTimeRules;
|
|
54
59
|
/** Resolve built-in constraints with caller hardness/weight overrides, then append customs. */
|
|
55
|
-
export declare function resolveConstraints(options: ConstraintOptions | undefined, rules?: WorkingTimeRules, objectives?: ObjectiveWeights): SchedulingConstraint[];
|
|
60
|
+
export declare function resolveConstraints(options: ConstraintOptions | undefined, rules?: WorkingTimeRules, objectives?: ObjectiveWeights, employeeRules?: Map<string, WorkingTimeRules>): SchedulingConstraint[];
|
|
56
61
|
/**
|
|
57
62
|
* Normalize and validate the scheduling problem. Throws
|
|
58
63
|
* `ScheduleValidationError` on malformed input — never a silent wrong schedule.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAER,gBAAgB,EAChB,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,aAAa,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAER,gBAAgB,EAChB,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,aAAa,EAGb,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAUjB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAmE,MAAM,QAAQ,CAAC;AAEvH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,EAAE,CA6B1E;AAiCD,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IACL,SAAS,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC1C,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CAC7C,GACF,aAAa,EAAE,CAmIjB;AA8VD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAAE,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,gBAAgB,CAIvH;AAED,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,KAAK,CAAC,EAAE,gBAAgB,EACxB,UAAU,CAAC,EAAE,gBAAgB,EAC7B,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC9C,oBAAoB,EAAE,CAwBxB;AAiCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAiL7D;AAED,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAKxF;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/scheduling/model.js
CHANGED
|
@@ -29,8 +29,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.MINUTES_PER_DAY = exports.availabilityApplies = exports.buildModel = exports.resolveConstraints = exports.mergeRules = exports.expandTemplate = exports.expandShiftInstances = exports.addDays = exports.daysBetween = void 0;
|
|
30
30
|
const types_1 = require("./types");
|
|
31
31
|
const constraint_1 = require("./constraints/constraint");
|
|
32
|
+
const employee_scope_1 = require("./constraints/employee-scope");
|
|
32
33
|
const min_rest_1 = require("./constraints/min-rest");
|
|
33
34
|
const overtime_1 = require("./constraints/overtime");
|
|
35
|
+
const qualification_1 = require("./constraints/qualification");
|
|
34
36
|
const contract_hours_1 = require("./contract-hours");
|
|
35
37
|
const sites_1 = require("./sites");
|
|
36
38
|
const time_1 = require("./time");
|
|
@@ -58,7 +60,14 @@ function expandShiftInstances(input) {
|
|
|
58
60
|
const publicHolidays = new Set(input.calendar?.publicHolidays ?? []);
|
|
59
61
|
for (const date of publicHolidays)
|
|
60
62
|
(0, time_1.assertIsoDate)(date, 'calendar.publicHolidays');
|
|
61
|
-
|
|
63
|
+
// The same site reading the solve does. Without it this path answered a
|
|
64
|
+
// different `isPublicHoliday` from `buildModel` for the very same input —
|
|
65
|
+
// the second reading path the module's own rules forbid — and skipped the
|
|
66
|
+
// site validation that refuses a mixed-zone roster.
|
|
67
|
+
const siteIndex = (0, sites_1.buildSiteIndex)(input.sites, input.travelSpeedKmh, input.period.timeZone);
|
|
68
|
+
void siteIndex;
|
|
69
|
+
const holidaysBySite = siteHolidayCalendars(input.sites);
|
|
70
|
+
const context = { nightRule: input.rules?.nightWork, publicHolidays, holidaysBySite };
|
|
62
71
|
const instances = [];
|
|
63
72
|
const seen = new Set();
|
|
64
73
|
for (const template of input.shifts) {
|
|
@@ -73,6 +82,33 @@ function expandShiftInstances(input) {
|
|
|
73
82
|
}
|
|
74
83
|
exports.expandShiftInstances = expandShiftInstances;
|
|
75
84
|
/** Expand one template into its dated instances inside the period. */
|
|
85
|
+
/**
|
|
86
|
+
* Per-site holiday calendars, keyed by site.
|
|
87
|
+
*
|
|
88
|
+
* A site that declares its own list replaces the roster's for its shifts; one
|
|
89
|
+
* that declares none inherits it, and a present-but-empty list means the site
|
|
90
|
+
* observes none. One builder because `expandShiftInstances` and `buildModel`
|
|
91
|
+
* both need it and answering differently is the failure the module's own rules
|
|
92
|
+
* name.
|
|
93
|
+
*/
|
|
94
|
+
function siteHolidayCalendars(sites) {
|
|
95
|
+
const out = new Map();
|
|
96
|
+
for (const site of sites ?? []) {
|
|
97
|
+
if (site.publicHolidays !== undefined)
|
|
98
|
+
out.set(site.id, new Set(site.publicHolidays));
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Which holiday calendar applies to a shift: the hosting site's own list where
|
|
104
|
+
* it declares one, otherwise the roster's. Holidays follow the place the work
|
|
105
|
+
* happens, so a shift with no site can only mean the roster calendar.
|
|
106
|
+
*/
|
|
107
|
+
function holidaysFor(siteId, context) {
|
|
108
|
+
if (siteId === undefined)
|
|
109
|
+
return context.publicHolidays;
|
|
110
|
+
return context.holidaysBySite?.get(siteId) ?? context.publicHolidays;
|
|
111
|
+
}
|
|
76
112
|
function expandTemplate(template, clock, periodDays, context) {
|
|
77
113
|
if (!template.id)
|
|
78
114
|
throw new types_1.ScheduleValidationError('Shift template is missing `id`');
|
|
@@ -87,6 +123,23 @@ function expandTemplate(template, clock, periodDays, context) {
|
|
|
87
123
|
throw new types_1.ScheduleValidationError(`Shift template "${template.id}" has maxEmployees below minEmployees`);
|
|
88
124
|
}
|
|
89
125
|
const overrides = validateDemandOverrides(template);
|
|
126
|
+
/*
|
|
127
|
+
* Shape checks run once per template, here, rather than per date inside
|
|
128
|
+
* `resolveDemand`.
|
|
129
|
+
*
|
|
130
|
+
* A template whose dates all fall outside the period produces no
|
|
131
|
+
* occurrences at all, so validation that happened per date never ran for it
|
|
132
|
+
* — bad configuration survived one solve and threw on the next, when the
|
|
133
|
+
* period moved over it.
|
|
134
|
+
*/
|
|
135
|
+
normalizeTagRequirements(template.tagRequirements, template.id);
|
|
136
|
+
normalizeTagRatios(template.tagRatios, template.id);
|
|
137
|
+
normalizeTagMaximums(template.tagMaximums, template.id);
|
|
138
|
+
for (const override of overrides) {
|
|
139
|
+
normalizeTagRequirements(override.tagRequirements, template.id);
|
|
140
|
+
normalizeTagRatios(override.tagRatios, template.id);
|
|
141
|
+
normalizeTagMaximums(override.tagMaximums, template.id);
|
|
142
|
+
}
|
|
90
143
|
const startTod = (0, time_1.parseTimeOfDay)(template.startTime, `shift "${template.id}".startTime`);
|
|
91
144
|
const endTodRaw = (0, time_1.parseTimeOfDay)(template.endTime, `shift "${template.id}".endTime`);
|
|
92
145
|
// Overnight shifts roll the end into the next day explicitly; a same-time
|
|
@@ -141,11 +194,11 @@ function expandTemplate(template, clock, periodDays, context) {
|
|
|
141
194
|
throw new types_1.ScheduleValidationError(`Shift template "${template.id}" resolves to a non-positive duration on ${date}`);
|
|
142
195
|
}
|
|
143
196
|
const unpaidBreak = template.unpaidBreakMinutes ?? 0;
|
|
144
|
-
if (unpaidBreak < 0 || unpaidBreak >= durationMinutes) {
|
|
197
|
+
if (!Number.isFinite(unpaidBreak) || unpaidBreak < 0 || unpaidBreak >= durationMinutes) {
|
|
145
198
|
throw new types_1.ScheduleValidationError(`Shift template "${template.id}" has invalid unpaidBreakMinutes`);
|
|
146
199
|
}
|
|
147
200
|
const paidBreak = template.paidBreakMinutes ?? 0;
|
|
148
|
-
if (paidBreak < 0 || unpaidBreak + paidBreak >= durationMinutes) {
|
|
201
|
+
if (!Number.isFinite(paidBreak) || paidBreak < 0 || unpaidBreak + paidBreak >= durationMinutes) {
|
|
149
202
|
throw new types_1.ScheduleValidationError(`Shift template "${template.id}" has invalid paidBreakMinutes`);
|
|
150
203
|
}
|
|
151
204
|
// A paid break counts as working time, so only the unpaid one is deducted.
|
|
@@ -167,6 +220,7 @@ function expandTemplate(template, clock, periodDays, context) {
|
|
|
167
220
|
minEmployees: demand.minEmployees,
|
|
168
221
|
maxEmployees: demand.maxEmployees,
|
|
169
222
|
tagRequirements: demand.tagRequirements,
|
|
223
|
+
tagRatios: demand.tagRatios,
|
|
170
224
|
tagMaximums: demand.tagMaximums,
|
|
171
225
|
requiredTags: demand.requiredTags,
|
|
172
226
|
shiftTypeTag: template.shiftTypeTag,
|
|
@@ -176,7 +230,7 @@ function expandTemplate(template, clock, periodDays, context) {
|
|
|
176
230
|
isNightShift: nightMinutes >= nightThreshold,
|
|
177
231
|
weekday: (0, time_1.isoWeekday)(date),
|
|
178
232
|
isSunday: (0, time_1.isoWeekday)(date) === 7,
|
|
179
|
-
isPublicHoliday: context.
|
|
233
|
+
isPublicHoliday: holidaysFor(template.siteId, context).has(date),
|
|
180
234
|
};
|
|
181
235
|
if (demand.label !== undefined)
|
|
182
236
|
instance.demandLabel = demand.label;
|
|
@@ -225,6 +279,105 @@ function validateDemandOverrides(template) {
|
|
|
225
279
|
* peak" plainly means three. Only a maximum the override itself states is held
|
|
226
280
|
* against the resolved minimum — that combination is a shape nobody can staff.
|
|
227
281
|
*/
|
|
282
|
+
/**
|
|
283
|
+
* Days of the period this contract is in force.
|
|
284
|
+
*
|
|
285
|
+
* Both bounds inclusive, clipped to the period, and zero when they do not
|
|
286
|
+
* overlap it at all — somebody whose contract ended in February is owed nothing
|
|
287
|
+
* in March rather than a full month they were not employed for.
|
|
288
|
+
*
|
|
289
|
+
* Arithmetic only: `validateContractDates` runs for every employee, including
|
|
290
|
+
* the ones this is never called for.
|
|
291
|
+
*/
|
|
292
|
+
/**
|
|
293
|
+
* The contract fields that change a roster whether or not a contracted week
|
|
294
|
+
* resolves.
|
|
295
|
+
*
|
|
296
|
+
* Separate from `daysInForce` because that runs only for employees whose
|
|
297
|
+
* weekly minutes resolve — and `contractLimits` string-compares these dates for
|
|
298
|
+
* *everybody*. An unpadded `2026-3-2` sorts after `2026-03-02`, so it pruned
|
|
299
|
+
* every instance and produced an empty roster with no error; a negative
|
|
300
|
+
* opening balance silently lifted a rolling cap. Both were validated for a
|
|
301
|
+
* full-timer and waved through for anybody else.
|
|
302
|
+
*/
|
|
303
|
+
function validateContractDates(employee) {
|
|
304
|
+
const contract = employee.contract;
|
|
305
|
+
if (!contract)
|
|
306
|
+
return;
|
|
307
|
+
if (contract.startDate)
|
|
308
|
+
(0, time_1.assertIsoDate)(contract.startDate, `employee "${employee.id}".contract.startDate`);
|
|
309
|
+
if (contract.endDate)
|
|
310
|
+
(0, time_1.assertIsoDate)(contract.endDate, `employee "${employee.id}".contract.endDate`);
|
|
311
|
+
if (contract.startDate && contract.endDate && contract.startDate > contract.endDate) {
|
|
312
|
+
throw new types_1.ScheduleValidationError(`Employee "${employee.id}" has a contract starting ${contract.startDate}, after it ends ${contract.endDate}`);
|
|
313
|
+
}
|
|
314
|
+
if (contract.openingBalanceMinutes !== undefined) {
|
|
315
|
+
if (!Number.isFinite(contract.openingBalanceMinutes) || contract.openingBalanceMinutes < 0) {
|
|
316
|
+
throw new types_1.ScheduleValidationError(`Employee "${employee.id}".contract.openingBalanceMinutes must be a non-negative number of minutes`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function daysInForce(employee, periodStart, periodDays) {
|
|
321
|
+
const contract = employee.contract;
|
|
322
|
+
const periodEnd = (0, time_1.addDays)(periodStart, periodDays - 1);
|
|
323
|
+
const from = contract?.startDate && contract.startDate > periodStart ? contract.startDate : periodStart;
|
|
324
|
+
const to = contract?.endDate && contract.endDate < periodEnd ? contract.endDate : periodEnd;
|
|
325
|
+
if (from > to)
|
|
326
|
+
return 0;
|
|
327
|
+
return (0, time_1.daysBetween)(from, to) + 1;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Both shapes of `tagRequirements`, resolved to one.
|
|
331
|
+
*
|
|
332
|
+
* A plain number is a count with no grade floor; the object form carries one.
|
|
333
|
+
* Normalising here means no rule downstream sees a union — the alternative,
|
|
334
|
+
* every counting site widening a `typeof` check, is how one of them ends up
|
|
335
|
+
* reading `{ min: 2 }` as `NaN` and quietly requiring nobody.
|
|
336
|
+
*/
|
|
337
|
+
function normalizeTagRequirements(stated, templateId) {
|
|
338
|
+
const out = {};
|
|
339
|
+
for (const [tag, value] of Object.entries(stated ?? {})) {
|
|
340
|
+
const requirement = typeof value === 'number' ? { min: value } : value;
|
|
341
|
+
if (!Number.isInteger(requirement?.min) || requirement.min < 0) {
|
|
342
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagRequirements["${tag}"] needs a non-negative whole minimum`);
|
|
343
|
+
}
|
|
344
|
+
if (requirement.level !== undefined) {
|
|
345
|
+
if (!Number.isFinite(requirement.level) || requirement.level <= 0) {
|
|
346
|
+
// Zero is refused rather than accepted, because it reads as "no
|
|
347
|
+
// floor" and means the opposite: `holds` skips the plain-tag
|
|
348
|
+
// branch the moment a level is present, so `{ min: 1, level: 0 }`
|
|
349
|
+
// silently excludes everybody whose tag carries no grade. Omit
|
|
350
|
+
// the level to count anybody holding the tag.
|
|
351
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagRequirements["${tag}"].level must be a positive number; ` +
|
|
352
|
+
`omit it to count anybody holding the tag`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
out[tag] = requirement.level === undefined ? { min: requirement.min } : { min: requirement.min, level: requirement.level };
|
|
356
|
+
}
|
|
357
|
+
return out;
|
|
358
|
+
}
|
|
359
|
+
/** Ceilings, checked like the minimums beside them. A negative maximum can never be met. */
|
|
360
|
+
function normalizeTagMaximums(stated, templateId) {
|
|
361
|
+
const out = {};
|
|
362
|
+
for (const [tag, max] of Object.entries(stated ?? {})) {
|
|
363
|
+
if (!Number.isInteger(max) || max < 0) {
|
|
364
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagMaximums["${tag}"] needs a non-negative whole maximum`);
|
|
365
|
+
}
|
|
366
|
+
out[tag] = max;
|
|
367
|
+
}
|
|
368
|
+
return out;
|
|
369
|
+
}
|
|
370
|
+
/** Proportions, checked as fractions. A ratio outside 0..1 is not a proportion of anything. */
|
|
371
|
+
function normalizeTagRatios(stated, templateId) {
|
|
372
|
+
const out = {};
|
|
373
|
+
for (const [tag, ratio] of Object.entries(stated ?? {})) {
|
|
374
|
+
if (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio < 0 || ratio > 1) {
|
|
375
|
+
throw new types_1.ScheduleValidationError(`Shift template "${templateId}".tagRatios["${tag}"] must be a fraction between 0 and 1`);
|
|
376
|
+
}
|
|
377
|
+
out[tag] = ratio;
|
|
378
|
+
}
|
|
379
|
+
return out;
|
|
380
|
+
}
|
|
228
381
|
function resolveDemand(template, overrides, date, onPattern) {
|
|
229
382
|
let min = template.minEmployees ?? 1;
|
|
230
383
|
let max = template.maxEmployees;
|
|
@@ -234,8 +387,9 @@ function resolveDemand(template, overrides, date, onPattern) {
|
|
|
234
387
|
const demand = {
|
|
235
388
|
minEmployees: min,
|
|
236
389
|
maxEmployees: max,
|
|
237
|
-
tagRequirements: template.tagRequirements
|
|
238
|
-
|
|
390
|
+
tagRequirements: normalizeTagRequirements(template.tagRequirements, template.id),
|
|
391
|
+
tagRatios: normalizeTagRatios(template.tagRatios, template.id),
|
|
392
|
+
tagMaximums: normalizeTagMaximums(template.tagMaximums, template.id),
|
|
239
393
|
requiredTags: template.requiredTags ?? [],
|
|
240
394
|
};
|
|
241
395
|
const weekday = (0, time_1.isoWeekday)(date);
|
|
@@ -259,10 +413,14 @@ function resolveDemand(template, overrides, date, onPattern) {
|
|
|
259
413
|
}
|
|
260
414
|
if (override.extraEmployees !== undefined)
|
|
261
415
|
extra += override.extraEmployees;
|
|
262
|
-
if (override.tagRequirements !== undefined)
|
|
263
|
-
demand.tagRequirements = override.tagRequirements;
|
|
264
|
-
|
|
265
|
-
|
|
416
|
+
if (override.tagRequirements !== undefined) {
|
|
417
|
+
demand.tagRequirements = normalizeTagRequirements(override.tagRequirements, template.id);
|
|
418
|
+
}
|
|
419
|
+
if (override.tagRatios !== undefined)
|
|
420
|
+
demand.tagRatios = normalizeTagRatios(override.tagRatios, template.id);
|
|
421
|
+
if (override.tagMaximums !== undefined) {
|
|
422
|
+
demand.tagMaximums = normalizeTagMaximums(override.tagMaximums, template.id);
|
|
423
|
+
}
|
|
266
424
|
if (override.requiredTags !== undefined)
|
|
267
425
|
demand.requiredTags = override.requiredTags;
|
|
268
426
|
if (override.runs !== undefined)
|
|
@@ -319,9 +477,12 @@ function blockedIntervalsFor(employee, clock, periodDays, instanceById) {
|
|
|
319
477
|
continue;
|
|
320
478
|
}
|
|
321
479
|
const offset = clock.dayIndexOf(entry.date);
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
480
|
+
const blocked = { start: clock.dayStartMinutes(offset), end: clock.dayStartMinutes(offset + 1) };
|
|
481
|
+
if (offset < 0 || offset >= periodDays) {
|
|
482
|
+
if (![...instanceById.values()].some((inst) => inst.startMinute < blocked.end && blocked.start < inst.endMinute))
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
out.push(blocked);
|
|
325
486
|
}
|
|
326
487
|
// External commitments are blackouts the roster may never override
|
|
327
488
|
// (Directive (EU) 2019/1152 Art 9 bars treating parallel employment as
|
|
@@ -333,19 +494,16 @@ function blockedIntervalsFor(employee, clock, periodDays, instanceById) {
|
|
|
333
494
|
}
|
|
334
495
|
/** Resolve an ISO date or date-time span to period minutes. */
|
|
335
496
|
function spanToMinutes(from, to, clock, field) {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const dayIndex = clock.dayIndexOf(datePart);
|
|
342
|
-
return endOfDayWhenBare ? clock.dayStartMinutes(dayIndex + 1) : clock.dayStartMinutes(dayIndex);
|
|
343
|
-
};
|
|
344
|
-
return { start: parse(from, false), end: parse(to, true) };
|
|
497
|
+
const start = clock.parseDateTime(from, `${field}.from`);
|
|
498
|
+
const end = clock.parseDateTime(to, `${field}.to`, true);
|
|
499
|
+
if (end <= start)
|
|
500
|
+
throw new types_1.ScheduleValidationError(`${field}: to must follow from`);
|
|
501
|
+
return { start, end };
|
|
345
502
|
}
|
|
346
503
|
function validateEmployee(employee) {
|
|
347
504
|
if (!employee.id)
|
|
348
505
|
throw new types_1.ScheduleValidationError('Employee is missing `id`');
|
|
506
|
+
validateContractDates(employee);
|
|
349
507
|
for (const [field, value] of [
|
|
350
508
|
['maxHoursForPeriod', employee.maxHoursForPeriod],
|
|
351
509
|
['minHoursForPeriod', employee.minHoursForPeriod],
|
|
@@ -404,20 +562,30 @@ function mergeRules(base, override) {
|
|
|
404
562
|
}
|
|
405
563
|
exports.mergeRules = mergeRules;
|
|
406
564
|
/** Resolve built-in constraints with caller hardness/weight overrides, then append customs. */
|
|
407
|
-
function resolveConstraints(options, rules, objectives) {
|
|
408
|
-
const
|
|
565
|
+
function resolveConstraints(options, rules, objectives, employeeRules) {
|
|
566
|
+
const defaults = {
|
|
409
567
|
minRestMinutes: options?.minRestMinutes ?? rules?.dailyRest?.minMinutes ?? min_rest_1.DEFAULT_MIN_REST_MINUTES,
|
|
410
568
|
oneShiftPerDay: options?.oneShiftPerDay ?? false,
|
|
411
569
|
rules,
|
|
412
570
|
objectives,
|
|
413
|
-
}
|
|
571
|
+
};
|
|
572
|
+
const constraints = employeeRules
|
|
573
|
+
? (0, employee_scope_1.scopeEmployeeConstraints)(defaults, employeeRules)
|
|
574
|
+
: (0, constraint_1.createDefaultConstraints)(defaults);
|
|
414
575
|
const overrides = options?.overrides ?? {};
|
|
415
576
|
for (const c of constraints) {
|
|
416
577
|
const o = overrides[c.id];
|
|
417
578
|
if (!o)
|
|
418
579
|
continue;
|
|
419
|
-
if (o.hardness !== undefined)
|
|
580
|
+
if (o.hardness !== undefined) {
|
|
420
581
|
c.hardness = o.hardness;
|
|
582
|
+
const verdict = c.verdict?.bind(c);
|
|
583
|
+
if (verdict)
|
|
584
|
+
c.verdict = (state, pair) => ({ ...verdict(state, pair), severity: o.hardness });
|
|
585
|
+
const evaluate = c.evaluate?.bind(c);
|
|
586
|
+
if (evaluate)
|
|
587
|
+
c.evaluate = (state) => evaluate(state).map((v) => ({ ...v, severity: o.hardness }));
|
|
588
|
+
}
|
|
421
589
|
if (o.weight !== undefined)
|
|
422
590
|
c.weight = o.weight;
|
|
423
591
|
}
|
|
@@ -456,19 +624,33 @@ function buildHistory(history, clock, personIdOf) {
|
|
|
456
624
|
function buildModel(input) {
|
|
457
625
|
(0, time_1.assertIsoDate)(input.period.startDate, 'period.startDate');
|
|
458
626
|
(0, time_1.assertIsoDate)(input.period.endDate, 'period.endDate');
|
|
627
|
+
for (const [name, value] of [
|
|
628
|
+
['timeBudgetMs', input.timeBudgetMs],
|
|
629
|
+
['maxIterations', input.maxIterations],
|
|
630
|
+
]) {
|
|
631
|
+
if (value !== undefined &&
|
|
632
|
+
(!Number.isFinite(value) || value < 0 || (name === 'maxIterations' && !Number.isInteger(value)))) {
|
|
633
|
+
throw new types_1.ScheduleValidationError(`${name} must be a finite non-negative ${name === 'maxIterations' ? 'integer' : 'number'}`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
459
636
|
const periodDays = (0, time_1.daysBetween)(input.period.startDate, input.period.endDate) + 1;
|
|
460
637
|
if (periodDays <= 0)
|
|
461
638
|
throw new types_1.ScheduleValidationError('period.endDate must not precede period.startDate');
|
|
462
639
|
const clock = new time_1.PeriodClock(input.period.startDate, periodDays, input.period.timeZone ?? 'UTC');
|
|
463
640
|
const rules = input.rules ?? {};
|
|
464
|
-
const siteIndex = (0, sites_1.buildSiteIndex)(input.sites, input.travelSpeedKmh);
|
|
641
|
+
const siteIndex = (0, sites_1.buildSiteIndex)(input.sites, input.travelSpeedKmh, input.period.timeZone);
|
|
465
642
|
const publicHolidays = new Set(input.calendar?.publicHolidays ?? []);
|
|
466
643
|
for (const date of publicHolidays)
|
|
467
644
|
(0, time_1.assertIsoDate)(date, 'calendar.publicHolidays');
|
|
645
|
+
const holidaysBySite = siteHolidayCalendars(input.sites);
|
|
468
646
|
const instances = [];
|
|
469
647
|
const instanceById = new Map();
|
|
470
648
|
for (const template of input.shifts) {
|
|
471
|
-
for (const inst of expandTemplate(template, clock, periodDays, {
|
|
649
|
+
for (const inst of expandTemplate(template, clock, periodDays, {
|
|
650
|
+
nightRule: rules.nightWork,
|
|
651
|
+
publicHolidays,
|
|
652
|
+
holidaysBySite,
|
|
653
|
+
})) {
|
|
472
654
|
if (instanceById.has(inst.id))
|
|
473
655
|
throw new types_1.ScheduleValidationError(`Duplicate shift instance id "${inst.id}"`);
|
|
474
656
|
instanceById.set(inst.id, inst);
|
|
@@ -497,6 +679,35 @@ function buildModel(input) {
|
|
|
497
679
|
personIdOf.set(employee.id, personId);
|
|
498
680
|
employeesOfPerson.set(personId, [...(employeesOfPerson.get(personId) ?? []), employee.id]);
|
|
499
681
|
}
|
|
682
|
+
// Tag possession is a question about the shift's date, so per-tag minimums
|
|
683
|
+
// and maximums must resolve it the same way `requiredTags` does. Plain tags
|
|
684
|
+
// short-circuit; only a dated qualification needs the scan. The cache keeps
|
|
685
|
+
// the search loop's repeated lookups off that scan — the model is immutable
|
|
686
|
+
// once built, so a memo can never go stale.
|
|
687
|
+
const tagOnCache = new Map();
|
|
688
|
+
/**
|
|
689
|
+
* The graded question. Deliberately not cached: a level floor makes the key
|
|
690
|
+
* space four-dimensional, and graded requirements are rare enough that the
|
|
691
|
+
* scan costs less than the memo would.
|
|
692
|
+
*/
|
|
693
|
+
const holdsTagAt = (employeeId, tag, date, minLevel) => {
|
|
694
|
+
const employee = employeeById.get(employeeId);
|
|
695
|
+
return employee ? (0, qualification_1.holds)(employee, tag, date, minLevel) : false;
|
|
696
|
+
};
|
|
697
|
+
const holdsTagOn = (employeeId, tag, date) => {
|
|
698
|
+
if (employeeTags.get(employeeId)?.has(tag))
|
|
699
|
+
return true;
|
|
700
|
+
const employee = employeeById.get(employeeId);
|
|
701
|
+
if (!employee?.qualifications?.length)
|
|
702
|
+
return false;
|
|
703
|
+
const key = `${employeeId}\0${tag}\0${date}`;
|
|
704
|
+
const cached = tagOnCache.get(key);
|
|
705
|
+
if (cached !== undefined)
|
|
706
|
+
return cached;
|
|
707
|
+
const result = (0, qualification_1.holds)(employee, tag, date);
|
|
708
|
+
tagOnCache.set(key, result);
|
|
709
|
+
return result;
|
|
710
|
+
};
|
|
500
711
|
// The contracted week resolves exactly once, against the rules that apply
|
|
501
712
|
// to the person (a per-person override may carry its own full-time week),
|
|
502
713
|
// and every rule reads the resolved figure from the context.
|
|
@@ -507,7 +718,11 @@ function buildModel(input) {
|
|
|
507
718
|
if (weekly === undefined)
|
|
508
719
|
continue;
|
|
509
720
|
contractedWeeklyMinutes.set(employee.id, weekly);
|
|
510
|
-
|
|
721
|
+
// Days the contract is actually in force inside the period, not the
|
|
722
|
+
// period's own length: somebody who joins on day fifteen is owed a
|
|
723
|
+
// fortnight, and planning them a full month is what made the
|
|
724
|
+
// contract-hours objective load a new starter past everybody else.
|
|
725
|
+
contractedPeriod.set(employee.id, (0, contract_hours_1.contractedPeriodMinutes)(weekly, daysInForce(employee, input.period.startDate, periodDays)));
|
|
511
726
|
}
|
|
512
727
|
const contractHoursWeight = input.objectives?.contractHoursWeight ?? contract_hours_1.DEFAULT_CONTRACT_HOURS_WEIGHT;
|
|
513
728
|
if (!Number.isFinite(contractHoursWeight) || contractHoursWeight < 0) {
|
|
@@ -525,6 +740,8 @@ function buildModel(input) {
|
|
|
525
740
|
}
|
|
526
741
|
const absences = new Map();
|
|
527
742
|
for (const absence of input.absences ?? []) {
|
|
743
|
+
if (!employeeById.has(absence.employeeId))
|
|
744
|
+
throw new types_1.ScheduleValidationError(`Unknown absence employee "${absence.employeeId}"`);
|
|
528
745
|
const span = spanToMinutes(absence.from, absence.to, clock, 'absences');
|
|
529
746
|
absences.set(absence.employeeId, [...(absences.get(absence.employeeId) ?? []), { ...span, kind: absence.kind }]);
|
|
530
747
|
// An absence blocks assignment as firmly as time off does.
|
|
@@ -537,30 +754,25 @@ function buildModel(input) {
|
|
|
537
754
|
publishedPairs.add(`${assignment.employeeId}|${assignment.shiftInstanceId}`);
|
|
538
755
|
}
|
|
539
756
|
const pinned = new Set((input.pinned ?? []).map((p) => `${p.employeeId}|${p.shiftInstanceId}`));
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
publishedAtMinute = clock.toPeriodMinutes(datePart, (timePart ?? '00:00').slice(0, 5), 'published.publishedAt');
|
|
545
|
-
}
|
|
546
|
-
let asOfMinute;
|
|
547
|
-
if (input.asOf) {
|
|
548
|
-
const [datePart, timePart] = input.asOf.split('T');
|
|
549
|
-
(0, time_1.assertIsoDate)(datePart, 'asOf');
|
|
550
|
-
asOfMinute = clock.toPeriodMinutes(datePart, (timePart ?? '00:00').slice(0, 5), 'asOf');
|
|
551
|
-
}
|
|
757
|
+
const publishedAtMinute = input.published?.publishedAt === undefined
|
|
758
|
+
? undefined
|
|
759
|
+
: clock.parseDateTime(input.published.publishedAt, 'published.publishedAt');
|
|
760
|
+
const asOfMinute = input.asOf === undefined ? undefined : clock.parseDateTime(input.asOf, 'asOf');
|
|
552
761
|
return {
|
|
553
762
|
periodStartDate: input.period.startDate,
|
|
554
763
|
periodDays,
|
|
555
764
|
employees: input.employees,
|
|
556
765
|
employeeById,
|
|
557
766
|
employeeTags,
|
|
767
|
+
holdsTagOn,
|
|
768
|
+
holdsTagAt,
|
|
558
769
|
instances,
|
|
559
770
|
instanceById,
|
|
560
771
|
siteIndex,
|
|
561
772
|
employeeBlockedIntervals,
|
|
562
773
|
minRestMinutes: input.constraints?.minRestMinutes ?? rules.dailyRest?.minMinutes ?? min_rest_1.DEFAULT_MIN_REST_MINUTES,
|
|
563
|
-
|
|
774
|
+
aggregateConstraints: input.constraints?.custom?.filter((c) => c.evaluate) ?? [],
|
|
775
|
+
constraints: resolveConstraints(input.constraints, rules, input.objectives, rulesByEmployee),
|
|
564
776
|
clock,
|
|
565
777
|
rules,
|
|
566
778
|
rulesByEmployee,
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
import type { AssignmentPair, ConstraintViolation, LedgerEntry, RuleVerdict, ScheduleInput, ScheduledAssignment, ContractHoursSummary } from './types';
|
|
21
21
|
export interface ComplianceReport {
|
|
22
22
|
compliant: boolean;
|
|
23
|
+
/** Whether all headcount and skill coverage requirements are met. */
|
|
24
|
+
coverageComplete: boolean;
|
|
25
|
+
/** A fully covered roster with no hard breaches. */
|
|
26
|
+
publishable: boolean;
|
|
23
27
|
violations: ConstraintViolation[];
|
|
24
28
|
/** Per-assignment verdicts for every rule that had something to say. */
|
|
25
29
|
verdicts: Array<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/scheduling/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
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