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,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Contract limits.
|
|
4
|
+
*
|
|
5
|
+
* Two shapes:
|
|
6
|
+
*
|
|
7
|
+
* - **Hours contracts** carry period bounds in minutes, which sit alongside
|
|
8
|
+
* the statutory limits rather than replacing them — a contract may be
|
|
9
|
+
* stricter than the law but never looser.
|
|
10
|
+
* - **Day-count contracts** have no hours limit at all. The French
|
|
11
|
+
* *forfait jours* fixes 218 working *days* a year for autonomous staff, and
|
|
12
|
+
* the daily and weekly hour caps do not apply to them — but the 11h daily
|
|
13
|
+
* and 35h weekly rest still do. Modelling that as a very large hours budget
|
|
14
|
+
* would be wrong in both directions, so it gets its own counter.
|
|
15
|
+
*
|
|
16
|
+
* A contract end date also bounds eligibility: a fixed-term worker cannot be
|
|
17
|
+
* rostered past their last day, which is easy to miss when the roster period
|
|
18
|
+
* outruns the contract.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.contractLimits = void 0;
|
|
22
|
+
const support_1 = require("./support");
|
|
23
|
+
function contractLimits() {
|
|
24
|
+
const constraint = (0, support_1.fromVerdict)({
|
|
25
|
+
id: 'contract',
|
|
26
|
+
hardness: 'hard',
|
|
27
|
+
weight: 1,
|
|
28
|
+
prune(ctx, eligibility) {
|
|
29
|
+
for (const [employeeId, instances] of eligibility) {
|
|
30
|
+
const endDate = ctx.employeeById.get(employeeId)?.contract?.endDate;
|
|
31
|
+
if (!endDate)
|
|
32
|
+
continue;
|
|
33
|
+
for (const instanceId of [...instances]) {
|
|
34
|
+
const inst = ctx.instanceById.get(instanceId);
|
|
35
|
+
if (inst && inst.date > endDate)
|
|
36
|
+
instances.delete(instanceId);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
verdict(state, pair) {
|
|
41
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
42
|
+
const contract = state.ctx.employeeById.get(pair.employeeId)?.contract;
|
|
43
|
+
if (!inst || !contract)
|
|
44
|
+
return (0, support_1.pass)('contract', 'no contract limits');
|
|
45
|
+
if (contract.endDate && inst.date > contract.endDate) {
|
|
46
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}"'s contract ends ${contract.endDate}, before "${inst.id}"`);
|
|
47
|
+
}
|
|
48
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
49
|
+
const probe = {
|
|
50
|
+
start: inst.startMinute,
|
|
51
|
+
end: inst.endMinute,
|
|
52
|
+
id: `${pair.employeeId}@@${pair.shiftInstanceId}`,
|
|
53
|
+
workingMinutes: inst.workingMinutes,
|
|
54
|
+
};
|
|
55
|
+
return timeline.withEntry(probe, (t) => {
|
|
56
|
+
const periodWindow = { start: 0, end: state.ctx.periodDays * support_1.MINUTES_PER_DAY };
|
|
57
|
+
if (contract.kind === 'days' && contract.maxDaysInPeriod !== undefined) {
|
|
58
|
+
const days = new Set(t.entriesIn(periodWindow).map((e) => state.ctx.clock.dayIndexOfMinute(e.start)))
|
|
59
|
+
.size;
|
|
60
|
+
if (days > contract.maxDaysInPeriod) {
|
|
61
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}" would work ${days} days, over their ${contract.maxDaysInPeriod}-day contract`, { actual: days, required: contract.maxDaysInPeriod, unit: 'days' });
|
|
62
|
+
}
|
|
63
|
+
// Day-count contracts are deliberately silent on hours.
|
|
64
|
+
return (0, support_1.pass)('contract', `${days} of ${contract.maxDaysInPeriod} contract days used`, {
|
|
65
|
+
actual: days,
|
|
66
|
+
required: contract.maxDaysInPeriod,
|
|
67
|
+
unit: 'days',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (contract.maxPeriodMinutes !== undefined) {
|
|
71
|
+
const worked = t.workingMinutesIn(periodWindow);
|
|
72
|
+
if (worked > contract.maxPeriodMinutes) {
|
|
73
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}" would work ${(0, support_1.h)(worked)}, over their ${(0, support_1.h)(contract.maxPeriodMinutes)} contract maximum`, { actual: worked, required: contract.maxPeriodMinutes, unit: 'minutes' });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return (0, support_1.pass)('contract', 'within contract limits');
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
// A minimum is only judgeable on the finished roster: every partial roster
|
|
81
|
+
// is below it by construction, so it cannot be a per-pair rule without
|
|
82
|
+
// blocking the very assignments that would satisfy it.
|
|
83
|
+
constraint.evaluate = (state) => {
|
|
84
|
+
const out = [];
|
|
85
|
+
for (const employee of state.ctx.employees) {
|
|
86
|
+
const contract = employee.contract;
|
|
87
|
+
if (!contract || contract.kind === 'days' || contract.minPeriodMinutes === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
const worked = state.minutesByEmployee.get(employee.id) ?? 0;
|
|
90
|
+
if (worked >= contract.minPeriodMinutes)
|
|
91
|
+
continue;
|
|
92
|
+
out.push({
|
|
93
|
+
constraintId: 'contract',
|
|
94
|
+
severity: 'hard',
|
|
95
|
+
employeeId: employee.id,
|
|
96
|
+
message: `employee "${employee.id}" is rostered ${(0, support_1.h)(worked)}, below their ${(0, support_1.h)(contract.minPeriodMinutes)} contract minimum`,
|
|
97
|
+
actual: worked,
|
|
98
|
+
required: contract.minPeriodMinutes,
|
|
99
|
+
unit: 'minutes',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
};
|
|
104
|
+
return constraint;
|
|
105
|
+
}
|
|
106
|
+
exports.contractLimits = contractLimits;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Labour cost as a soft objective term.
|
|
3
|
+
*
|
|
4
|
+
* Opt-in via `ScheduleInput.objectives.costWeightPerEuro`. The term contributes
|
|
5
|
+
* `euros × weight` per assignment to the *soft* level, so the solver prefers
|
|
6
|
+
* cheaper rosters among otherwise-equal ones — and can never buy a hard breach
|
|
7
|
+
* or an unfilled slot with a cost saving, because levels are lexicographic. That
|
|
8
|
+
* ordering is the legal point: "minimise cost" is a legitimate objective only
|
|
9
|
+
* inside the space of lawful, covered rosters.
|
|
10
|
+
*
|
|
11
|
+
* This is not a rule and never fails: its verdict always passes, so it produces
|
|
12
|
+
* no violations — only score. The arithmetic is `cost.ts`'s, shared with the
|
|
13
|
+
* repair ranking and the result's cost summary, so the number the solver
|
|
14
|
+
* minimises is the number the manager is shown.
|
|
15
|
+
*/
|
|
16
|
+
import type { SchedulingConstraint } from '../types';
|
|
17
|
+
export declare function costObjective(weightPerEuro: number): SchedulingConstraint;
|
|
18
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAkB,oBAAoB,EAAe,MAAM,UAAU,CAAC;AAGlF,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,oBAAoB,CAuBzE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Labour cost as a soft objective term.
|
|
4
|
+
*
|
|
5
|
+
* Opt-in via `ScheduleInput.objectives.costWeightPerEuro`. The term contributes
|
|
6
|
+
* `euros × weight` per assignment to the *soft* level, so the solver prefers
|
|
7
|
+
* cheaper rosters among otherwise-equal ones — and can never buy a hard breach
|
|
8
|
+
* or an unfilled slot with a cost saving, because levels are lexicographic. That
|
|
9
|
+
* ordering is the legal point: "minimise cost" is a legitimate objective only
|
|
10
|
+
* inside the space of lawful, covered rosters.
|
|
11
|
+
*
|
|
12
|
+
* This is not a rule and never fails: its verdict always passes, so it produces
|
|
13
|
+
* no violations — only score. The arithmetic is `cost.ts`'s, shared with the
|
|
14
|
+
* repair ranking and the result's cost summary, so the number the solver
|
|
15
|
+
* minimises is the number the manager is shown.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.costObjective = void 0;
|
|
19
|
+
const cost_1 = require("../cost");
|
|
20
|
+
function costObjective(weightPerEuro) {
|
|
21
|
+
return {
|
|
22
|
+
id: 'cost',
|
|
23
|
+
hardness: 'soft',
|
|
24
|
+
weight: weightPerEuro,
|
|
25
|
+
delta(state, pair) {
|
|
26
|
+
return pairCostCents(state, pair) / 100;
|
|
27
|
+
},
|
|
28
|
+
verdict(state, pair) {
|
|
29
|
+
const cents = pairCostCents(state, pair);
|
|
30
|
+
return {
|
|
31
|
+
ruleId: 'cost',
|
|
32
|
+
pass: true,
|
|
33
|
+
severity: 'soft',
|
|
34
|
+
actual: cents,
|
|
35
|
+
unit: 'count',
|
|
36
|
+
message: `costs €${(cents / 100).toFixed(2)}${cents === 0 ? ' (no cost model)' : ''}`,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
explain() {
|
|
40
|
+
return null;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.costObjective = costObjective;
|
|
45
|
+
/**
|
|
46
|
+
* The pair's share of its employee's labour cost.
|
|
47
|
+
*
|
|
48
|
+
* For an assigned pair the overtime surcharge is allocated across the person's
|
|
49
|
+
* shifts pro rata by working minutes, so the shares sum exactly to the payroll;
|
|
50
|
+
* for a candidate not yet assigned it is the true marginal cost of adding it.
|
|
51
|
+
*/
|
|
52
|
+
function pairCostCents(state, pair) {
|
|
53
|
+
const employee = state.ctx.employeeById.get(pair.employeeId);
|
|
54
|
+
const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
|
|
55
|
+
if (!employee?.cost?.hourlyRateCents || !inst)
|
|
56
|
+
return 0;
|
|
57
|
+
const worked = state.minutesByEmployee.get(pair.employeeId) ?? 0;
|
|
58
|
+
if (!state.isAssigned(pair.employeeId, pair.shiftInstanceId)) {
|
|
59
|
+
return (0, cost_1.marginalCostCents)(inst, employee, worked, state.ctx.rules.engagement);
|
|
60
|
+
}
|
|
61
|
+
const base = (0, cost_1.shiftCostCents)(inst, employee.cost, state.ctx.rules.engagement);
|
|
62
|
+
const surcharge = (0, cost_1.overtimeSurchargeCents)(worked, employee.cost);
|
|
63
|
+
const share = worked > 0 ? (surcharge * inst.workingMinutes) / worked : 0;
|
|
64
|
+
return base + share;
|
|
65
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daily rest — Directive 2003/88/EC Art 3 and its national variants.
|
|
3
|
+
*
|
|
4
|
+
* The EU floor is 11 consecutive hours per 24-hour period; Spain and Romania
|
|
5
|
+
* require 12, Finnish period work allows 9. Derogations under Art 17/18 may
|
|
6
|
+
* reduce it further (8h in NL/DK/CZ, 9h in FR by collective agreement) but only
|
|
7
|
+
* against equivalent compensatory rest — which Jaeger (C-151/02) requires
|
|
8
|
+
* "immediately following" the period worked, and which never licenses breaching
|
|
9
|
+
* the weekly hours cap.
|
|
10
|
+
*
|
|
11
|
+
* Three shapes national law takes that a naive "gap between consecutive shifts"
|
|
12
|
+
* check cannot express, all handled here:
|
|
13
|
+
*
|
|
14
|
+
* - the rest must fit in *every rolling 24h*, not merely between two shifts;
|
|
15
|
+
* - a reduction may be used only so many times per window (NL: once per 7×24h);
|
|
16
|
+
* - the rest may have to *contain* a clock band — Sweden requires the 11h to
|
|
17
|
+
* include 00:00–05:00, which is positional, not a duration at all.
|
|
18
|
+
*/
|
|
19
|
+
import type { DailyRestRule, SchedulingConstraint } from '../types';
|
|
20
|
+
export declare const DAILY_REST_CITATION = "Directive 2003/88/EC Art 3";
|
|
21
|
+
export declare function dailyRest(rule: DailyRestRule): SchedulingConstraint;
|
|
22
|
+
//# sourceMappingURL=daily-rest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daily-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/daily-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAe,oBAAoB,EAA+B,MAAM,UAAU,CAAC;AAG9G,eAAO,MAAM,mBAAmB,+BAA+B,CAAC;AAEhE,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,oBAAoB,CA0FnE"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Daily rest — Directive 2003/88/EC Art 3 and its national variants.
|
|
4
|
+
*
|
|
5
|
+
* The EU floor is 11 consecutive hours per 24-hour period; Spain and Romania
|
|
6
|
+
* require 12, Finnish period work allows 9. Derogations under Art 17/18 may
|
|
7
|
+
* reduce it further (8h in NL/DK/CZ, 9h in FR by collective agreement) but only
|
|
8
|
+
* against equivalent compensatory rest — which Jaeger (C-151/02) requires
|
|
9
|
+
* "immediately following" the period worked, and which never licenses breaching
|
|
10
|
+
* the weekly hours cap.
|
|
11
|
+
*
|
|
12
|
+
* Three shapes national law takes that a naive "gap between consecutive shifts"
|
|
13
|
+
* check cannot express, all handled here:
|
|
14
|
+
*
|
|
15
|
+
* - the rest must fit in *every rolling 24h*, not merely between two shifts;
|
|
16
|
+
* - a reduction may be used only so many times per window (NL: once per 7×24h);
|
|
17
|
+
* - the rest may have to *contain* a clock band — Sweden requires the 11h to
|
|
18
|
+
* include 00:00–05:00, which is positional, not a duration at all.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.dailyRest = exports.DAILY_REST_CITATION = void 0;
|
|
22
|
+
const support_1 = require("./support");
|
|
23
|
+
exports.DAILY_REST_CITATION = 'Directive 2003/88/EC Art 3';
|
|
24
|
+
function dailyRest(rule) {
|
|
25
|
+
const windowMinutes = rule.perWindowMinutes ?? support_1.MINUTES_PER_DAY;
|
|
26
|
+
// A permitted derogation moves the effective floor down; the allowance on
|
|
27
|
+
// how often it may be used is enforced separately below.
|
|
28
|
+
const floor = rule.reducibleToMinutes ?? rule.minMinutes;
|
|
29
|
+
return (0, support_1.fromVerdict)({
|
|
30
|
+
id: 'daily-rest',
|
|
31
|
+
hardness: 'hard',
|
|
32
|
+
weight: 1,
|
|
33
|
+
citation: exports.DAILY_REST_CITATION,
|
|
34
|
+
verdict(state, pair) {
|
|
35
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
36
|
+
if (!inst)
|
|
37
|
+
return (0, support_1.pass)('daily-rest', 'unknown shift');
|
|
38
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
39
|
+
const range = (0, support_1.rangeOf)(inst);
|
|
40
|
+
const gap = timeline.minGapAround(range, (0, support_1.entryIdOf)(pair));
|
|
41
|
+
if (gap === 0) {
|
|
42
|
+
// Overlapping work is `no-overlap`'s business; reporting it here
|
|
43
|
+
// too would double-count the same defect.
|
|
44
|
+
return (0, support_1.pass)('daily-rest', 'overlap is handled by no-overlap');
|
|
45
|
+
}
|
|
46
|
+
if (gap < floor) {
|
|
47
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}" would get ${(0, support_1.h)(gap)} rest around "${inst.id}", below the ${(0, support_1.h)(floor)} minimum`, { actual: gap, required: floor, unit: 'minutes', citation: exports.DAILY_REST_CITATION });
|
|
48
|
+
}
|
|
49
|
+
// Art 3 is "per 24-hour period", not "between two shifts". The gap
|
|
50
|
+
// check above misses the case where several duties in one day each
|
|
51
|
+
// leave an acceptable gap but no single stretch of rest reaches the
|
|
52
|
+
// minimum — a 14h duty inside a 24h window cannot yield 11h off,
|
|
53
|
+
// however comfortable the gaps either side of it are.
|
|
54
|
+
const rolling = timeline.withEntry({ ...range, id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes }, (t) => t.minLongestRestInAnyWindow(windowMinutes, {
|
|
55
|
+
start: range.start - windowMinutes,
|
|
56
|
+
end: range.end + windowMinutes,
|
|
57
|
+
}));
|
|
58
|
+
if (rolling < floor) {
|
|
59
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}" would have only ${(0, support_1.h)(rolling)} continuous rest in some ${(0, support_1.h)(windowMinutes)} window, below the ${(0, support_1.h)(floor)} minimum`, { actual: rolling, required: floor, unit: 'minutes', citation: exports.DAILY_REST_CITATION });
|
|
60
|
+
}
|
|
61
|
+
// Between the reduced floor and the nominal minimum the assignment
|
|
62
|
+
// is lawful only if a reduction allowance is left.
|
|
63
|
+
if (gap < rule.minMinutes && rule.reductionsPer) {
|
|
64
|
+
const used = countReductions(state, pair, rule);
|
|
65
|
+
if (used > rule.reductionsPer.max) {
|
|
66
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}" would use a ${(0, support_1.h)(gap)} reduced rest more than ${rule.reductionsPer.max} time(s) per ${rule.reductionsPer.windowDays} days`, { actual: used, required: rule.reductionsPer.max, unit: 'count', citation: exports.DAILY_REST_CITATION });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (rule.mustContainClockRange) {
|
|
70
|
+
const intrusion = state.ctx.clock.minutesInClockRange(range, rule.mustContainClockRange);
|
|
71
|
+
if (intrusion > 0) {
|
|
72
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}"'s rest must cover ${rule.mustContainClockRange.from}-${rule.mustContainClockRange.to}, but "${inst.id}" works ${(0, support_1.h)(intrusion)} inside it`, { actual: intrusion, required: 0, unit: 'minutes', citation: exports.DAILY_REST_CITATION });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return (0, support_1.pass)('daily-rest', `${(0, support_1.h)(gap)} rest, at or above the ${(0, support_1.h)(rule.minMinutes)} minimum`, {
|
|
76
|
+
actual: gap,
|
|
77
|
+
required: rule.minMinutes,
|
|
78
|
+
unit: 'minutes',
|
|
79
|
+
citation: exports.DAILY_REST_CITATION,
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.dailyRest = dailyRest;
|
|
85
|
+
/**
|
|
86
|
+
* How many reduced rest periods fall in the allowance window, counting the
|
|
87
|
+
* candidate assignment.
|
|
88
|
+
*
|
|
89
|
+
* Counted over the *gaps between consecutive entries* rather than per entry:
|
|
90
|
+
* one short rest sits between two shifts, so asking each shift about its
|
|
91
|
+
* neighbours would count it twice.
|
|
92
|
+
*/
|
|
93
|
+
function countReductions(state, pair, rule) {
|
|
94
|
+
const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
|
|
95
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
96
|
+
const span = (rule.reductionsPer?.windowDays ?? 7) * support_1.MINUTES_PER_DAY;
|
|
97
|
+
const window = { start: inst.startMinute - span, end: inst.endMinute + span };
|
|
98
|
+
const floor = rule.reducibleToMinutes ?? rule.minMinutes;
|
|
99
|
+
// The candidate is not on the timeline yet, so splice it into the ordered
|
|
100
|
+
// list before measuring the gaps it creates.
|
|
101
|
+
const entries = [...timeline.entriesIn(window).filter((e) => e.id !== (0, support_1.entryIdOf)(pair)), (0, support_1.rangeOf)(inst)].sort((a, b) => a.start - b.start);
|
|
102
|
+
let reductions = 0;
|
|
103
|
+
for (let i = 1; i < entries.length; i++) {
|
|
104
|
+
const gap = entries[i].start - entries[i - 1].end;
|
|
105
|
+
if (gap > 0 && gap < rule.minMinutes && gap >= floor)
|
|
106
|
+
reductions++;
|
|
107
|
+
}
|
|
108
|
+
return reductions;
|
|
109
|
+
}
|
|
110
|
+
/*
|
|
111
|
+
* The clock-band rule reduces to "do not work inside the protected band".
|
|
112
|
+
*
|
|
113
|
+
* An earlier version asked whether *some* nearby night still had an unbroken
|
|
114
|
+
* band free, which passes a shift that eats one night as long as the night
|
|
115
|
+
* before was quiet. Sweden's requirement is that each daily rest include
|
|
116
|
+
* 00:00–05:00, so working through any occurrence of the band breaches it — the
|
|
117
|
+
* check is the intrusion, measured directly on the candidate's own span.
|
|
118
|
+
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duty-type volume quotas — rolling caps on how much of one duty type a person
|
|
3
|
+
* may hold, matched on `shiftTypeTag`.
|
|
4
|
+
*
|
|
5
|
+
* The canonical case is a stand-by ceiling: "at most 30 hours of *valveaeg* in
|
|
6
|
+
* any month". Working-time limits cannot express it, because a stand-by duty's
|
|
7
|
+
* point is precisely that most of its span does *not* count as working time —
|
|
8
|
+
* so the quota measures **elapsed** duty minutes (how long the duty occupies
|
|
9
|
+
* the person's clock), or a plain occurrence count. Night work has its own
|
|
10
|
+
* quota shape (`NightWorkRule.volumeQuotas`) because "night shift" is a
|
|
11
|
+
* predicate over the clock band, not a tag; everything tag-shaped lands here.
|
|
12
|
+
*
|
|
13
|
+
* Windows are rolling, anchored on the person's own matching duties — a
|
|
14
|
+
* calendar-month grid would miss a run of stand-by straddling the month
|
|
15
|
+
* boundary, which is exactly where such runs cluster.
|
|
16
|
+
*/
|
|
17
|
+
import type { DutyQuota, SchedulingConstraint } from '../types';
|
|
18
|
+
export declare const DUTY_QUOTA_CITATION = "National duty-volume law (e.g. EE T\u00F6\u00F6lepingu seadus \u00A748)";
|
|
19
|
+
export declare function dutyQuotas(quotas: DutyQuota[]): SchedulingConstraint;
|
|
20
|
+
//# sourceMappingURL=duty-quota.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duty-quota.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/duty-quota.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAe,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAiB7E,eAAO,MAAM,mBAAmB,4EAA6D,CAAC;AAE9F,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,oBAAoB,CAqDpE"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Duty-type volume quotas — rolling caps on how much of one duty type a person
|
|
4
|
+
* may hold, matched on `shiftTypeTag`.
|
|
5
|
+
*
|
|
6
|
+
* The canonical case is a stand-by ceiling: "at most 30 hours of *valveaeg* in
|
|
7
|
+
* any month". Working-time limits cannot express it, because a stand-by duty's
|
|
8
|
+
* point is precisely that most of its span does *not* count as working time —
|
|
9
|
+
* so the quota measures **elapsed** duty minutes (how long the duty occupies
|
|
10
|
+
* the person's clock), or a plain occurrence count. Night work has its own
|
|
11
|
+
* quota shape (`NightWorkRule.volumeQuotas`) because "night shift" is a
|
|
12
|
+
* predicate over the clock band, not a tag; everything tag-shaped lands here.
|
|
13
|
+
*
|
|
14
|
+
* Windows are rolling, anchored on the person's own matching duties — a
|
|
15
|
+
* calendar-month grid would miss a run of stand-by straddling the month
|
|
16
|
+
* boundary, which is exactly where such runs cluster.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.dutyQuotas = exports.DUTY_QUOTA_CITATION = void 0;
|
|
20
|
+
const time_1 = require("../time");
|
|
21
|
+
const support_1 = require("./support");
|
|
22
|
+
exports.DUTY_QUOTA_CITATION = 'National duty-volume law (e.g. EE Töölepingu seadus §48)';
|
|
23
|
+
function dutyQuotas(quotas) {
|
|
24
|
+
return (0, support_1.fromVerdict)({
|
|
25
|
+
id: 'duty-quota',
|
|
26
|
+
hardness: 'hard',
|
|
27
|
+
weight: 1,
|
|
28
|
+
citation: exports.DUTY_QUOTA_CITATION,
|
|
29
|
+
verdict(state, pair) {
|
|
30
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
31
|
+
if (!inst)
|
|
32
|
+
return (0, support_1.pass)('duty-quota', 'unknown shift');
|
|
33
|
+
if (!inst.shiftTypeTag)
|
|
34
|
+
return (0, support_1.pass)('duty-quota', 'shift has no duty type');
|
|
35
|
+
const applied = (0, support_1.rulesFor)(state.ctx, pair.employeeId).dutyQuotas ?? quotas;
|
|
36
|
+
const applicable = applied.filter((q) => q.shiftTypeTag === inst.shiftTypeTag);
|
|
37
|
+
if (applicable.length === 0)
|
|
38
|
+
return (0, support_1.pass)('duty-quota', `no quota covers "${inst.shiftTypeTag}"`);
|
|
39
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
40
|
+
const range = (0, support_1.rangeOf)(inst);
|
|
41
|
+
const probe = { ...range, id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes, tag: inst.shiftTypeTag };
|
|
42
|
+
return timeline.withEntry(probe, (t) => {
|
|
43
|
+
for (const quota of applicable) {
|
|
44
|
+
const span = quota.windowDays * support_1.MINUTES_PER_DAY;
|
|
45
|
+
const citation = quota.citation ?? exports.DUTY_QUOTA_CITATION;
|
|
46
|
+
const label = quota.label ?? `${quota.shiftTypeTag} / ${quota.windowDays}d`;
|
|
47
|
+
if (quota.maxMinutes !== undefined) {
|
|
48
|
+
const worst = worstTagged(t, quota.shiftTypeTag, span, range, sumElapsed);
|
|
49
|
+
if (worst > quota.maxMinutes) {
|
|
50
|
+
return (0, support_1.fail)('duty-quota', 'hard', `employee "${pair.employeeId}" would hold ${(0, support_1.h)(worst)} of "${quota.shiftTypeTag}" duty in some ${quota.windowDays}-day window, over the ${(0, support_1.h)(quota.maxMinutes)} quota (${label})`, { actual: worst, required: quota.maxMinutes, unit: 'minutes', citation });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (quota.maxCount !== undefined) {
|
|
54
|
+
const worst = worstTagged(t, quota.shiftTypeTag, span, range, (hits) => hits.length);
|
|
55
|
+
if (worst > quota.maxCount) {
|
|
56
|
+
return (0, support_1.fail)('duty-quota', 'hard', `employee "${pair.employeeId}" would hold ${worst} "${quota.shiftTypeTag}" duties in some ${quota.windowDays}-day window, over the ${quota.maxCount} quota (${label})`, { actual: worst, required: quota.maxCount, unit: 'count', citation });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return (0, support_1.pass)('duty-quota', 'within every configured duty quota', { citation: exports.DUTY_QUOTA_CITATION });
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.dutyQuotas = dutyQuotas;
|
|
66
|
+
/**
|
|
67
|
+
* Worst value of `measure` over matching entries intersected with any window of
|
|
68
|
+
* `span` minutes near `range`. Candidate left edges sit on matching-entry
|
|
69
|
+
* boundaries — sliding a window until an edge meets a boundary never reduces
|
|
70
|
+
* the extreme being sought, so this finite set contains the answer.
|
|
71
|
+
*/
|
|
72
|
+
function worstTagged(timeline, tag, span, range, measure) {
|
|
73
|
+
const bounds = { start: range.start - 2 * span, end: range.end + 2 * span };
|
|
74
|
+
const matching = timeline.entriesIn(bounds).filter((e) => e.tag === tag);
|
|
75
|
+
if (matching.length === 0)
|
|
76
|
+
return 0;
|
|
77
|
+
const starts = new Set();
|
|
78
|
+
for (const entry of matching) {
|
|
79
|
+
starts.add(entry.start);
|
|
80
|
+
starts.add(entry.end - span);
|
|
81
|
+
}
|
|
82
|
+
let worst = 0;
|
|
83
|
+
for (const start of starts) {
|
|
84
|
+
const window = { start, end: start + span };
|
|
85
|
+
const hits = matching.filter((e) => e.start < window.end && e.end > window.start);
|
|
86
|
+
const value = measure(hits, window);
|
|
87
|
+
if (value > worst)
|
|
88
|
+
worst = value;
|
|
89
|
+
}
|
|
90
|
+
return worst;
|
|
91
|
+
}
|
|
92
|
+
/** Elapsed duty minutes inside the window, counting partial overlaps. */
|
|
93
|
+
function sumElapsed(hits, window) {
|
|
94
|
+
return hits.reduce((sum, entry) => sum + (0, time_1.overlapMinutes)(entry, window), 0);
|
|
95
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimum engagement — the rules that decouple *paid* from *worked*.
|
|
3
|
+
*
|
|
4
|
+
* Belgium requires at least three hours per work session (Labour Act 1971
|
|
5
|
+
* art. 21); the Netherlands pays an on-call worker a minimum of three hours per
|
|
6
|
+
* call and credits 30 minutes for any call-out; Germany's TzBfG §12 implies
|
|
7
|
+
* three consecutive hours where none is agreed; Ireland owes the lesser of 25%
|
|
8
|
+
* of contracted hours or 15 hours when someone is sent home early.
|
|
9
|
+
*
|
|
10
|
+
* These constrain *shift design* rather than assignment — a two-hour shift is
|
|
11
|
+
* unlawful in Belgium no matter who works it — so the breach is reported once
|
|
12
|
+
* per instance, and the paid-minutes floor is surfaced for the cost model
|
|
13
|
+
* rather than folded into working time, since a minimum payment does not make
|
|
14
|
+
* the time count against a working-time limit.
|
|
15
|
+
*/
|
|
16
|
+
import type { EngagementRule, SchedulingConstraint, ShiftInstance } from '../types';
|
|
17
|
+
export declare const ENGAGEMENT_CITATION = "National minimum-engagement law (e.g. BE Labour Act 1971 art. 21)";
|
|
18
|
+
export declare function engagementFloor(rule: EngagementRule): SchedulingConstraint;
|
|
19
|
+
/**
|
|
20
|
+
* Minutes that must be *paid* for a shift, which can exceed the minutes worked.
|
|
21
|
+
*
|
|
22
|
+
* Kept separate from working time deliberately: a three-hour minimum payment for
|
|
23
|
+
* a one-hour call-out costs three hours of wages and one hour of the worker's
|
|
24
|
+
* 48-hour weekly allowance. Folding the floor into working time would overstate
|
|
25
|
+
* the second.
|
|
26
|
+
*/
|
|
27
|
+
export declare function paidMinutesFor(inst: ShiftInstance, rule: EngagementRule | undefined): number;
|
|
28
|
+
//# sourceMappingURL=engagement-floor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engagement-floor.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/engagement-floor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAuB,cAAc,EAAe,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtH,eAAO,MAAM,mBAAmB,sEAAsE,CAAC;AAEvG,wBAAgB,eAAe,CAAC,IAAI,EAAE,cAAc,GAAG,oBAAoB,CAiD1E;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,MAAM,CAG5F"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Minimum engagement — the rules that decouple *paid* from *worked*.
|
|
4
|
+
*
|
|
5
|
+
* Belgium requires at least three hours per work session (Labour Act 1971
|
|
6
|
+
* art. 21); the Netherlands pays an on-call worker a minimum of three hours per
|
|
7
|
+
* call and credits 30 minutes for any call-out; Germany's TzBfG §12 implies
|
|
8
|
+
* three consecutive hours where none is agreed; Ireland owes the lesser of 25%
|
|
9
|
+
* of contracted hours or 15 hours when someone is sent home early.
|
|
10
|
+
*
|
|
11
|
+
* These constrain *shift design* rather than assignment — a two-hour shift is
|
|
12
|
+
* unlawful in Belgium no matter who works it — so the breach is reported once
|
|
13
|
+
* per instance, and the paid-minutes floor is surfaced for the cost model
|
|
14
|
+
* rather than folded into working time, since a minimum payment does not make
|
|
15
|
+
* the time count against a working-time limit.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.paidMinutesFor = exports.engagementFloor = exports.ENGAGEMENT_CITATION = void 0;
|
|
19
|
+
const support_1 = require("./support");
|
|
20
|
+
exports.ENGAGEMENT_CITATION = 'National minimum-engagement law (e.g. BE Labour Act 1971 art. 21)';
|
|
21
|
+
function engagementFloor(rule) {
|
|
22
|
+
const tooShort = (inst) => rule.minShiftMinutes !== undefined && inst.durationMinutes < rule.minShiftMinutes;
|
|
23
|
+
const constraint = (0, support_1.fromVerdict)({
|
|
24
|
+
id: 'engagement-floor',
|
|
25
|
+
hardness: 'hard',
|
|
26
|
+
weight: 1,
|
|
27
|
+
citation: exports.ENGAGEMENT_CITATION,
|
|
28
|
+
verdict(state, pair) {
|
|
29
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
30
|
+
if (!inst)
|
|
31
|
+
return (0, support_1.pass)('engagement-floor', 'unknown shift');
|
|
32
|
+
if (tooShort(inst)) {
|
|
33
|
+
return (0, support_1.fail)('engagement-floor', 'hard', `shift "${inst.id}" is ${(0, support_1.h)(inst.durationMinutes)}, below the ${(0, support_1.h)(rule.minShiftMinutes)} minimum engagement`, {
|
|
34
|
+
actual: inst.durationMinutes,
|
|
35
|
+
required: rule.minShiftMinutes,
|
|
36
|
+
unit: 'minutes',
|
|
37
|
+
citation: exports.ENGAGEMENT_CITATION,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return (0, support_1.pass)('engagement-floor', 'meets the minimum engagement', { citation: exports.ENGAGEMENT_CITATION });
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
constraint.evaluate = (state) => {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const inst of state.ctx.instances) {
|
|
46
|
+
if ((state.assignments.get(inst.id)?.size ?? 0) === 0)
|
|
47
|
+
continue;
|
|
48
|
+
if (!tooShort(inst))
|
|
49
|
+
continue;
|
|
50
|
+
out.push({
|
|
51
|
+
constraintId: 'engagement-floor',
|
|
52
|
+
severity: 'hard',
|
|
53
|
+
shiftInstanceId: inst.id,
|
|
54
|
+
message: `shift "${inst.id}" is ${(0, support_1.h)(inst.durationMinutes)}, below the ${(0, support_1.h)(rule.minShiftMinutes)} minimum engagement`,
|
|
55
|
+
actual: inst.durationMinutes,
|
|
56
|
+
required: rule.minShiftMinutes,
|
|
57
|
+
unit: 'minutes',
|
|
58
|
+
citation: exports.ENGAGEMENT_CITATION,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
};
|
|
63
|
+
return constraint;
|
|
64
|
+
}
|
|
65
|
+
exports.engagementFloor = engagementFloor;
|
|
66
|
+
/**
|
|
67
|
+
* Minutes that must be *paid* for a shift, which can exceed the minutes worked.
|
|
68
|
+
*
|
|
69
|
+
* Kept separate from working time deliberately: a three-hour minimum payment for
|
|
70
|
+
* a one-hour call-out costs three hours of wages and one hour of the worker's
|
|
71
|
+
* 48-hour weekly allowance. Folding the floor into working time would overstate
|
|
72
|
+
* the second.
|
|
73
|
+
*/
|
|
74
|
+
function paidMinutesFor(inst, rule) {
|
|
75
|
+
if (!rule?.minPaidMinutesPerEngagement)
|
|
76
|
+
return inst.workingMinutes;
|
|
77
|
+
return Math.max(inst.workingMinutes, rule.minPaidMinutesPerEngagement);
|
|
78
|
+
}
|
|
79
|
+
exports.paidMinutesFor = paidMinutesFor;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fairness — equalising load across the team.
|
|
3
|
+
*
|
|
4
|
+
* Three deliberate choices:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Per dimension, separately.** Equal total hours says nothing about who
|
|
7
|
+
* takes the nights. Two people can work identical hours while one does every
|
|
8
|
+
* weekend, so hours, nights, weekends and holidays are balanced as separate
|
|
9
|
+
* dimensions rather than rolled into one number.
|
|
10
|
+
*
|
|
11
|
+
* 2. **L1 deviation, not variance.** Variance is quadratic and non-decomposable:
|
|
12
|
+
* changing one person's load changes every other person's contribution
|
|
13
|
+
* through the mean, so it cannot be evaluated incrementally. Summed absolute
|
|
14
|
+
* deviation from the fair share gives the same ordering pressure and stays
|
|
15
|
+
* local.
|
|
16
|
+
*
|
|
17
|
+
* 3. **Realised counts only.** The fair share is computed from what people have
|
|
18
|
+
* actually been assigned, plus `carriedFairness` from previous periods. No
|
|
19
|
+
* behavioural or predictive signal enters — that boundary is what keeps this
|
|
20
|
+
* a constraint solver rather than profiling under AI Act Annex III 4(b).
|
|
21
|
+
*
|
|
22
|
+
* Pro-rata weighting matters legally as well as morally: the part-time,
|
|
23
|
+
* fixed-term and agency directives all require equal treatment on a pro rata
|
|
24
|
+
* temporis basis, so a half-time worker's fair share is half.
|
|
25
|
+
*/
|
|
26
|
+
import type { FairnessRule, SchedulingConstraint, SearchState } from '../types';
|
|
27
|
+
export declare const FAIRNESS_CITATION = "Directive 97/81/EC cl. 4 (pro rata temporis)";
|
|
28
|
+
export declare function fairness(rules: FairnessRule[]): SchedulingConstraint;
|
|
29
|
+
/**
|
|
30
|
+
* Summed absolute deviation from the fair share, across every dimension.
|
|
31
|
+
* Lower is fairer. The objective adds this, weighted, at the soft level.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fairnessPenalty(state: SearchState, rules: FairnessRule[] | undefined): number;
|
|
34
|
+
//# sourceMappingURL=fairness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fairness.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/fairness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAuB,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAiB,MAAM,UAAU,CAAC;AAEpH,eAAO,MAAM,iBAAiB,iDAAiD,CAAC;AAEhF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,oBAAoB,CAmCpE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,SAAS,GAAG,MAAM,CAiB7F"}
|