assignment-user-matcher 1.8.0 → 1.10.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 +240 -12
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/matcher.class.d.ts +44 -2
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +393 -4
- package/dist/queries/pagination.d.ts +5 -1
- package/dist/queries/pagination.d.ts.map +1 -1
- package/dist/queries/pagination.js +14 -3
- package/dist/schedule/policy.d.ts +35 -0
- package/dist/schedule/policy.d.ts.map +1 -0
- package/dist/schedule/policy.js +62 -0
- package/dist/scheduling/constraints/availability.d.ts +44 -0
- package/dist/scheduling/constraints/availability.d.ts.map +1 -0
- package/dist/scheduling/constraints/availability.js +142 -0
- package/dist/scheduling/constraints/consecutive.d.ts +25 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -0
- package/dist/scheduling/constraints/consecutive.js +215 -0
- package/dist/scheduling/constraints/constraint.d.ts +35 -0
- package/dist/scheduling/constraints/constraint.d.ts.map +1 -0
- package/dist/scheduling/constraints/constraint.js +97 -0
- package/dist/scheduling/constraints/contract.d.ts +21 -0
- package/dist/scheduling/constraints/contract.d.ts.map +1 -0
- package/dist/scheduling/constraints/contract.js +106 -0
- package/dist/scheduling/constraints/cost.d.ts +18 -0
- package/dist/scheduling/constraints/cost.d.ts.map +1 -0
- package/dist/scheduling/constraints/cost.js +65 -0
- package/dist/scheduling/constraints/daily-rest.d.ts +22 -0
- package/dist/scheduling/constraints/daily-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/daily-rest.js +118 -0
- package/dist/scheduling/constraints/duty-quota.d.ts +20 -0
- package/dist/scheduling/constraints/duty-quota.d.ts.map +1 -0
- package/dist/scheduling/constraints/duty-quota.js +95 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts +28 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts.map +1 -0
- package/dist/scheduling/constraints/engagement-floor.js +79 -0
- package/dist/scheduling/constraints/fairness.d.ts +34 -0
- package/dist/scheduling/constraints/fairness.d.ts.map +1 -0
- package/dist/scheduling/constraints/fairness.js +149 -0
- package/dist/scheduling/constraints/group-composition.d.ts +19 -0
- package/dist/scheduling/constraints/group-composition.d.ts.map +1 -0
- package/dist/scheduling/constraints/group-composition.js +92 -0
- package/dist/scheduling/constraints/hour-budget.d.ts +13 -0
- package/dist/scheduling/constraints/hour-budget.d.ts.map +1 -0
- package/dist/scheduling/constraints/hour-budget.js +59 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts +24 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts.map +1 -0
- package/dist/scheduling/constraints/in-shift-breaks.js +97 -0
- package/dist/scheduling/constraints/intervals.d.ts +5 -0
- package/dist/scheduling/constraints/intervals.d.ts.map +1 -0
- package/dist/scheduling/constraints/intervals.js +17 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts +7 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts.map +1 -0
- package/dist/scheduling/constraints/max-shift-duration.js +38 -0
- package/dist/scheduling/constraints/min-rest.d.ts +22 -0
- package/dist/scheduling/constraints/min-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-rest.js +60 -0
- package/dist/scheduling/constraints/min-staffing.d.ts +14 -0
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-staffing.js +59 -0
- package/dist/scheduling/constraints/night-work.d.ts +24 -0
- package/dist/scheduling/constraints/night-work.d.ts.map +1 -0
- package/dist/scheduling/constraints/night-work.js +163 -0
- package/dist/scheduling/constraints/no-overlap.d.ts +7 -0
- package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -0
- package/dist/scheduling/constraints/no-overlap.js +36 -0
- package/dist/scheduling/constraints/notice.d.ts +44 -0
- package/dist/scheduling/constraints/notice.d.ts.map +1 -0
- package/dist/scheduling/constraints/notice.js +140 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts +7 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts.map +1 -0
- package/dist/scheduling/constraints/one-shift-per-day.js +35 -0
- package/dist/scheduling/constraints/overtime.d.ts +47 -0
- package/dist/scheduling/constraints/overtime.d.ts.map +1 -0
- package/dist/scheduling/constraints/overtime.js +149 -0
- package/dist/scheduling/constraints/protections.d.ts +21 -0
- package/dist/scheduling/constraints/protections.d.ts.map +1 -0
- package/dist/scheduling/constraints/protections.js +93 -0
- package/dist/scheduling/constraints/qualification.d.ts +18 -0
- package/dist/scheduling/constraints/qualification.d.ts.map +1 -0
- package/dist/scheduling/constraints/qualification.js +78 -0
- package/dist/scheduling/constraints/rest-days.d.ts +30 -0
- package/dist/scheduling/constraints/rest-days.d.ts.map +1 -0
- package/dist/scheduling/constraints/rest-days.js +133 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts +24 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -0
- package/dist/scheduling/constraints/rolling-hours.js +147 -0
- package/dist/scheduling/constraints/start-interval.d.ts +20 -0
- package/dist/scheduling/constraints/start-interval.d.ts.map +1 -0
- package/dist/scheduling/constraints/start-interval.js +53 -0
- package/dist/scheduling/constraints/support.d.ts +48 -0
- package/dist/scheduling/constraints/support.d.ts.map +1 -0
- package/dist/scheduling/constraints/support.js +97 -0
- package/dist/scheduling/constraints/time-off.d.ts +7 -0
- package/dist/scheduling/constraints/time-off.d.ts.map +1 -0
- package/dist/scheduling/constraints/time-off.js +42 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts +22 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/weekly-rest.js +92 -0
- package/dist/scheduling/cost.d.ts +56 -0
- package/dist/scheduling/cost.d.ts.map +1 -0
- package/dist/scheduling/cost.js +120 -0
- package/dist/scheduling/engine/construction.d.ts +22 -0
- package/dist/scheduling/engine/construction.d.ts.map +1 -0
- package/dist/scheduling/engine/construction.js +97 -0
- package/dist/scheduling/engine/explain.d.ts +12 -0
- package/dist/scheduling/engine/explain.d.ts.map +1 -0
- package/dist/scheduling/engine/explain.js +24 -0
- package/dist/scheduling/engine/objective.d.ts +73 -0
- package/dist/scheduling/engine/objective.d.ts.map +1 -0
- package/dist/scheduling/engine/objective.js +164 -0
- package/dist/scheduling/engine/prng.d.ts +5 -0
- package/dist/scheduling/engine/prng.d.ts.map +1 -0
- package/dist/scheduling/engine/prng.js +24 -0
- package/dist/scheduling/engine/propagation.d.ts +19 -0
- package/dist/scheduling/engine/propagation.d.ts.map +1 -0
- package/dist/scheduling/engine/propagation.js +40 -0
- package/dist/scheduling/engine/search.d.ts +50 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -0
- package/dist/scheduling/engine/search.js +127 -0
- package/dist/scheduling/engine/state.d.ts +28 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -0
- package/dist/scheduling/engine/state.js +96 -0
- package/dist/scheduling/engine/timeline.d.ts +179 -0
- package/dist/scheduling/engine/timeline.d.ts.map +1 -0
- package/dist/scheduling/engine/timeline.js +416 -0
- package/dist/scheduling/engine/verdicts.d.ts +18 -0
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -0
- package/dist/scheduling/engine/verdicts.js +74 -0
- package/dist/scheduling/index.d.ts +10 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +29 -0
- package/dist/scheduling/model.d.ts +53 -0
- package/dist/scheduling/model.d.ts.map +1 -0
- package/dist/scheduling/model.js +379 -0
- package/dist/scheduling/operations.d.ts +134 -0
- package/dist/scheduling/operations.d.ts.map +1 -0
- package/dist/scheduling/operations.js +376 -0
- package/dist/scheduling/provenance.d.ts +33 -0
- package/dist/scheduling/provenance.d.ts.map +1 -0
- package/dist/scheduling/provenance.js +70 -0
- package/dist/scheduling/rules.d.ts +23 -0
- package/dist/scheduling/rules.d.ts.map +1 -0
- package/dist/scheduling/rules.js +37 -0
- package/dist/scheduling/scheduler.class.d.ts +24 -0
- package/dist/scheduling/scheduler.class.d.ts.map +1 -0
- package/dist/scheduling/scheduler.class.js +150 -0
- package/dist/scheduling/time.d.ts +132 -0
- package/dist/scheduling/time.d.ts.map +1 -0
- package/dist/scheduling/time.js +256 -0
- package/dist/scheduling/types.d.ts +932 -0
- package/dist/scheduling/types.d.ts.map +1 -0
- package/dist/scheduling/types.js +19 -0
- package/dist/scoring/match-score.d.ts.map +1 -1
- package/dist/scoring/match-score.js +1 -3
- package/dist/types/matcher.d.ts +195 -1
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/utils/keys.d.ts +3 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +15 -0
- package/dist/validation/assignment-lint.d.ts +24 -0
- package/dist/validation/assignment-lint.d.ts.map +1 -0
- package/dist/validation/assignment-lint.js +132 -0
- package/package.json +4 -2
|
@@ -0,0 +1,932 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shift-scheduling types — the public contract of the `scheduling` module.
|
|
3
|
+
*
|
|
4
|
+
* Everything in this module is pure logic: no Redis, no I/O, no timers owned
|
|
5
|
+
* by the scheduler itself beyond a cooperative wall-clock budget. The caller
|
|
6
|
+
* provides a `ScheduleInput`, receives a `ScheduleResult`, and persists or
|
|
7
|
+
* ships it however they like.
|
|
8
|
+
*/
|
|
9
|
+
import type { PeriodClock } from './time';
|
|
10
|
+
import type { TimelineEntry, TimelineIndex } from './engine/timeline';
|
|
11
|
+
/**
|
|
12
|
+
* A single employee that can be rostered. Durations are minutes unless the
|
|
13
|
+
* field name says otherwise — the `*HoursForPeriod` bounds are in hours, every
|
|
14
|
+
* `*Minutes` field is in minutes.
|
|
15
|
+
*/
|
|
16
|
+
export interface Employee {
|
|
17
|
+
id: string;
|
|
18
|
+
tags: string[];
|
|
19
|
+
/** ISO dates (YYYY-MM-DD) or explicit shift instances the employee must not work. */
|
|
20
|
+
timeOff: TimeOffEntry[];
|
|
21
|
+
/** Hard upper bound of worked **hours** over the whole period. */
|
|
22
|
+
maxHoursForPeriod?: number;
|
|
23
|
+
/** Soft lower bound of worked **hours** over the whole period (warn, don't block). */
|
|
24
|
+
minHoursForPeriod?: number;
|
|
25
|
+
/** Hard upper bound of a single shift's duration for this employee. */
|
|
26
|
+
maxShiftDurationMinutes?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The natural person behind this record. Defaults to `id`.
|
|
29
|
+
*
|
|
30
|
+
* Set it when one human holds several contracts or roles: CJEU C-585/19
|
|
31
|
+
* holds that daily rest applies to all contracts with the same employer
|
|
32
|
+
* *taken as a whole*. Rest, rolling hour windows and sequence rules
|
|
33
|
+
* aggregate on this key, so leaving it unset for a double-contracted worker
|
|
34
|
+
* understates their hours and overstates their rest.
|
|
35
|
+
*/
|
|
36
|
+
personId?: string;
|
|
37
|
+
/** Qualifications with optional validity dates. Absent dates mean "always valid". */
|
|
38
|
+
qualifications?: Qualification[];
|
|
39
|
+
/** Recurring availability, preferences and hard blackouts. */
|
|
40
|
+
availability?: AvailabilityRule[];
|
|
41
|
+
/**
|
|
42
|
+
* Commitments outside this employer that the roster may never override —
|
|
43
|
+
* a second job, studies, agreed carer time. Directive (EU) 2019/1152 Art 9
|
|
44
|
+
* forbids treating parallel employment as a schedulable gap.
|
|
45
|
+
*/
|
|
46
|
+
externalCommitments?: Array<{
|
|
47
|
+
from: string;
|
|
48
|
+
to: string;
|
|
49
|
+
}>;
|
|
50
|
+
/** Contract shape; `kind: 'days'` models day-count contracts such as the French *forfait jours*. */
|
|
51
|
+
contract?: EmployeeContract;
|
|
52
|
+
/**
|
|
53
|
+
* Per-person overrides of the global rule set. This is how age classes,
|
|
54
|
+
* opt-outs, hazardous-night status and autonomous-worker derogations are
|
|
55
|
+
* expressed — the rules themselves stay generic.
|
|
56
|
+
*/
|
|
57
|
+
rules?: WorkingTimeRules;
|
|
58
|
+
/** Statutory protections that select a stricter rule path for this person. */
|
|
59
|
+
protections?: EmployeeProtection[];
|
|
60
|
+
/** Cost inputs for the ranking and cost objective. */
|
|
61
|
+
cost?: EmployeeCost;
|
|
62
|
+
/**
|
|
63
|
+
* Whether this person has agreed to work overtime, where
|
|
64
|
+
* `OvertimeRule.requiresConsent` makes that agreement a precondition.
|
|
65
|
+
* Consent is a fact the caller records, never something the engine assumes.
|
|
66
|
+
*/
|
|
67
|
+
overtimeConsent?: boolean;
|
|
68
|
+
/** Higher wins where a collective agreement orders offers by seniority. */
|
|
69
|
+
seniority?: number;
|
|
70
|
+
/** Realised counts carried in from previous periods, keyed by fairness dimension. */
|
|
71
|
+
carriedFairness?: Record<string, number>;
|
|
72
|
+
}
|
|
73
|
+
/** A qualification, optionally valid only for part of the period. */
|
|
74
|
+
export interface Qualification {
|
|
75
|
+
/** Matches `ShiftTemplate.tagRequirements` keys and `requiredTags`. */
|
|
76
|
+
tag: string;
|
|
77
|
+
/** Optional proficiency; group-composition rules can require a minimum. */
|
|
78
|
+
level?: number;
|
|
79
|
+
/** Inclusive ISO date the qualification becomes valid. */
|
|
80
|
+
validFrom?: string;
|
|
81
|
+
/** Inclusive ISO date the qualification expires. A shift after this is ineligible. */
|
|
82
|
+
validUntil?: string;
|
|
83
|
+
}
|
|
84
|
+
/** A recurring availability or preference window. */
|
|
85
|
+
export interface AvailabilityRule {
|
|
86
|
+
/** ISO weekdays 1 (Mon) .. 7 (Sun). Omit for every day. */
|
|
87
|
+
daysOfWeek?: number[];
|
|
88
|
+
/** Inclusive ISO date bounds. Omit for the whole period. */
|
|
89
|
+
fromDate?: string;
|
|
90
|
+
toDate?: string;
|
|
91
|
+
/** Wall-clock window within the day. Omit for the whole day. */
|
|
92
|
+
from?: string;
|
|
93
|
+
to?: string;
|
|
94
|
+
/**
|
|
95
|
+
* `unavailable` is a hard blackout; `available` restricts to the listed
|
|
96
|
+
* windows (any shift outside every `available` rule is ineligible);
|
|
97
|
+
* `preferred` / `avoid` are soft and scale by `weight`.
|
|
98
|
+
*/
|
|
99
|
+
kind: 'unavailable' | 'available' | 'preferred' | 'avoid';
|
|
100
|
+
/** Soft-rule strength. Defaults to 1. */
|
|
101
|
+
weight?: number;
|
|
102
|
+
}
|
|
103
|
+
/** Contract shape — hours-based or day-count. */
|
|
104
|
+
export interface EmployeeContract {
|
|
105
|
+
kind: 'hours' | 'days';
|
|
106
|
+
/** Target contractual minutes per week, used for pro-rata fairness. */
|
|
107
|
+
weeklyMinutes?: number;
|
|
108
|
+
/** Day-count contracts: maximum working days in the period (e.g. FR forfait jours). */
|
|
109
|
+
maxDaysInPeriod?: number;
|
|
110
|
+
/** Hard bounds over the period, in minutes. */
|
|
111
|
+
minPeriodMinutes?: number;
|
|
112
|
+
maxPeriodMinutes?: number;
|
|
113
|
+
/** Last day the contract runs; shifts after it are ineligible. */
|
|
114
|
+
endDate?: string;
|
|
115
|
+
}
|
|
116
|
+
/** A statutory protection that changes which rules apply to a person. */
|
|
117
|
+
export interface EmployeeProtection {
|
|
118
|
+
/**
|
|
119
|
+
* `minor` and `hazardousNight` select stricter limits; `pregnancyNightExclusion`
|
|
120
|
+
* is a certificate-triggered bar on night work (Directive 92/85/EEC Art 7),
|
|
121
|
+
* which mandates a day-work alternative rather than mere unavailability.
|
|
122
|
+
*/
|
|
123
|
+
kind: 'minor' | 'hazardousNight' | 'pregnancyNightExclusion';
|
|
124
|
+
/** What the employer owes instead. Recorded in the result, not solved for. */
|
|
125
|
+
fallback?: 'dayShift' | 'leave';
|
|
126
|
+
}
|
|
127
|
+
/** Cost inputs. All money is in minor units (cents) to keep arithmetic integral. */
|
|
128
|
+
export interface EmployeeCost {
|
|
129
|
+
hourlyRateCents?: number;
|
|
130
|
+
/** Minutes in the period after which overtime rates apply. */
|
|
131
|
+
overtimeAfterMinutes?: number;
|
|
132
|
+
overtimeMultiplier?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Fraction of the hourly rate paid for the non-working remainder of a
|
|
135
|
+
* duty-classified span — stand-by hours that occupy the clock without
|
|
136
|
+
* counting as work. Estonia's *valveaeg* owes at least 1/10 of the agreed
|
|
137
|
+
* wage (`0.1`); unset means the remainder is unpaid.
|
|
138
|
+
*/
|
|
139
|
+
standbyRateFraction?: number;
|
|
140
|
+
/** Premium multipliers by predicate, applied to the minutes actually inside each band. */
|
|
141
|
+
premiums?: Array<{
|
|
142
|
+
predicate: 'night' | 'sunday' | 'holiday';
|
|
143
|
+
multiplier: number;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* How multiple applicable premiums combine. Romania requires `'add'`
|
|
147
|
+
* (overtime 75% + night 25% + holiday 100% stack); most others take the max.
|
|
148
|
+
* Defaults to `'max'`.
|
|
149
|
+
*/
|
|
150
|
+
stacking?: 'add' | 'max';
|
|
151
|
+
}
|
|
152
|
+
/** Time-off as an explicit entry — date alone blocks the whole day; `shiftInstanceId` scopes it. */
|
|
153
|
+
export interface TimeOffEntry {
|
|
154
|
+
/** ISO date, YYYY-MM-DD. */
|
|
155
|
+
date: string;
|
|
156
|
+
/** Optional shift-instance id (`<templateId>@<date>`); when set only that instance is blocked. */
|
|
157
|
+
shiftInstanceId?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The labour-law layer, as plain typed configuration.
|
|
161
|
+
*
|
|
162
|
+
* Every field is optional and every value is caller-supplied: the library ships
|
|
163
|
+
* the *shapes* that EU working-time law takes, never a jurisdiction's numbers.
|
|
164
|
+
* That split matters twice over — legal values differ per member state, per
|
|
165
|
+
* sector and per collective agreement and change without notice; and for the
|
|
166
|
+
* sectoral regimes that *replace* the Working Time Directive rather than relax
|
|
167
|
+
* it (Art 14/20/21 — mobile workers, seafarers), the correct encoding is to
|
|
168
|
+
* omit the displaced rule entirely rather than to widen its bounds.
|
|
169
|
+
*
|
|
170
|
+
* `Employee.rules` overrides this per person, which is how age classes,
|
|
171
|
+
* individual opt-outs and hazardous-work status are expressed.
|
|
172
|
+
*/
|
|
173
|
+
export interface WorkingTimeRules {
|
|
174
|
+
dailyRest?: DailyRestRule;
|
|
175
|
+
weeklyRest?: WeeklyRestRule;
|
|
176
|
+
workingTime?: WorkingTimeLimits;
|
|
177
|
+
/** The ordinary-vs-overtime split and its caps. */
|
|
178
|
+
overtime?: OvertimeRule;
|
|
179
|
+
/** Rolling volume caps on particular duty types, matched on `shiftTypeTag`. */
|
|
180
|
+
dutyQuotas?: DutyQuota[];
|
|
181
|
+
consecutive?: ConsecutiveRule;
|
|
182
|
+
/**
|
|
183
|
+
* Minimum minutes between the *starts* of two assignments. Poland's
|
|
184
|
+
* *doba pracownicza* makes restarting inside 24h of the previous start
|
|
185
|
+
* overtime regardless of how much rest was taken, so it is keyed on starts,
|
|
186
|
+
* not gaps — a distinct shape from `dailyRest`.
|
|
187
|
+
*/
|
|
188
|
+
minimumStartInterval?: {
|
|
189
|
+
minMinutes: number;
|
|
190
|
+
};
|
|
191
|
+
nightWork?: NightWorkRule;
|
|
192
|
+
breaks?: BreakRule[];
|
|
193
|
+
restDays?: RestDayRule;
|
|
194
|
+
engagement?: EngagementRule;
|
|
195
|
+
notice?: NoticeRule;
|
|
196
|
+
/** Fairness dimensions to equalise. Soft by nature. */
|
|
197
|
+
fairness?: FairnessRule[];
|
|
198
|
+
/** How to aggregate a person's assignments across records. */
|
|
199
|
+
aggregation?: {
|
|
200
|
+
acrossContracts?: boolean;
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** Daily rest — Directive 2003/88/EC Art 3 and its national variants. */
|
|
204
|
+
export interface DailyRestRule {
|
|
205
|
+
/** e.g. 660 (EU floor), 720 (ES, RO), 540 (FI period work). */
|
|
206
|
+
minMinutes: number;
|
|
207
|
+
/** Window the rest must fit in. Defaults to 1440 — "in every rolling 24h". */
|
|
208
|
+
perWindowMinutes?: number;
|
|
209
|
+
/** Floor a permitted derogation may reduce rest to (NL/DK/CZ 480, FR 540). */
|
|
210
|
+
reducibleToMinutes?: number;
|
|
211
|
+
/** How often the reduction may be used, e.g. NL's "once per 7×24h". */
|
|
212
|
+
reductionsPer?: {
|
|
213
|
+
max: number;
|
|
214
|
+
windowDays: number;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Deadline for the compensatory rest a derogation creates. Jaeger (C-151/02)
|
|
218
|
+
* requires it "immediately following" the period worked; national rules give
|
|
219
|
+
* a window instead (DE 28 days, AT 10).
|
|
220
|
+
*/
|
|
221
|
+
compensateWithinDays?: number;
|
|
222
|
+
/**
|
|
223
|
+
* A clock band the rest must contain. Sweden requires the 11h to include
|
|
224
|
+
* 00:00–05:00 — a *positional* rule, not a duration one.
|
|
225
|
+
*/
|
|
226
|
+
mustContainClockRange?: ClockRangeConfig;
|
|
227
|
+
}
|
|
228
|
+
/** Weekly rest — Art 5, with the Art 16(a) averaging option. */
|
|
229
|
+
export interface WeeklyRestRule {
|
|
230
|
+
/** Continuous rest required per window: 2100 (35h), 2160 (36h), 2880 (48h). */
|
|
231
|
+
minMinutes: number;
|
|
232
|
+
/** Length of the window in days. Normally 7. */
|
|
233
|
+
windowDays: number;
|
|
234
|
+
/**
|
|
235
|
+
* A lower per-window floor that always holds when `minMinutes` is only met
|
|
236
|
+
* on average. Estonia requires 36h every week *and* 48h on average.
|
|
237
|
+
*/
|
|
238
|
+
absoluteFloorMinutes?: number;
|
|
239
|
+
/** Averaging window in days; Art 16(a) caps this at 14. */
|
|
240
|
+
averageOverDays?: number;
|
|
241
|
+
}
|
|
242
|
+
/** Volume limits, including the rolling reference periods that define EU working time. */
|
|
243
|
+
export interface WorkingTimeLimits {
|
|
244
|
+
maxPerShiftMinutes?: number;
|
|
245
|
+
/** Ordinary daily cap, e.g. Germany's 8h. */
|
|
246
|
+
maxPerDayMinutes?: number;
|
|
247
|
+
/** Extended daily cap permitted when the average over `dayAverageWindowDays` holds. */
|
|
248
|
+
maxPerDayExtendedMinutes?: number;
|
|
249
|
+
dayAverageWindowDays?: number;
|
|
250
|
+
/** Cap no single week may exceed regardless of averaging. */
|
|
251
|
+
maxPerWeekAbsoluteMinutes?: number;
|
|
252
|
+
/**
|
|
253
|
+
* Rolling averages, each "at most `maxMinutes` of working time in any
|
|
254
|
+
* window of `windowDays` days". The EU 48h/4-month rule is
|
|
255
|
+
* `{ maxMinutes: 2880, windowDays: 120 }`; the Netherlands stacks
|
|
256
|
+
* `{3300, 28}` with `{2880, 112}`; Spain averages over a year.
|
|
257
|
+
*/
|
|
258
|
+
rollingAverages?: RollingAverage[];
|
|
259
|
+
/** Hard cap over the whole period, in minutes. */
|
|
260
|
+
maxPerPeriodMinutes?: number;
|
|
261
|
+
/**
|
|
262
|
+
* Absence kinds excluded from rolling averages. Art 16(b) requires paid
|
|
263
|
+
* annual leave and sick leave to be neutral in the 48h calculation, so
|
|
264
|
+
* counting them would wrongly depress a worker's average.
|
|
265
|
+
*/
|
|
266
|
+
neutraliseAbsenceKinds?: string[];
|
|
267
|
+
}
|
|
268
|
+
/** One rolling-average limit. */
|
|
269
|
+
export interface RollingAverage {
|
|
270
|
+
maxMinutes: number;
|
|
271
|
+
windowDays: number;
|
|
272
|
+
/** Optional label used in violation messages, e.g. "48h/4 months". */
|
|
273
|
+
label?: string;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The ordinary-vs-overtime split.
|
|
277
|
+
*
|
|
278
|
+
* `WorkingTimeLimits` caps *total* working time; several member states also
|
|
279
|
+
* regulate the overtime portion by itself — Estonia makes overtime conditional
|
|
280
|
+
* on agreement and compensates it primarily in time off, Germany's ArbZG builds
|
|
281
|
+
* the 10h day out of 8 ordinary + 2 averaged, Austria caps overtime separately
|
|
282
|
+
* from normal hours. That needs a defined ordinary baseline, which is what the
|
|
283
|
+
* `ordinary*` fields (or a person's `contract.weeklyMinutes`) supply; everything
|
|
284
|
+
* worked beyond the baseline in a window is that window's overtime.
|
|
285
|
+
*/
|
|
286
|
+
export interface OvertimeRule {
|
|
287
|
+
/** Working minutes per rolling 24h beyond which time is overtime. */
|
|
288
|
+
ordinaryPerDayMinutes?: number;
|
|
289
|
+
/**
|
|
290
|
+
* Working minutes per rolling 7 days beyond which time is overtime.
|
|
291
|
+
* A person's `contract.weeklyMinutes` overrides this — a part-timer's
|
|
292
|
+
* overtime starts at their agreed hours, not at full time.
|
|
293
|
+
*/
|
|
294
|
+
ordinaryPerWeekMinutes?: number;
|
|
295
|
+
/** Cap on overtime minutes in any rolling 24h. Requires `ordinaryPerDayMinutes`. */
|
|
296
|
+
maxOvertimePerDayMinutes?: number;
|
|
297
|
+
/**
|
|
298
|
+
* Caps on overtime minutes over rolling windows, each measured against the
|
|
299
|
+
* weekly ordinary baseline pro-rated to the window. Requires a weekly
|
|
300
|
+
* baseline (`ordinaryPerWeekMinutes` or per-person contract minutes).
|
|
301
|
+
*/
|
|
302
|
+
maxOvertimeInWindow?: Array<{
|
|
303
|
+
maxMinutes: number;
|
|
304
|
+
windowDays: number;
|
|
305
|
+
label?: string;
|
|
306
|
+
}>;
|
|
307
|
+
/**
|
|
308
|
+
* Overtime needs the employee's agreement (`Employee.overtimeConsent`).
|
|
309
|
+
* Without recorded consent, any overtime at all is a hard breach.
|
|
310
|
+
*/
|
|
311
|
+
requiresConsent?: boolean;
|
|
312
|
+
/**
|
|
313
|
+
* How overtime is compensated. `'timeOff'` accrues a `timeOffInLieu` ledger
|
|
314
|
+
* entry per employee; `'pay'` leaves compensation to the cost model.
|
|
315
|
+
*/
|
|
316
|
+
compensation?: 'timeOff' | 'pay';
|
|
317
|
+
/** Legal source echoed into verdicts and violations. */
|
|
318
|
+
citation?: string;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* A rolling volume cap on one duty type — "at most N hours (or N occurrences)
|
|
322
|
+
* of stand-by in any 28 days". Matched on `ShiftTemplate.shiftTypeTag`.
|
|
323
|
+
*
|
|
324
|
+
* `maxMinutes` counts *elapsed* duty minutes, not working minutes: a cap on
|
|
325
|
+
* stand-by limits how long the duty may occupy the person's clock, which is
|
|
326
|
+
* precisely the time a duty classification keeps out of the working-time
|
|
327
|
+
* budget. Working-time volume belongs to `workingTime`, not here.
|
|
328
|
+
*/
|
|
329
|
+
export interface DutyQuota {
|
|
330
|
+
/** Which duties count: exact match on the instance's `shiftTypeTag`. */
|
|
331
|
+
shiftTypeTag: string;
|
|
332
|
+
/** Cap on elapsed minutes of matching duties in any window. */
|
|
333
|
+
maxMinutes?: number;
|
|
334
|
+
/** Cap on the number of matching duties in any window. */
|
|
335
|
+
maxCount?: number;
|
|
336
|
+
windowDays: number;
|
|
337
|
+
label?: string;
|
|
338
|
+
citation?: string;
|
|
339
|
+
}
|
|
340
|
+
/** Sequence rules over one person's ordered assignments. */
|
|
341
|
+
export interface ConsecutiveRule {
|
|
342
|
+
/** e.g. Portugal's 6. */
|
|
343
|
+
maxWorkingDays?: number;
|
|
344
|
+
/** e.g. Finland 5, Netherlands 7. */
|
|
345
|
+
maxNightShifts?: number;
|
|
346
|
+
/** Rest owed once the night run ends: NL 2760 (46h), FI 1440 (24h). */
|
|
347
|
+
restAfterNightBlockMinutes?: number;
|
|
348
|
+
/**
|
|
349
|
+
* Disallowed shift-type transitions, matched on `ShiftTemplate.shiftTypeTag`.
|
|
350
|
+
* The classic is Night → Early ("quick return").
|
|
351
|
+
*/
|
|
352
|
+
forbiddenSuccessions?: Array<{
|
|
353
|
+
fromTag: string;
|
|
354
|
+
toTag: string;
|
|
355
|
+
minGapMinutes?: number;
|
|
356
|
+
}>;
|
|
357
|
+
}
|
|
358
|
+
/** Night work — Art 2(3), 2(4), 8 and their national variants. */
|
|
359
|
+
export interface NightWorkRule {
|
|
360
|
+
/**
|
|
361
|
+
* The night band. Art 2(3) requires at least 7 hours including 00:00–05:00,
|
|
362
|
+
* but the exact window is national: 20:00–06:00 (BE) through 00:00–07:00 (IE),
|
|
363
|
+
* and Poland lets the employer choose any 8h band within 21:00–07:00.
|
|
364
|
+
*/
|
|
365
|
+
window: ClockRangeConfig;
|
|
366
|
+
/** Night minutes in a shift that make it a night shift. Art 2(4)(a) uses 180. */
|
|
367
|
+
qualifiesAfterMinutes?: number;
|
|
368
|
+
/** Cap on a night worker's shift, normally 480. */
|
|
369
|
+
maxShiftMinutes?: number;
|
|
370
|
+
/** Days over which the 8h night limit is averaged. Art 8(a) sets no EU ceiling. */
|
|
371
|
+
averageWindowDays?: number;
|
|
372
|
+
/**
|
|
373
|
+
* Art 8(b): for work involving special hazards or heavy strain the 8h is an
|
|
374
|
+
* absolute per-24h cap with no averaging. Set by `Employee.protections`
|
|
375
|
+
* carrying `hazardousNight`, or globally here.
|
|
376
|
+
*/
|
|
377
|
+
absoluteWhenHazardous?: boolean;
|
|
378
|
+
/** Caps on how many night shifts may fall in a window, optionally filtered by end time. */
|
|
379
|
+
volumeQuotas?: NightVolumeQuota[];
|
|
380
|
+
/** Clock bands where work is barred outright (94/33/EC bars adolescents 00:00–04:00). */
|
|
381
|
+
prohibitedRanges?: ClockRangeConfig[];
|
|
382
|
+
}
|
|
383
|
+
/** A cap on night-shift count over a rolling window. */
|
|
384
|
+
export interface NightVolumeQuota {
|
|
385
|
+
max: number;
|
|
386
|
+
windowDays: number;
|
|
387
|
+
/** Only count shifts ending after this wall-clock time (NL counts those past 02:00). */
|
|
388
|
+
endingAfter?: string;
|
|
389
|
+
label?: string;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* In-shift break entitlement. Art 4 fixes the >6h trigger but leaves the
|
|
393
|
+
* duration to member states — 10 min (IT floor) to 60–120 min (PT).
|
|
394
|
+
*/
|
|
395
|
+
export interface BreakRule {
|
|
396
|
+
/** Working minutes after which the break is owed. */
|
|
397
|
+
afterMinutes: number;
|
|
398
|
+
minMinutes: number;
|
|
399
|
+
/**
|
|
400
|
+
* The entitlement is to a *paid* break, so only `ShiftTemplate.paidBreakMinutes`
|
|
401
|
+
* discharges it — an unpaid break costs the worker wages and does not.
|
|
402
|
+
* Unset, any declared break (paid or unpaid) counts.
|
|
403
|
+
*/
|
|
404
|
+
paid?: boolean;
|
|
405
|
+
/**
|
|
406
|
+
* A break the worker must stay reachable through. C-107/19 holds such a
|
|
407
|
+
* break is working time *and* does not discharge the Art 4 entitlement, so
|
|
408
|
+
* an interruptible break never satisfies this rule.
|
|
409
|
+
*/
|
|
410
|
+
interruptible?: boolean;
|
|
411
|
+
}
|
|
412
|
+
/** Rest days, Sunday and public-holiday rules. */
|
|
413
|
+
export interface RestDayRule {
|
|
414
|
+
/** e.g. Germany's 15, the Netherlands' 13. */
|
|
415
|
+
minFreeSundaysPerYear?: number;
|
|
416
|
+
/** Rolling form, e.g. Poland's one free Sunday per 4 weeks. */
|
|
417
|
+
minFreeSundaysPer?: {
|
|
418
|
+
count: number;
|
|
419
|
+
weeks: number;
|
|
420
|
+
};
|
|
421
|
+
/** Deadline for the substitute rest day Sunday or holiday work creates. */
|
|
422
|
+
compensatoryRestWithinDays?: {
|
|
423
|
+
sunday?: number;
|
|
424
|
+
holiday?: number;
|
|
425
|
+
};
|
|
426
|
+
/** Bar Sunday or holiday work outright. */
|
|
427
|
+
sundayAllowed?: boolean;
|
|
428
|
+
holidayAllowed?: boolean;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Minimum engagement. Belgium requires 3h per work session; the Netherlands
|
|
432
|
+
* pays a minimum of 3h per call and credits 30 min per call-out; Ireland owes
|
|
433
|
+
* the lesser of 25% of contracted hours or 15h. These decouple *paid* from
|
|
434
|
+
* *worked*, so they constrain shift design rather than assignment.
|
|
435
|
+
*/
|
|
436
|
+
export interface EngagementRule {
|
|
437
|
+
minShiftMinutes?: number;
|
|
438
|
+
minPaidMinutesPerEngagement?: number;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Publication and change notice — Directive (EU) 2019/1152 Art 10.
|
|
442
|
+
*
|
|
443
|
+
* Work outside the reference hours, or notified inside the notice window, may
|
|
444
|
+
* be refused without detriment; cancelling late can create a pay liability.
|
|
445
|
+
* These are facts about a *published* roster, so they need `published` on the
|
|
446
|
+
* input to mean anything.
|
|
447
|
+
*/
|
|
448
|
+
export interface NoticeRule {
|
|
449
|
+
/** The reference hours and days within which work may be required at all. */
|
|
450
|
+
referenceHours?: Array<{
|
|
451
|
+
daysOfWeek: number[];
|
|
452
|
+
from: string;
|
|
453
|
+
to: string;
|
|
454
|
+
}>;
|
|
455
|
+
/** "Reasonable" notice of an assignment. No EU number exists; member states differ. */
|
|
456
|
+
minNoticeMinutes?: number;
|
|
457
|
+
/** After this deadline, cancelling owes compensation. */
|
|
458
|
+
cancellationDeadlineMinutes?: number;
|
|
459
|
+
/** Minutes payable when an assignment is cancelled late (NL pays the called hours). */
|
|
460
|
+
cancellationCompensationMinutes?: number;
|
|
461
|
+
/** Whether a published roster may be changed at all. Finland requires consent or cause. */
|
|
462
|
+
changeAfterPublication?: 'consent' | 'cause' | 'free';
|
|
463
|
+
}
|
|
464
|
+
/** A dimension to equalise across the team. */
|
|
465
|
+
export interface FairnessRule {
|
|
466
|
+
dimension: 'minutes' | 'shifts' | 'nights' | 'weekends' | 'holidays' | 'tag';
|
|
467
|
+
/**
|
|
468
|
+
* Required when `dimension` is `'tag'`: shifts whose `shiftTypeTag` equals
|
|
469
|
+
* this are the load being equalised (e.g. spread the `'oncall'` shifts).
|
|
470
|
+
*/
|
|
471
|
+
tag?: string;
|
|
472
|
+
weight?: number;
|
|
473
|
+
/**
|
|
474
|
+
* Hard cap on the spread between the most- and least-loaded person on this
|
|
475
|
+
* dimension. Leave unset to keep fairness purely soft.
|
|
476
|
+
*/
|
|
477
|
+
hardMaxSpread?: number;
|
|
478
|
+
/** Weight each person's fair share by contracted hours rather than headcount. */
|
|
479
|
+
proRataByContract?: boolean;
|
|
480
|
+
}
|
|
481
|
+
/** A wall-clock band; `to <= from` wraps past midnight. */
|
|
482
|
+
export interface ClockRangeConfig {
|
|
483
|
+
from: string;
|
|
484
|
+
to: string;
|
|
485
|
+
}
|
|
486
|
+
/** A recurring or dated shift definition. Times are local time-of-day `HH:MM` or `HH:MM:SS`. */
|
|
487
|
+
export interface ShiftTemplate {
|
|
488
|
+
id: string;
|
|
489
|
+
name: string;
|
|
490
|
+
/** Time of day the shift starts. */
|
|
491
|
+
startTime: string;
|
|
492
|
+
/** Time of day the shift ends; `endTime <= startTime` means it runs into the next day. */
|
|
493
|
+
endTime: string;
|
|
494
|
+
/** Inclusive ISO dates this template occurs on. Mutually exclusive with `daysOfWeek`. */
|
|
495
|
+
dates?: string[];
|
|
496
|
+
/** ISO weekdays 1 (Mon) .. 7 (Sun) within the scheduling period. Mutually exclusive with `dates`. */
|
|
497
|
+
daysOfWeek?: number[];
|
|
498
|
+
/** Minimum employees that must be assigned to each occurrence. Defaults to 1. */
|
|
499
|
+
minEmployees?: number;
|
|
500
|
+
/** Per-tag minimums: at least `count` assigned employees must carry the tag. */
|
|
501
|
+
tagRequirements?: Record<string, number>;
|
|
502
|
+
/** Cap on assignees. Useful for supervision limits and to stop over-staffing. */
|
|
503
|
+
maxEmployees?: number;
|
|
504
|
+
/** Per-tag maximums, e.g. at most 2 trainees on a shift. */
|
|
505
|
+
tagMaximums?: Record<string, number>;
|
|
506
|
+
/** Tags every assignee must hold, checked against date-valid qualifications. */
|
|
507
|
+
requiredTags?: string[];
|
|
508
|
+
/**
|
|
509
|
+
* Classification tag for sequence rules — `'night'`, `'early'`, `'late'`.
|
|
510
|
+
* `ConsecutiveRule.forbiddenSuccessions` matches on this.
|
|
511
|
+
*/
|
|
512
|
+
shiftTypeTag?: string;
|
|
513
|
+
/**
|
|
514
|
+
* Unpaid break minutes inside the span. Working time is the span minus this,
|
|
515
|
+
* which is why a 9h shift with a 45-minute unpaid break is 8h15 against an
|
|
516
|
+
* hours budget — not 9h.
|
|
517
|
+
*/
|
|
518
|
+
unpaidBreakMinutes?: number;
|
|
519
|
+
/**
|
|
520
|
+
* Paid break minutes inside the span. They count as working time (no
|
|
521
|
+
* deduction), and they are what discharges a `BreakRule` with `paid: true`.
|
|
522
|
+
*/
|
|
523
|
+
paidBreakMinutes?: number;
|
|
524
|
+
/**
|
|
525
|
+
* How this duty counts as working time.
|
|
526
|
+
*
|
|
527
|
+
* The engine never infers this. Whether stand-by counts is a fact-specific
|
|
528
|
+
* legal test — on-premises stand-by counts in full even while asleep
|
|
529
|
+
* (SIMAP, Jaeger), while off-premises stand-by turns on response time and
|
|
530
|
+
* call-out frequency under an all-circumstances test the CJEU has
|
|
531
|
+
* deliberately declined to reduce to a threshold (Matzak, C-344/19,
|
|
532
|
+
* C-580/19). The caller classifies; the engine does the arithmetic.
|
|
533
|
+
*/
|
|
534
|
+
duty?: DutyClassification;
|
|
535
|
+
/** Site this shift is at, for multi-site rosters. */
|
|
536
|
+
siteId?: string;
|
|
537
|
+
}
|
|
538
|
+
/** How a duty's elapsed time converts into working time. */
|
|
539
|
+
export interface DutyClassification {
|
|
540
|
+
/**
|
|
541
|
+
* `'full'` counts the whole span (a normal shift, or on-premises stand-by).
|
|
542
|
+
* `'actualOnly'` counts only `expectedActiveMinutes`.
|
|
543
|
+
* A number between 0 and 1 counts that fraction — the usual encoding for
|
|
544
|
+
* stand-by that accrues at a percentage.
|
|
545
|
+
*/
|
|
546
|
+
countsAsWorkingTime: 'full' | 'actualOnly' | number;
|
|
547
|
+
/** Expected active minutes when `countsAsWorkingTime` is `'actualOnly'`. */
|
|
548
|
+
expectedActiveMinutes?: number;
|
|
549
|
+
/** Whether the duty still blocks the rest clock even if it barely counts as work. */
|
|
550
|
+
countsTowardRestClock?: boolean;
|
|
551
|
+
standby?: {
|
|
552
|
+
atWorkplace: boolean;
|
|
553
|
+
responseMinutes?: number;
|
|
554
|
+
avgCalloutsPerPeriod?: number;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Why it was classified this way. Echoed into the result's provenance so a
|
|
558
|
+
* roster can be defended without re-litigating the classification.
|
|
559
|
+
*/
|
|
560
|
+
classificationNote?: string;
|
|
561
|
+
}
|
|
562
|
+
/** Tunables for built-in constraints plus caller-supplied customs. */
|
|
563
|
+
export interface ConstraintOptions {
|
|
564
|
+
/**
|
|
565
|
+
* Minimum rest minutes between the end of one assignment and the start of
|
|
566
|
+
* the next. Defaults to 660 (11h), the Directive 2003/88/EC Art 3 floor.
|
|
567
|
+
*/
|
|
568
|
+
minRestMinutes?: number;
|
|
569
|
+
/**
|
|
570
|
+
* Enforce at most one shift per calendar day. Defaults to `false` — split
|
|
571
|
+
* shifts are lawful, and `no-overlap` + `min-rest` already exclude the
|
|
572
|
+
* impossible cases.
|
|
573
|
+
*/
|
|
574
|
+
oneShiftPerDay?: boolean;
|
|
575
|
+
/** Override built-in hardness/weight by constraint id. */
|
|
576
|
+
overrides?: Record<string, {
|
|
577
|
+
hardness?: 'hard' | 'soft';
|
|
578
|
+
weight?: number;
|
|
579
|
+
}>;
|
|
580
|
+
/** Additional caller-supplied constraints, evaluated alongside the built-ins. */
|
|
581
|
+
custom?: SchedulingConstraint[];
|
|
582
|
+
}
|
|
583
|
+
/** The full scheduling problem. */
|
|
584
|
+
export interface ScheduleInput {
|
|
585
|
+
/** Inclusive ISO date range, plus the zone its wall-clock times are read in. */
|
|
586
|
+
period: {
|
|
587
|
+
startDate: string;
|
|
588
|
+
endDate: string;
|
|
589
|
+
timeZone?: string;
|
|
590
|
+
};
|
|
591
|
+
employees: Employee[];
|
|
592
|
+
shifts: ShiftTemplate[];
|
|
593
|
+
objective?: 'standard' | 'balanced';
|
|
594
|
+
/** Weights of optional soft-objective terms. Omitted terms stay out of the solve. */
|
|
595
|
+
objectives?: ObjectiveWeights;
|
|
596
|
+
constraints?: ConstraintOptions;
|
|
597
|
+
/** Seed for reproducible runs. */
|
|
598
|
+
seed?: number;
|
|
599
|
+
/** Wall-clock budget for the improvement loop. Default 10_000. */
|
|
600
|
+
timeBudgetMs?: number;
|
|
601
|
+
/** The labour-law layer. Omit for a plain feasibility solve. */
|
|
602
|
+
rules?: WorkingTimeRules;
|
|
603
|
+
/** Public holidays and closures, as ISO dates. */
|
|
604
|
+
calendar?: {
|
|
605
|
+
publicHolidays?: string[];
|
|
606
|
+
closedDates?: string[];
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Assignments from before the period, used to seed rest and rolling
|
|
610
|
+
* windows. Without them the first days of every period are non-compliant by
|
|
611
|
+
* construction, because an 11h rest rule cannot see the shift that ended at
|
|
612
|
+
* 06:00 on day one.
|
|
613
|
+
*/
|
|
614
|
+
history?: HistoricalAssignment[];
|
|
615
|
+
/** A published roster, which anchors the notice clock and the perturbation objective. */
|
|
616
|
+
published?: {
|
|
617
|
+
roster: ScheduledAssignment[];
|
|
618
|
+
publishedAt?: string;
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
* The instant this solve or compliance run represents, as an ISO date or
|
|
622
|
+
* date-time. It anchors deadline arithmetic that needs a "now" — notably
|
|
623
|
+
* whether cancelling a published assignment fell inside
|
|
624
|
+
* `notice.cancellationDeadlineMinutes` of the shift's start. Omitted, every
|
|
625
|
+
* cancellation is treated as late (the conservative reading). Caller-supplied
|
|
626
|
+
* so runs stay deterministic and replayable.
|
|
627
|
+
*/
|
|
628
|
+
asOf?: string;
|
|
629
|
+
/** Pairs the solver may not move. */
|
|
630
|
+
pinned?: AssignmentPair[];
|
|
631
|
+
/** Absences that block assignment and may be neutral in rolling averages. */
|
|
632
|
+
absences?: Array<{
|
|
633
|
+
employeeId: string;
|
|
634
|
+
from: string;
|
|
635
|
+
to: string;
|
|
636
|
+
kind?: string;
|
|
637
|
+
}>;
|
|
638
|
+
/** Called with the best roster so far as the search improves it. */
|
|
639
|
+
onProgress?: (best: ScheduleResult) => void;
|
|
640
|
+
}
|
|
641
|
+
/** An assignment from before the period start, treated as immutable context. */
|
|
642
|
+
export interface HistoricalAssignment {
|
|
643
|
+
employeeId: string;
|
|
644
|
+
/** ISO date the duty started on; may precede `period.startDate`. */
|
|
645
|
+
date: string;
|
|
646
|
+
startTime: string;
|
|
647
|
+
endTime: string;
|
|
648
|
+
/** Working minutes, if they differ from the elapsed span. */
|
|
649
|
+
workingMinutes?: number;
|
|
650
|
+
shiftTypeTag?: string;
|
|
651
|
+
id?: string;
|
|
652
|
+
}
|
|
653
|
+
/** One rostered (employee, shift occurrence) pair. */
|
|
654
|
+
export interface ScheduledAssignment {
|
|
655
|
+
shiftInstanceId: string;
|
|
656
|
+
employeeId: string;
|
|
657
|
+
/** ISO date of the shift occurrence (its start day). */
|
|
658
|
+
date: string;
|
|
659
|
+
/** Human-readable reasons produced by the constraint layer. */
|
|
660
|
+
reasons: string[];
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Lexicographic severity levels.
|
|
664
|
+
*
|
|
665
|
+
* They are compared in order, not summed: no quantity of `soft` improvement can
|
|
666
|
+
* buy a single `hard` breach. A weighted sum would let a large enough cost
|
|
667
|
+
* saving purchase a rest violation, which is not a trade the law permits.
|
|
668
|
+
*
|
|
669
|
+
* `hard` = legally or physically impossible. `medium` = coverage shortfalls.
|
|
670
|
+
* `soft` = cost, fairness, preferences.
|
|
671
|
+
*/
|
|
672
|
+
export type Severity = 'hard' | 'medium' | 'soft';
|
|
673
|
+
/** A constraint breach that survived into the returned schedule. */
|
|
674
|
+
export interface ConstraintViolation {
|
|
675
|
+
constraintId: string;
|
|
676
|
+
severity: Severity;
|
|
677
|
+
message: string;
|
|
678
|
+
shiftInstanceId?: string;
|
|
679
|
+
employeeId?: string;
|
|
680
|
+
/** Legal source, echoed from the rule that produced it. */
|
|
681
|
+
citation?: string;
|
|
682
|
+
/** The measured value and the bound it broke, for machine-readable reports. */
|
|
683
|
+
actual?: number;
|
|
684
|
+
required?: number;
|
|
685
|
+
unit?: string;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* A single rule's structured judgement on one candidate assignment.
|
|
689
|
+
*
|
|
690
|
+
* The same type answers "why can't Anna work this shift?", validates a proposed
|
|
691
|
+
* swap, and populates the violation report — so the score and the explanation
|
|
692
|
+
* can never drift apart, which they do as soon as they have separate code paths.
|
|
693
|
+
*/
|
|
694
|
+
export interface RuleVerdict {
|
|
695
|
+
ruleId: string;
|
|
696
|
+
pass: boolean;
|
|
697
|
+
severity: Severity;
|
|
698
|
+
/** Measured value, e.g. rest actually available. */
|
|
699
|
+
actual?: number;
|
|
700
|
+
/** Bound it was measured against. */
|
|
701
|
+
required?: number;
|
|
702
|
+
unit?: 'minutes' | 'hours' | 'count' | 'days';
|
|
703
|
+
message: string;
|
|
704
|
+
citation?: string;
|
|
705
|
+
}
|
|
706
|
+
/** The outcome of a solve. `'optimal'` means "no known improvement", never a proof. */
|
|
707
|
+
export interface ScheduleResult {
|
|
708
|
+
status: 'optimal' | 'feasible' | 'partial';
|
|
709
|
+
assignments: ScheduledAssignment[];
|
|
710
|
+
violations: ConstraintViolation[];
|
|
711
|
+
stats: {
|
|
712
|
+
evaluatedVariants: number;
|
|
713
|
+
durationMs: number;
|
|
714
|
+
unfilledSlots: number;
|
|
715
|
+
};
|
|
716
|
+
/**
|
|
717
|
+
* What produced this roster. Reproducibility is an audit requirement:
|
|
718
|
+
* "the roster was lawful under the rules as they stood" is the defence, and
|
|
719
|
+
* it needs the rules and weights to be identifiable after the fact. In
|
|
720
|
+
* Germany the objective weights are themselves co-determination subject
|
|
721
|
+
* matter (BetrVG §87(1)), not internal tuning.
|
|
722
|
+
*/
|
|
723
|
+
provenance?: ScheduleProvenance;
|
|
724
|
+
/** Deferred obligations the roster created, such as compensatory rest owed. */
|
|
725
|
+
ledger?: LedgerEntry[];
|
|
726
|
+
/** Per-person cost breakdown when a cost model was supplied. */
|
|
727
|
+
cost?: {
|
|
728
|
+
totalCents: number;
|
|
729
|
+
byEmployee: Record<string, number>;
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
/** Identifying stamp for a solve. */
|
|
733
|
+
export interface ScheduleProvenance {
|
|
734
|
+
engineVersion: string;
|
|
735
|
+
seed: number;
|
|
736
|
+
rulesHash: string;
|
|
737
|
+
/** Duty classifications the caller supplied, recorded verbatim. */
|
|
738
|
+
dutyClassificationNotes?: Record<string, string>;
|
|
739
|
+
/**
|
|
740
|
+
* True when no behavioural or predictive per-worker signal fed the
|
|
741
|
+
* allocation. Allocating on declared qualifications, availability, legal
|
|
742
|
+
* limits, cost and realised counts is a constraint solve; adding
|
|
743
|
+
* reliability or no-show prediction makes it profiling, which is
|
|
744
|
+
* unconditionally high-risk under AI Act Annex III point 4(b).
|
|
745
|
+
*/
|
|
746
|
+
profilingFree: boolean;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Weights of optional soft-objective terms.
|
|
750
|
+
*
|
|
751
|
+
* These are co-determination subject matter in some member states (BetrVG
|
|
752
|
+
* §87(1)), so they live on the input — versioned and hashed with the rules —
|
|
753
|
+
* rather than being internal tuning.
|
|
754
|
+
*/
|
|
755
|
+
export interface ObjectiveWeights {
|
|
756
|
+
/**
|
|
757
|
+
* Soft-score points per euro of projected labour cost. Any positive value
|
|
758
|
+
* makes the solver prefer cheaper rosters *within* the soft level — it can
|
|
759
|
+
* never buy a hard or coverage breach, because levels are lexicographic.
|
|
760
|
+
* Unset or 0 leaves cost out of the solve; ranking and the result's cost
|
|
761
|
+
* summary still use the cost model either way.
|
|
762
|
+
*/
|
|
763
|
+
costWeightPerEuro?: number;
|
|
764
|
+
}
|
|
765
|
+
/** A dated obligation created by an assignment. */
|
|
766
|
+
export interface LedgerEntry {
|
|
767
|
+
kind: 'compensatoryRest' | 'substituteRestDay' | 'lateCancellationPay' | 'timeOffInLieu';
|
|
768
|
+
employeeId: string;
|
|
769
|
+
minutes?: number;
|
|
770
|
+
/** ISO date by which the obligation must be discharged. */
|
|
771
|
+
dueBy?: string;
|
|
772
|
+
reason: string;
|
|
773
|
+
citation?: string;
|
|
774
|
+
}
|
|
775
|
+
/** Thrown synchronously by the facade for malformed input (bad dates, negative budgets, …). */
|
|
776
|
+
export declare class ScheduleValidationError extends Error {
|
|
777
|
+
constructor(message: string);
|
|
778
|
+
}
|
|
779
|
+
/** One expanded, dated occurrence of a shift template. */
|
|
780
|
+
export interface ShiftInstance {
|
|
781
|
+
/** Unique id: `<templateId>@<date>`. */
|
|
782
|
+
id: string;
|
|
783
|
+
templateId: string;
|
|
784
|
+
name: string;
|
|
785
|
+
/** ISO date the shift starts on. */
|
|
786
|
+
date: string;
|
|
787
|
+
/** Minutes since period epoch (midnight of `period.startDate`) when the shift starts. */
|
|
788
|
+
startMinute: number;
|
|
789
|
+
/** Minutes since period epoch when the shift ends; may exceed 24h for overnight shifts. */
|
|
790
|
+
endMinute: number;
|
|
791
|
+
/** Elapsed duration in minutes, always positive. */
|
|
792
|
+
durationMinutes: number;
|
|
793
|
+
minEmployees: number;
|
|
794
|
+
tagRequirements: Record<string, number>;
|
|
795
|
+
/**
|
|
796
|
+
* Minutes that count as working time — the span less unpaid breaks, scaled
|
|
797
|
+
* by the duty classification. Hour budgets and rolling averages use this;
|
|
798
|
+
* rest gaps use `startMinute`/`endMinute`, because a duty can occupy the
|
|
799
|
+
* clock without counting as work.
|
|
800
|
+
*/
|
|
801
|
+
workingMinutes: number;
|
|
802
|
+
/** Paid break minutes declared by the template. Count as working time. */
|
|
803
|
+
paidBreakMinutes: number;
|
|
804
|
+
maxEmployees?: number;
|
|
805
|
+
tagMaximums: Record<string, number>;
|
|
806
|
+
requiredTags: string[];
|
|
807
|
+
shiftTypeTag?: string;
|
|
808
|
+
siteId?: string;
|
|
809
|
+
duty?: DutyClassification;
|
|
810
|
+
/** Minutes of this occurrence falling inside the configured night band. */
|
|
811
|
+
nightMinutes: number;
|
|
812
|
+
/** Whether it counts as a night shift under `NightWorkRule.qualifiesAfterMinutes`. */
|
|
813
|
+
isNightShift: boolean;
|
|
814
|
+
/** ISO weekday 1..7 of the start day. */
|
|
815
|
+
weekday: number;
|
|
816
|
+
isSunday: boolean;
|
|
817
|
+
isPublicHoliday: boolean;
|
|
818
|
+
}
|
|
819
|
+
/** The normalized, fully-indexed problem the engine and constraints operate on. */
|
|
820
|
+
export interface ModelContext {
|
|
821
|
+
periodStartDate: string;
|
|
822
|
+
periodDays: number;
|
|
823
|
+
employees: Employee[];
|
|
824
|
+
employeeById: Map<string, Employee>;
|
|
825
|
+
employeeTags: Map<string, Set<string>>;
|
|
826
|
+
instances: ShiftInstance[];
|
|
827
|
+
instanceById: Map<string, ShiftInstance>;
|
|
828
|
+
/** Minutes in [0, periodDays*1440) the employee is blocked by time-off. */
|
|
829
|
+
employeeBlockedIntervals: Map<string, Array<{
|
|
830
|
+
start: number;
|
|
831
|
+
end: number;
|
|
832
|
+
}>>;
|
|
833
|
+
minRestMinutes: number;
|
|
834
|
+
/** Constraint registry snapshot, resolved with caller overrides. */
|
|
835
|
+
constraints: SchedulingConstraint[];
|
|
836
|
+
/** DST-correct wall-clock resolver for the roster's zone. */
|
|
837
|
+
clock: PeriodClock;
|
|
838
|
+
/** Rules after merging the global set with each person's overrides. */
|
|
839
|
+
rules: WorkingTimeRules;
|
|
840
|
+
rulesByEmployee: Map<string, WorkingTimeRules>;
|
|
841
|
+
/** Employee id → the natural person it belongs to (CJEU C-585/19). */
|
|
842
|
+
personIdOf: Map<string, string>;
|
|
843
|
+
/** Person id → the employee records that share it. */
|
|
844
|
+
employeesOfPerson: Map<string, string[]>;
|
|
845
|
+
/** Pre-period assignments, keyed by person, at negative period minutes. */
|
|
846
|
+
history: Map<string, TimelineEntry[]>;
|
|
847
|
+
publicHolidays: Set<string>;
|
|
848
|
+
/** Absence spans per employee, with the kind that drives averaging neutrality. */
|
|
849
|
+
absences: Map<string, Array<{
|
|
850
|
+
start: number;
|
|
851
|
+
end: number;
|
|
852
|
+
kind?: string;
|
|
853
|
+
}>>;
|
|
854
|
+
pinned: Set<string>;
|
|
855
|
+
/** Period minutes the roster was published, when a published roster was supplied. */
|
|
856
|
+
publishedAtMinute?: number;
|
|
857
|
+
publishedPairs: Set<string>;
|
|
858
|
+
/** Period minutes of `ScheduleInput.asOf`, when supplied. */
|
|
859
|
+
asOfMinute?: number;
|
|
860
|
+
}
|
|
861
|
+
/** A candidate (employee, shiftInstance) pair under evaluation. */
|
|
862
|
+
export interface AssignmentPair {
|
|
863
|
+
employeeId: string;
|
|
864
|
+
shiftInstanceId: string;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Mutable search state shared with constraints for delta/explain evaluation.
|
|
868
|
+
* The engine keeps these structures consistent on every assign/unassign.
|
|
869
|
+
*/
|
|
870
|
+
export interface SearchState {
|
|
871
|
+
ctx: ModelContext;
|
|
872
|
+
/** instanceId -> set of assigned employee ids. */
|
|
873
|
+
assignments: Map<string, Set<string>>;
|
|
874
|
+
/** employeeId -> assigned instance ids. */
|
|
875
|
+
byEmployee: Map<string, Set<string>>;
|
|
876
|
+
/** employeeId -> total assigned minutes in the period. */
|
|
877
|
+
minutesByEmployee: Map<string, number>;
|
|
878
|
+
/** Whether `(employeeId, instanceId)` is currently assigned. */
|
|
879
|
+
isAssigned(employeeId: string, instanceId: string): boolean;
|
|
880
|
+
/**
|
|
881
|
+
* Per-person timelines, history included, kept in step with every
|
|
882
|
+
* assign/unassign. Window rules read them instead of rebuilding a person's
|
|
883
|
+
* schedule from `byEmployee` on each evaluation.
|
|
884
|
+
*/
|
|
885
|
+
timelines: TimelineIndex;
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* A self-contained scheduling rule. Built-ins ship in `constraints/`; callers
|
|
889
|
+
* may register customs via `ConstraintOptions.custom`. A constraint must be
|
|
890
|
+
* pure with respect to the passed-in state — the engine owns all mutation.
|
|
891
|
+
*/
|
|
892
|
+
export interface SchedulingConstraint {
|
|
893
|
+
id: string;
|
|
894
|
+
/**
|
|
895
|
+
* Lexicographic level. `'hard'` breaches are never accepted by construction;
|
|
896
|
+
* `'medium'` and `'soft'` are traded off within their own level by `weight`.
|
|
897
|
+
*/
|
|
898
|
+
hardness: Severity;
|
|
899
|
+
/** Drives soft/medium score contribution, violation severity and repair priority. */
|
|
900
|
+
weight?: number;
|
|
901
|
+
/** Legal source, echoed into every violation and verdict this rule produces. */
|
|
902
|
+
citation?: string;
|
|
903
|
+
/** Prune ineligible (employee, shiftInstance) pairs before search, in place on `eligibility`. */
|
|
904
|
+
prune?(ctx: ModelContext, eligibility: Map<string, Set<string>>): void;
|
|
905
|
+
/**
|
|
906
|
+
* Breach magnitude of assigning `pair` in `state`: 0 when compliant,
|
|
907
|
+
* positive otherwise.
|
|
908
|
+
*
|
|
909
|
+
* Return *how far* over the line the assignment is, not a 0/1 flag, where
|
|
910
|
+
* that is meaningful — a rest gap 10 minutes short and one 6 hours short are
|
|
911
|
+
* both breaches, but only a graded signal lets local search climb out of an
|
|
912
|
+
* infeasible region instead of sitting on a plateau.
|
|
913
|
+
*/
|
|
914
|
+
delta(state: SearchState, pair: AssignmentPair): number;
|
|
915
|
+
/**
|
|
916
|
+
* Breach magnitude *removed* by unassigning `pair`. Defaults to `delta` when
|
|
917
|
+
* absent, which is right for symmetric rules; rules whose breach depends on
|
|
918
|
+
* the surrounding sequence should implement it.
|
|
919
|
+
*/
|
|
920
|
+
deltaRemove?(state: SearchState, pair: AssignmentPair): number;
|
|
921
|
+
/**
|
|
922
|
+
* Breaches visible only across the whole roster — staffing shortfalls,
|
|
923
|
+
* per-person window totals, team fairness spread. Pair-scoped `delta`
|
|
924
|
+
* cannot see these.
|
|
925
|
+
*/
|
|
926
|
+
evaluate?(state: SearchState): ConstraintViolation[];
|
|
927
|
+
/** Structured judgement for explanations and swap validation. */
|
|
928
|
+
verdict?(state: SearchState, pair: AssignmentPair): RuleVerdict;
|
|
929
|
+
/** Human-readable breach description for the violation report, or null when compliant. */
|
|
930
|
+
explain(state: SearchState, pair: AssignmentPair): string | null;
|
|
931
|
+
}
|
|
932
|
+
//# sourceMappingURL=types.d.ts.map
|