assignment-user-matcher 1.16.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +312 -20
- package/dist/escalation/policy.d.ts +11 -0
- package/dist/escalation/policy.d.ts.map +1 -1
- package/dist/escalation/policy.js +22 -1
- package/dist/forecasting/backtest.d.ts +52 -0
- package/dist/forecasting/backtest.d.ts.map +1 -0
- package/dist/forecasting/backtest.js +195 -0
- package/dist/forecasting/calendar.d.ts +44 -0
- package/dist/forecasting/calendar.d.ts.map +1 -0
- package/dist/forecasting/calendar.js +85 -0
- package/dist/forecasting/cover.d.ts +69 -0
- package/dist/forecasting/cover.d.ts.map +1 -0
- package/dist/forecasting/cover.js +103 -0
- package/dist/forecasting/days.d.ts +17 -0
- package/dist/forecasting/days.d.ts.map +1 -0
- package/dist/forecasting/days.js +35 -0
- package/dist/forecasting/distributions.d.ts +31 -0
- package/dist/forecasting/distributions.d.ts.map +1 -0
- package/dist/forecasting/distributions.js +154 -0
- package/dist/forecasting/effects.d.ts +88 -0
- package/dist/forecasting/effects.d.ts.map +1 -0
- package/dist/forecasting/effects.js +303 -0
- package/dist/forecasting/erlang.d.ts +31 -0
- package/dist/forecasting/erlang.d.ts.map +1 -0
- package/dist/forecasting/erlang.js +86 -0
- package/dist/forecasting/forecast.d.ts +7 -0
- package/dist/forecasting/forecast.d.ts.map +1 -0
- package/dist/forecasting/forecast.js +221 -0
- package/dist/forecasting/index.d.ts +18 -0
- package/dist/forecasting/index.d.ts.map +1 -0
- package/dist/forecasting/index.js +54 -0
- package/dist/forecasting/model.d.ts +145 -0
- package/dist/forecasting/model.d.ts.map +1 -0
- package/dist/forecasting/model.js +583 -0
- package/dist/forecasting/nowcast.d.ts +26 -0
- package/dist/forecasting/nowcast.d.ts.map +1 -0
- package/dist/forecasting/nowcast.js +92 -0
- package/dist/forecasting/simulation.d.ts +91 -0
- package/dist/forecasting/simulation.d.ts.map +1 -0
- package/dist/forecasting/simulation.js +478 -0
- package/dist/forecasting/spikes.d.ts +6 -0
- package/dist/forecasting/spikes.d.ts.map +1 -0
- package/dist/forecasting/spikes.js +73 -0
- package/dist/forecasting/staffing.d.ts +64 -0
- package/dist/forecasting/staffing.d.ts.map +1 -0
- package/dist/forecasting/staffing.js +765 -0
- package/dist/forecasting/stats.d.ts +11 -0
- package/dist/forecasting/stats.d.ts.map +1 -0
- package/dist/forecasting/stats.js +45 -0
- package/dist/forecasting/types.d.ts +299 -0
- package/dist/forecasting/types.d.ts.map +1 -0
- package/dist/forecasting/types.js +8 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/learning/auto-weights.d.ts +1 -5
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +0 -3
- package/dist/lua/book-slot.lua +84 -0
- package/dist/lua/claim-queued.lua +47 -0
- package/dist/managers/DecisionTraceManager.d.ts +15 -0
- package/dist/managers/DecisionTraceManager.d.ts.map +1 -1
- package/dist/managers/DecisionTraceManager.js +117 -11
- package/dist/managers/LearningManager.d.ts +12 -0
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +21 -7
- package/dist/managers/ReliabilityManager.d.ts +1 -2
- package/dist/managers/ReliabilityManager.d.ts.map +1 -1
- package/dist/managers/ReliabilityManager.js +1 -1
- package/dist/managers/TelemetryManager.d.ts.map +1 -1
- package/dist/managers/TelemetryManager.js +9 -3
- package/dist/managers/WorkflowManager.d.ts.map +1 -1
- package/dist/managers/WorkflowManager.js +3 -4
- package/dist/matcher.class.d.ts +319 -4
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +1428 -102
- package/dist/queries/lane-stats.d.ts +51 -0
- package/dist/queries/lane-stats.d.ts.map +1 -0
- package/dist/queries/lane-stats.js +78 -0
- package/dist/schedule/recurrence.d.ts +11 -0
- package/dist/schedule/recurrence.d.ts.map +1 -1
- package/dist/schedule/recurrence.js +19 -2
- package/dist/schedule/slot.d.ts +60 -0
- package/dist/schedule/slot.d.ts.map +1 -0
- package/dist/schedule/slot.js +86 -0
- package/dist/scheduling/constraints/availability.d.ts +2 -14
- package/dist/scheduling/constraints/availability.d.ts.map +1 -1
- package/dist/scheduling/constraints/availability.js +14 -15
- package/dist/scheduling/constraints/consecutive.d.ts +10 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -1
- package/dist/scheduling/constraints/consecutive.js +64 -1
- package/dist/scheduling/constraints/contract.d.ts.map +1 -1
- package/dist/scheduling/constraints/contract.js +12 -3
- package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
- package/dist/scheduling/constraints/employee-scope.js +10 -2
- package/dist/scheduling/constraints/group-composition.js +2 -2
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -1
- package/dist/scheduling/constraints/min-staffing.js +51 -8
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -1
- package/dist/scheduling/constraints/rolling-hours.js +29 -4
- package/dist/scheduling/constraints/support.d.ts +4 -8
- package/dist/scheduling/constraints/support.d.ts.map +1 -1
- package/dist/scheduling/constraints/support.js +23 -2
- package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
- package/dist/scheduling/constraints/weekly-rest.js +108 -21
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +56 -7
- package/dist/scheduling/engine/objective.d.ts +0 -1
- package/dist/scheduling/engine/objective.d.ts.map +1 -1
- package/dist/scheduling/engine/objective.js +65 -6
- package/dist/scheduling/engine/search.d.ts +4 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -1
- package/dist/scheduling/engine/search.js +2 -1
- package/dist/scheduling/engine/state.d.ts +14 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -1
- package/dist/scheduling/engine/state.js +7 -0
- package/dist/scheduling/engine/timeline.d.ts +23 -1
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +85 -27
- package/dist/scheduling/engine/verdicts.d.ts +40 -1
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
- package/dist/scheduling/engine/verdicts.js +177 -17
- package/dist/scheduling/index.d.ts +3 -2
- package/dist/scheduling/index.d.ts.map +1 -1
- package/dist/scheduling/index.js +7 -1
- package/dist/scheduling/model.d.ts +8 -4
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +239 -23
- package/dist/scheduling/operations.d.ts +174 -2
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +558 -21
- package/dist/scheduling/preference-report.d.ts +15 -0
- package/dist/scheduling/preference-report.d.ts.map +1 -0
- package/dist/scheduling/preference-report.js +111 -0
- package/dist/scheduling/preferences.d.ts +30 -0
- package/dist/scheduling/preferences.d.ts.map +1 -0
- package/dist/scheduling/preferences.js +85 -0
- package/dist/scheduling/resilience.d.ts +46 -0
- package/dist/scheduling/resilience.d.ts.map +1 -0
- package/dist/scheduling/resilience.js +45 -0
- package/dist/scheduling/scheduler.class.d.ts +12 -1
- package/dist/scheduling/scheduler.class.d.ts.map +1 -1
- package/dist/scheduling/scheduler.class.js +28 -4
- package/dist/scheduling/sites.d.ts +1 -1
- package/dist/scheduling/sites.d.ts.map +1 -1
- package/dist/scheduling/sites.js +34 -1
- package/dist/scheduling/time.d.ts +28 -6
- package/dist/scheduling/time.d.ts.map +1 -1
- package/dist/scheduling/time.js +59 -17
- package/dist/scheduling/types.d.ts +247 -7
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.js +2 -1
- package/dist/tracing/decision-trace.d.ts +5 -0
- package/dist/tracing/decision-trace.d.ts.map +1 -1
- package/dist/tracing/decision-trace.js +3 -0
- package/dist/types/matcher.d.ts +369 -2
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/updates/assignment-update.d.ts +93 -0
- package/dist/updates/assignment-update.d.ts.map +1 -0
- package/dist/updates/assignment-update.js +91 -0
- package/dist/utils/keys.d.ts +10 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +43 -0
- package/package.json +25 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure assembly for `getLaneStats()`: per-tag queue depth and age, and the
|
|
3
|
+
* wait-clock distribution. The matcher does the Redis reads; everything that
|
|
4
|
+
* decides what the numbers mean lives here.
|
|
5
|
+
*/
|
|
6
|
+
import type { LaneStat, WaitDistribution } from '../types/matcher';
|
|
7
|
+
export interface LaneSampleEntry {
|
|
8
|
+
/** The assignment's tag CSV; null when the record has no tag index (claimed or gone) */
|
|
9
|
+
tagsCsv: string | null;
|
|
10
|
+
/** First-enqueue time (ms epoch), the wait clock's score */
|
|
11
|
+
queuedAt: number;
|
|
12
|
+
}
|
|
13
|
+
export interface SummarizeLanesInput {
|
|
14
|
+
counts: {
|
|
15
|
+
tag: string;
|
|
16
|
+
queued: number;
|
|
17
|
+
}[];
|
|
18
|
+
/** Oldest waiting assignments, oldest first */
|
|
19
|
+
sample: LaneSampleEntry[];
|
|
20
|
+
/** True when `sample` holds every waiting assignment */
|
|
21
|
+
sampleComplete: boolean;
|
|
22
|
+
now: number;
|
|
23
|
+
/** Tags that are not routing lanes (the injected `default`) */
|
|
24
|
+
ignore?: ReadonlySet<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Tag CSVs of a few queued assignments from lanes the sample missed, so
|
|
27
|
+
* every lane's `alsoTagged` is read off real work, not only the oldest.
|
|
28
|
+
*/
|
|
29
|
+
extraTagSets?: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* One lane per tag with queued work, deepest first.
|
|
33
|
+
*
|
|
34
|
+
* A lane's oldest age is exact when one of its assignments appears in the
|
|
35
|
+
* sample (the sample is read oldest-first, so the first hit is the oldest).
|
|
36
|
+
* A lane with no sampled assignment is younger than everything sampled, so
|
|
37
|
+
* the last sampled age is an honest upper bound — flagged, never presented
|
|
38
|
+
* as exact.
|
|
39
|
+
*/
|
|
40
|
+
export declare function summarizeLanes(input: SummarizeLanesInput): LaneStat[];
|
|
41
|
+
/**
|
|
42
|
+
* Nearest-rank position (0-based, oldest first) of the entry whose wait is
|
|
43
|
+
* exceeded by `share` of the population: `share` 0.05 → the p95 age.
|
|
44
|
+
*/
|
|
45
|
+
export declare function waitRank(count: number, share: number): number;
|
|
46
|
+
export declare function waitDistribution(count: number, scores: {
|
|
47
|
+
p50: number | null;
|
|
48
|
+
p95: number | null;
|
|
49
|
+
oldest: number | null;
|
|
50
|
+
}, now: number): WaitDistribution;
|
|
51
|
+
//# sourceMappingURL=lane-stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lane-stats.d.ts","sourceRoot":"","sources":["../../src/queries/lane-stats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,WAAW,eAAe;IAC5B,wFAAwF;IACxF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,+CAA+C;IAC/C,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,wDAAwD;IACxD,cAAc,EAAE,OAAO,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,QAAQ,EAAE,CAsCrE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACzE,GAAG,EAAE,MAAM,GACZ,gBAAgB,CAQlB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitDistribution = exports.waitRank = exports.summarizeLanes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* One lane per tag with queued work, deepest first.
|
|
6
|
+
*
|
|
7
|
+
* A lane's oldest age is exact when one of its assignments appears in the
|
|
8
|
+
* sample (the sample is read oldest-first, so the first hit is the oldest).
|
|
9
|
+
* A lane with no sampled assignment is younger than everything sampled, so
|
|
10
|
+
* the last sampled age is an honest upper bound — flagged, never presented
|
|
11
|
+
* as exact.
|
|
12
|
+
*/
|
|
13
|
+
function summarizeLanes(input) {
|
|
14
|
+
const firstSeen = new Map();
|
|
15
|
+
const together = new Map();
|
|
16
|
+
const note = (tags) => {
|
|
17
|
+
for (const tag of tags) {
|
|
18
|
+
let seen = together.get(tag);
|
|
19
|
+
if (!seen)
|
|
20
|
+
together.set(tag, (seen = new Map()));
|
|
21
|
+
for (const other of tags)
|
|
22
|
+
if (other !== tag)
|
|
23
|
+
seen.set(other, (seen.get(other) ?? 0) + 1);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
for (const entry of input.sample) {
|
|
27
|
+
// No tag index means the assignment left the queue (claimed, so it is
|
|
28
|
+
// pending) — its wait clock still runs but it is not in any lane.
|
|
29
|
+
if (!entry.tagsCsv)
|
|
30
|
+
continue;
|
|
31
|
+
const tags = entry.tagsCsv.split(',').filter((tag) => tag && !input.ignore?.has(tag));
|
|
32
|
+
for (const tag of tags) {
|
|
33
|
+
if (!firstSeen.has(tag))
|
|
34
|
+
firstSeen.set(tag, entry.queuedAt);
|
|
35
|
+
}
|
|
36
|
+
note(tags);
|
|
37
|
+
}
|
|
38
|
+
for (const csv of input.extraTagSets ?? []) {
|
|
39
|
+
note(csv.split(',').filter((tag) => tag && !input.ignore?.has(tag)));
|
|
40
|
+
}
|
|
41
|
+
const last = input.sample.length > 0 ? input.sample[input.sample.length - 1].queuedAt : input.now;
|
|
42
|
+
const lanes = [];
|
|
43
|
+
for (const { tag, queued } of input.counts) {
|
|
44
|
+
if (queued <= 0 || input.ignore?.has(tag))
|
|
45
|
+
continue;
|
|
46
|
+
const seen = firstSeen.get(tag);
|
|
47
|
+
const exact = seen !== undefined || input.sampleComplete;
|
|
48
|
+
const at = seen ?? (input.sampleComplete ? input.now : last);
|
|
49
|
+
const also = [...(together.get(tag) ?? new Map()).entries()]
|
|
50
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
51
|
+
.slice(0, 5)
|
|
52
|
+
.map(([other]) => other);
|
|
53
|
+
lanes.push({ tag, queued, oldestWaitingMs: Math.max(0, input.now - at), oldestExact: exact, alsoTagged: also });
|
|
54
|
+
}
|
|
55
|
+
lanes.sort((a, b) => b.queued - a.queued || a.tag.localeCompare(b.tag));
|
|
56
|
+
return lanes;
|
|
57
|
+
}
|
|
58
|
+
exports.summarizeLanes = summarizeLanes;
|
|
59
|
+
/**
|
|
60
|
+
* Nearest-rank position (0-based, oldest first) of the entry whose wait is
|
|
61
|
+
* exceeded by `share` of the population: `share` 0.05 → the p95 age.
|
|
62
|
+
*/
|
|
63
|
+
function waitRank(count, share) {
|
|
64
|
+
if (count <= 0)
|
|
65
|
+
return 0;
|
|
66
|
+
return Math.min(count - 1, Math.max(0, Math.floor(share * (count - 1))));
|
|
67
|
+
}
|
|
68
|
+
exports.waitRank = waitRank;
|
|
69
|
+
function waitDistribution(count, scores, now) {
|
|
70
|
+
const age = (score) => (score === null ? null : Math.max(0, now - score));
|
|
71
|
+
return {
|
|
72
|
+
waiting: count,
|
|
73
|
+
p50Ms: count > 0 ? age(scores.p50) : null,
|
|
74
|
+
p95Ms: count > 0 ? age(scores.p95) : null,
|
|
75
|
+
oldestMs: count > 0 ? age(scores.oldest) : null,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.waitDistribution = waitDistribution;
|
|
@@ -10,11 +10,22 @@
|
|
|
10
10
|
* cadence decides *when* a slot is noticed, never *where* it sits. The sweep
|
|
11
11
|
* materializes one interval ahead (`horizon = now + everyMs`), so the next
|
|
12
12
|
* occurrence exists as a scheduled assignment before its window opens.
|
|
13
|
+
*
|
|
14
|
+
* `times` spreads several occurrences evenly across one period ("twice a
|
|
15
|
+
* week"). It is resolved here, once, into the gap between two consecutive
|
|
16
|
+
* occurrences — `NormalizedRecurrencePolicy.everyMs` *is* that gap, and
|
|
17
|
+
* nothing downstream reads the caller's period. A second reading of the
|
|
18
|
+
* cadence is how a sweep and a validator stop agreeing.
|
|
13
19
|
*/
|
|
14
20
|
import type { Assignment, RecurrencePolicy, RecurringAssignment } from '../types/matcher';
|
|
15
21
|
/** A policy with every optional field resolved. */
|
|
16
22
|
export interface NormalizedRecurrencePolicy {
|
|
23
|
+
/** Gap between two consecutive occurrences: the caller's period ÷ `times`. */
|
|
17
24
|
everyMs: number;
|
|
25
|
+
/** The caller's period, kept for reporting the policy back — never for slot arithmetic. */
|
|
26
|
+
periodMs: number;
|
|
27
|
+
/** Occurrences per period. 1 unless the caller asked for more. */
|
|
28
|
+
times: number;
|
|
18
29
|
startAt?: number;
|
|
19
30
|
windowMs?: number;
|
|
20
31
|
onMiss: 'park' | 'drop';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recurrence.d.ts","sourceRoot":"","sources":["../../src/schedule/recurrence.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"recurrence.d.ts","sourceRoot":"","sources":["../../src/schedule/recurrence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAkB,MAAM,kBAAkB,CAAC;AAE1G,mDAAmD;AACnD,MAAM,WAAW,0BAA0B;IACvC,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAC;IAChB,2FAA2F;IAC3F,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;CAC3B;AAED,oDAAoD;AACpD,MAAM,WAAW,eAAe;IAC5B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,gEAAgE;AAChE,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAOvC;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,GAAG,0BAA0B,GAAG,IAAI,CA+BxH;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAExE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACpB,MAAM,EAAE,0BAA0B,EAClC,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,MAAM,GACZ;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,eAAe,CAAC;IAAC,aAAa,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAAA;CAAE,CAyC9F;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,0BAA0B,EAClC,MAAM,EAAE,MAAM,GACf,UAAU,CAUZ;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,0BAA0B,GAAG,MAAM,CAE7F"}
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* cadence decides *when* a slot is noticed, never *where* it sits. The sweep
|
|
12
12
|
* materializes one interval ahead (`horizon = now + everyMs`), so the next
|
|
13
13
|
* occurrence exists as a scheduled assignment before its window opens.
|
|
14
|
+
*
|
|
15
|
+
* `times` spreads several occurrences evenly across one period ("twice a
|
|
16
|
+
* week"). It is resolved here, once, into the gap between two consecutive
|
|
17
|
+
* occurrences — `NormalizedRecurrencePolicy.everyMs` *is* that gap, and
|
|
18
|
+
* nothing downstream reads the caller's period. A second reading of the
|
|
19
|
+
* cadence is how a sweep and a validator stop agreeing.
|
|
14
20
|
*/
|
|
15
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
22
|
exports.sweepDueAt = exports.materializeOccurrence = exports.dueSlots = exports.occurrenceId = exports.normalizeRecurrencePolicy = exports.MAX_SLOTS_PER_SWEEP = exports.MIN_EVERY_MS = void 0;
|
|
@@ -37,8 +43,17 @@ function positiveInt(value) {
|
|
|
37
43
|
function normalizeRecurrencePolicy(policy) {
|
|
38
44
|
if (!policy || typeof policy !== 'object')
|
|
39
45
|
return null;
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
46
|
+
const periodMs = positiveInt(policy.everyMs);
|
|
47
|
+
if (periodMs === undefined)
|
|
48
|
+
return null;
|
|
49
|
+
const times = policy.times === undefined ? 1 : positiveInt(policy.times);
|
|
50
|
+
if (times === undefined)
|
|
51
|
+
return null;
|
|
52
|
+
// The gap is what every slot, window and horizon is measured in, so a
|
|
53
|
+
// period that divides into sub-second work is refused on the gap, not on
|
|
54
|
+
// the period the caller happened to name it with.
|
|
55
|
+
const everyMs = times === 1 ? periodMs : Math.round(periodMs / times);
|
|
56
|
+
if (everyMs < exports.MIN_EVERY_MS)
|
|
42
57
|
return null;
|
|
43
58
|
const startAt = positiveInt(policy.startAt);
|
|
44
59
|
const windowMs = positiveInt(policy.windowMs);
|
|
@@ -49,6 +64,8 @@ function normalizeRecurrencePolicy(policy) {
|
|
|
49
64
|
return null;
|
|
50
65
|
return {
|
|
51
66
|
everyMs,
|
|
67
|
+
periodMs,
|
|
68
|
+
times,
|
|
52
69
|
startAt,
|
|
53
70
|
windowMs,
|
|
54
71
|
onMiss: policy.onMiss === 'drop' ? 'drop' : 'park',
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeslot policy — pure logic.
|
|
3
|
+
*
|
|
4
|
+
* A `SchedulePolicy` says when an assignment may be *offered*; a `TimeSlot`
|
|
5
|
+
* says when the work is *performed* and for how long. They are different
|
|
6
|
+
* clocks and deliberately different objects: escalation owns the response
|
|
7
|
+
* clock, SLA the completion clock, schedule the offer window, and the slot
|
|
8
|
+
* the appointment itself. Folding a fourth meaning into `schedule` is how one
|
|
9
|
+
* field's two readings start disagreeing.
|
|
10
|
+
*
|
|
11
|
+
* Everything here is side-effect free: `AssignmentMatcher` owns the Redis
|
|
12
|
+
* writes and `src/lua/book-slot.lua` owns the atomic reservation, this module
|
|
13
|
+
* owns the arithmetic and the definition of a clash.
|
|
14
|
+
*/
|
|
15
|
+
import type { TimeSlot } from '../types/matcher';
|
|
16
|
+
/** How far ahead of the slot the booking sweep reserves a worker by default. */
|
|
17
|
+
export declare const DEFAULT_BOOK_AHEAD_MS: number;
|
|
18
|
+
/** A slot with every optional field resolved. */
|
|
19
|
+
export interface NormalizedSlot {
|
|
20
|
+
startAt: number;
|
|
21
|
+
durationMs: number;
|
|
22
|
+
bookAheadMs: number;
|
|
23
|
+
onUnbooked: 'queue' | 'park' | 'drop';
|
|
24
|
+
}
|
|
25
|
+
/** A half-open interval `[startAt, endAt)`. */
|
|
26
|
+
export interface SlotSpan {
|
|
27
|
+
startAt: number;
|
|
28
|
+
endAt: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve an assignment's timeslot, or `null` when it has none or the one it
|
|
32
|
+
* has is unusable. A zero-length appointment is not an appointment and a
|
|
33
|
+
* negative one is a data error; both return `null` so the assignment stays on
|
|
34
|
+
* the untouched legacy path rather than being half-booked.
|
|
35
|
+
*/
|
|
36
|
+
export declare function normalizeSlot(slot: TimeSlot | undefined | null): NormalizedSlot | null;
|
|
37
|
+
/** When the appointment finishes. Exclusive: the slot is `[startAt, endAt)`. */
|
|
38
|
+
export declare function slotEndsAt(slot: NormalizedSlot): number;
|
|
39
|
+
/**
|
|
40
|
+
* Whether two appointments collide.
|
|
41
|
+
*
|
|
42
|
+
* The intervals are half-open, so a job ending at 15:00 and the next starting
|
|
43
|
+
* at 15:00 do not clash — that is an ordinary working day, and refusing it
|
|
44
|
+
* would make every back-to-back schedule unbookable.
|
|
45
|
+
*/
|
|
46
|
+
export declare function slotsOverlap(a: SlotSpan, b: SlotSpan): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The earliest the booking sweep may reserve somebody. Clamped at 0 so a slot
|
|
49
|
+
* close to the epoch (only ever seen in tests) still produces a sane index
|
|
50
|
+
* score rather than a negative one.
|
|
51
|
+
*/
|
|
52
|
+
export declare function bookingOpensAt(slot: NormalizedSlot): number;
|
|
53
|
+
/**
|
|
54
|
+
* Same question, answered from the stored JSON without paying for a parse.
|
|
55
|
+
* Assignments without a slot — effectively all of them in a typical
|
|
56
|
+
* deployment — cost one `indexOf` and nothing else, mirroring
|
|
57
|
+
* `scheduleFromJson`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function slotFromJson(json: string | null | undefined): NormalizedSlot | null;
|
|
60
|
+
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../src/schedule/slot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAc,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE7D,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,QAA0B,CAAC;AAE7D,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;CACzC;AAED,+CAA+C;AAC/C,MAAM,WAAW,QAAQ;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACjB;AAOD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,CAatF;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc,GAAG,IAAI,CAOnF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Timeslot policy — pure logic.
|
|
4
|
+
*
|
|
5
|
+
* A `SchedulePolicy` says when an assignment may be *offered*; a `TimeSlot`
|
|
6
|
+
* says when the work is *performed* and for how long. They are different
|
|
7
|
+
* clocks and deliberately different objects: escalation owns the response
|
|
8
|
+
* clock, SLA the completion clock, schedule the offer window, and the slot
|
|
9
|
+
* the appointment itself. Folding a fourth meaning into `schedule` is how one
|
|
10
|
+
* field's two readings start disagreeing.
|
|
11
|
+
*
|
|
12
|
+
* Everything here is side-effect free: `AssignmentMatcher` owns the Redis
|
|
13
|
+
* writes and `src/lua/book-slot.lua` owns the atomic reservation, this module
|
|
14
|
+
* owns the arithmetic and the definition of a clash.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.slotFromJson = exports.bookingOpensAt = exports.slotsOverlap = exports.slotEndsAt = exports.normalizeSlot = exports.DEFAULT_BOOK_AHEAD_MS = void 0;
|
|
18
|
+
/** How far ahead of the slot the booking sweep reserves a worker by default. */
|
|
19
|
+
exports.DEFAULT_BOOK_AHEAD_MS = 7 * 24 * 60 * 60 * 1000;
|
|
20
|
+
function positive(value) {
|
|
21
|
+
const n = Number(value);
|
|
22
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve an assignment's timeslot, or `null` when it has none or the one it
|
|
26
|
+
* has is unusable. A zero-length appointment is not an appointment and a
|
|
27
|
+
* negative one is a data error; both return `null` so the assignment stays on
|
|
28
|
+
* the untouched legacy path rather than being half-booked.
|
|
29
|
+
*/
|
|
30
|
+
function normalizeSlot(slot) {
|
|
31
|
+
if (!slot || typeof slot !== 'object')
|
|
32
|
+
return null;
|
|
33
|
+
const startAt = positive(slot.startAt);
|
|
34
|
+
const durationMs = positive(slot.durationMs);
|
|
35
|
+
if (startAt === undefined || durationMs === undefined)
|
|
36
|
+
return null;
|
|
37
|
+
return {
|
|
38
|
+
startAt,
|
|
39
|
+
durationMs,
|
|
40
|
+
bookAheadMs: positive(slot.bookAheadMs) ?? exports.DEFAULT_BOOK_AHEAD_MS,
|
|
41
|
+
onUnbooked: slot.onUnbooked === 'park' || slot.onUnbooked === 'drop' ? slot.onUnbooked : 'queue',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.normalizeSlot = normalizeSlot;
|
|
45
|
+
/** When the appointment finishes. Exclusive: the slot is `[startAt, endAt)`. */
|
|
46
|
+
function slotEndsAt(slot) {
|
|
47
|
+
return slot.startAt + slot.durationMs;
|
|
48
|
+
}
|
|
49
|
+
exports.slotEndsAt = slotEndsAt;
|
|
50
|
+
/**
|
|
51
|
+
* Whether two appointments collide.
|
|
52
|
+
*
|
|
53
|
+
* The intervals are half-open, so a job ending at 15:00 and the next starting
|
|
54
|
+
* at 15:00 do not clash — that is an ordinary working day, and refusing it
|
|
55
|
+
* would make every back-to-back schedule unbookable.
|
|
56
|
+
*/
|
|
57
|
+
function slotsOverlap(a, b) {
|
|
58
|
+
return a.startAt < b.endAt && b.startAt < a.endAt;
|
|
59
|
+
}
|
|
60
|
+
exports.slotsOverlap = slotsOverlap;
|
|
61
|
+
/**
|
|
62
|
+
* The earliest the booking sweep may reserve somebody. Clamped at 0 so a slot
|
|
63
|
+
* close to the epoch (only ever seen in tests) still produces a sane index
|
|
64
|
+
* score rather than a negative one.
|
|
65
|
+
*/
|
|
66
|
+
function bookingOpensAt(slot) {
|
|
67
|
+
return Math.max(0, slot.startAt - slot.bookAheadMs);
|
|
68
|
+
}
|
|
69
|
+
exports.bookingOpensAt = bookingOpensAt;
|
|
70
|
+
/**
|
|
71
|
+
* Same question, answered from the stored JSON without paying for a parse.
|
|
72
|
+
* Assignments without a slot — effectively all of them in a typical
|
|
73
|
+
* deployment — cost one `indexOf` and nothing else, mirroring
|
|
74
|
+
* `scheduleFromJson`.
|
|
75
|
+
*/
|
|
76
|
+
function slotFromJson(json) {
|
|
77
|
+
if (!json || json.indexOf('"slot"') === -1)
|
|
78
|
+
return null;
|
|
79
|
+
try {
|
|
80
|
+
return normalizeSlot(JSON.parse(json).slot);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.slotFromJson = slotFromJson;
|
|
@@ -16,19 +16,8 @@
|
|
|
16
16
|
* directives, and it can only be traded off if it is scored rather than binary.
|
|
17
17
|
*/
|
|
18
18
|
import type { AvailabilityRule, SchedulingConstraint, SearchState, ShiftInstance } from '../types';
|
|
19
|
+
import { type ClockLike } from '../preferences';
|
|
19
20
|
export declare function availability(): SchedulingConstraint;
|
|
20
|
-
declare function overlapsRule(clock: {
|
|
21
|
-
minutesInClockRange: (r: {
|
|
22
|
-
start: number;
|
|
23
|
-
end: number;
|
|
24
|
-
}, c: {
|
|
25
|
-
from: string;
|
|
26
|
-
to: string;
|
|
27
|
-
}) => number;
|
|
28
|
-
}, range: {
|
|
29
|
-
start: number;
|
|
30
|
-
end: number;
|
|
31
|
-
}, rule: AvailabilityRule): number;
|
|
32
21
|
/**
|
|
33
22
|
* Weighted preference term over the whole roster, for the soft objective:
|
|
34
23
|
* every assigned pair contributes its `avoid` weights and is credited its
|
|
@@ -38,6 +27,5 @@ declare function overlapsRule(clock: {
|
|
|
38
27
|
*/
|
|
39
28
|
export declare function preferencePenalty(state: SearchState): number;
|
|
40
29
|
/** Soft preference score for a pair: negative is better. Used by candidate ranking. */
|
|
41
|
-
export declare function preferenceScore(clock:
|
|
42
|
-
export {};
|
|
30
|
+
export declare function preferenceScore(clock: ClockLike, rules: AvailabilityRule[] | undefined, inst: ShiftInstance): number;
|
|
43
31
|
//# sourceMappingURL=availability.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"availability.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/availability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAe,oBAAoB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"availability.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/availability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAe,oBAAoB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAChH,OAAO,EAAgE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG9G,wBAAgB,YAAY,IAAI,oBAAoB,CAyFnD;AAkCD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAW5D;AAED,uFAAuF;AACvF,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM,CAWpH"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.preferenceScore = exports.preferencePenalty = exports.availability = void 0;
|
|
21
|
-
const
|
|
21
|
+
const preferences_1 = require("../preferences");
|
|
22
22
|
const support_1 = require("./support");
|
|
23
23
|
function availability() {
|
|
24
24
|
const constraint = (0, support_1.fromVerdict)({
|
|
@@ -33,9 +33,9 @@ function availability() {
|
|
|
33
33
|
const clock = state.ctx.clock;
|
|
34
34
|
const range = { start: inst.startMinute, end: inst.endMinute };
|
|
35
35
|
const span = range.end - range.start;
|
|
36
|
-
const matching = employee.availability.filter((rule) => (0,
|
|
36
|
+
const matching = employee.availability.filter((rule) => (0, preferences_1.availabilityApplies)(rule, inst));
|
|
37
37
|
for (const rule of matching.filter((r) => r.kind === 'unavailable')) {
|
|
38
|
-
if (
|
|
38
|
+
if ((0, preferences_1.ruleOverlapMinutes)(clock, range, rule) > 0) {
|
|
39
39
|
return (0, support_1.fail)('availability', 'hard', `employee "${pair.employeeId}" is unavailable during "${inst.id}"`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -51,13 +51,17 @@ function availability() {
|
|
|
51
51
|
return (0, support_1.fail)('availability', 'hard', `"${inst.id}" falls outside employee "${pair.employeeId}"'s declared availability`, { actual: covered, required: span, unit: 'minutes' });
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
// Read the resolved rule, not the stated one, so the weight shown
|
|
55
|
+
// here is the weight the objective scores (priority and budget applied).
|
|
56
|
+
const avoided = state.ctx.preferenceRules
|
|
57
|
+
.get(pair.employeeId)
|
|
58
|
+
?.find((r) => r.kind === 'avoid' && (0, preferences_1.ruleMatchesInstance)(clock, r, inst));
|
|
55
59
|
if (avoided) {
|
|
56
60
|
return (0, support_1.fail)('availability', 'soft', `employee "${pair.employeeId}" prefers to avoid "${inst.id}"`, {
|
|
57
|
-
actual: avoided.weight
|
|
61
|
+
actual: avoided.weight,
|
|
58
62
|
});
|
|
59
63
|
}
|
|
60
|
-
const preferred = matching.find((r) => r.kind === 'preferred' &&
|
|
64
|
+
const preferred = matching.find((r) => r.kind === 'preferred' && (0, preferences_1.ruleOverlapMinutes)(clock, range, r) > 0);
|
|
61
65
|
return (0, support_1.pass)('availability', preferred ? `matches a preferred window` : 'no availability objection');
|
|
62
66
|
},
|
|
63
67
|
});
|
|
@@ -96,7 +100,7 @@ exports.availability = availability;
|
|
|
96
100
|
/**
|
|
97
101
|
* Minutes of `range` covered by the union of the given windows. A window with
|
|
98
102
|
* no `from`/`to` covers the whole range; timed windows are projected onto the
|
|
99
|
-
* range via the clock (same per-day band semantics as `
|
|
103
|
+
* range via the clock (same per-day band semantics as `ruleOverlapMinutes`) and
|
|
100
104
|
* merged, so contiguous or overlapping declarations never undercount.
|
|
101
105
|
*/
|
|
102
106
|
function unionCoveredMinutes(clock, range, rules) {
|
|
@@ -117,11 +121,6 @@ function unionCoveredMinutes(clock, range, rules) {
|
|
|
117
121
|
}
|
|
118
122
|
return covered;
|
|
119
123
|
}
|
|
120
|
-
function overlapsRule(clock, range, rule) {
|
|
121
|
-
if (rule.from === undefined || rule.to === undefined)
|
|
122
|
-
return range.end - range.start;
|
|
123
|
-
return clock.minutesInClockRange(range, { from: rule.from, to: rule.to });
|
|
124
|
-
}
|
|
125
124
|
/**
|
|
126
125
|
* Weighted preference term over the whole roster, for the soft objective:
|
|
127
126
|
* every assigned pair contributes its `avoid` weights and is credited its
|
|
@@ -136,7 +135,7 @@ function preferencePenalty(state) {
|
|
|
136
135
|
if (!inst)
|
|
137
136
|
continue;
|
|
138
137
|
for (const employeeId of employees) {
|
|
139
|
-
const rules = state.ctx.
|
|
138
|
+
const rules = state.ctx.preferenceRules.get(employeeId);
|
|
140
139
|
if (rules?.length)
|
|
141
140
|
penalty += preferenceScore(state.ctx.clock, rules, inst);
|
|
142
141
|
}
|
|
@@ -151,9 +150,9 @@ function preferenceScore(clock, rules, inst) {
|
|
|
151
150
|
const range = { start: inst.startMinute, end: inst.endMinute };
|
|
152
151
|
let score = 0;
|
|
153
152
|
for (const rule of rules) {
|
|
154
|
-
if (!(0,
|
|
153
|
+
if (!(0, preferences_1.availabilityApplies)(rule, inst))
|
|
155
154
|
continue;
|
|
156
|
-
if (
|
|
155
|
+
if ((0, preferences_1.ruleOverlapMinutes)(clock, range, rule) <= 0)
|
|
157
156
|
continue;
|
|
158
157
|
if (rule.kind === 'preferred')
|
|
159
158
|
score -= rule.weight ?? 1;
|
|
@@ -19,6 +19,16 @@ import type { ConsecutiveRule, SchedulingConstraint } from '../types';
|
|
|
19
19
|
export declare const CONSECUTIVE_CITATION = "National working-time law / collective agreement";
|
|
20
20
|
/** Every sequence constraint the rule configures. */
|
|
21
21
|
export declare function consecutiveConstraints(rule: ConsecutiveRule): SchedulingConstraint[];
|
|
22
|
+
/**
|
|
23
|
+
* Weekends in a row.
|
|
24
|
+
*
|
|
25
|
+
* "Every second weekend off" — the term most often negotiated and the one a
|
|
26
|
+
* count cannot hold. Weekends are keyed by the Saturday that opens them, so a
|
|
27
|
+
* Saturday and the Sunday after it are one weekend; keying by week number would
|
|
28
|
+
* split a weekend across a year boundary and keying by day would make every
|
|
29
|
+
* ordinary weekend a run of two.
|
|
30
|
+
*/
|
|
31
|
+
export declare function consecutiveWeekends(maxWeekends: number): SchedulingConstraint;
|
|
22
32
|
export declare function consecutiveDays(maxDays: number): SchedulingConstraint;
|
|
23
33
|
export declare function consecutiveNights(rule: ConsecutiveRule): SchedulingConstraint;
|
|
24
34
|
export declare function shiftSuccession(forbidden: NonNullable<ConsecutiveRule['forbiddenSuccessions']>): SchedulingConstraint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consecutive.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/consecutive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAe,oBAAoB,EAA8B,MAAM,UAAU,CAAC;AAI/G,eAAO,MAAM,oBAAoB,qDAAqD,CAAC;AAEvF,qDAAqD;AACrD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,GAAG,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"consecutive.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/consecutive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAe,oBAAoB,EAA8B,MAAM,UAAU,CAAC;AAI/G,eAAO,MAAM,oBAAoB,qDAAqD,CAAC;AAEvF,qDAAqD;AACrD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,GAAG,oBAAoB,EAAE,CASpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,oBAAoB,CAiC7E;AAwBD,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAiCrE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,oBAAoB,CAqE7E;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC,GAAG,oBAAoB,CA6DrH"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* minimum.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.shiftSuccession = exports.consecutiveNights = exports.consecutiveDays = exports.consecutiveConstraints = exports.CONSECUTIVE_CITATION = void 0;
|
|
20
|
+
exports.shiftSuccession = exports.consecutiveNights = exports.consecutiveDays = exports.consecutiveWeekends = exports.consecutiveConstraints = exports.CONSECUTIVE_CITATION = void 0;
|
|
21
21
|
const support_1 = require("./support");
|
|
22
22
|
exports.CONSECUTIVE_CITATION = 'National working-time law / collective agreement';
|
|
23
23
|
/** Every sequence constraint the rule configures. */
|
|
@@ -28,11 +28,74 @@ function consecutiveConstraints(rule) {
|
|
|
28
28
|
if (rule.maxNightShifts !== undefined || rule.restAfterNightBlockMinutes !== undefined) {
|
|
29
29
|
out.push(consecutiveNights(rule));
|
|
30
30
|
}
|
|
31
|
+
if (rule.maxConsecutiveWeekends !== undefined)
|
|
32
|
+
out.push(consecutiveWeekends(rule.maxConsecutiveWeekends));
|
|
31
33
|
if (rule.forbiddenSuccessions?.length)
|
|
32
34
|
out.push(shiftSuccession(rule.forbiddenSuccessions));
|
|
33
35
|
return out;
|
|
34
36
|
}
|
|
35
37
|
exports.consecutiveConstraints = consecutiveConstraints;
|
|
38
|
+
/**
|
|
39
|
+
* Weekends in a row.
|
|
40
|
+
*
|
|
41
|
+
* "Every second weekend off" — the term most often negotiated and the one a
|
|
42
|
+
* count cannot hold. Weekends are keyed by the Saturday that opens them, so a
|
|
43
|
+
* Saturday and the Sunday after it are one weekend; keying by week number would
|
|
44
|
+
* split a weekend across a year boundary and keying by day would make every
|
|
45
|
+
* ordinary weekend a run of two.
|
|
46
|
+
*/
|
|
47
|
+
function consecutiveWeekends(maxWeekends) {
|
|
48
|
+
return (0, support_1.fromVerdict)({
|
|
49
|
+
id: 'consecutive-weekends',
|
|
50
|
+
hardness: 'hard',
|
|
51
|
+
weight: 1,
|
|
52
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
53
|
+
verdict(state, pair) {
|
|
54
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
55
|
+
if (!inst)
|
|
56
|
+
return (0, support_1.pass)('consecutive-weekends', 'unknown shift');
|
|
57
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
58
|
+
const probe = { ...(0, support_1.rangeOf)(inst), id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes };
|
|
59
|
+
const clock = state.ctx.clock;
|
|
60
|
+
return timeline.withEntry(probe, (t) => {
|
|
61
|
+
const run = t.longestConsecutiveWeekends((minute) => weekendKey(clock, minute));
|
|
62
|
+
if (run > maxWeekends) {
|
|
63
|
+
return (0, support_1.fail)('consecutive-weekends', 'hard', `employee "${pair.employeeId}" would work ${run} weekends in a row, over the ${maxWeekends} allowed`, { actual: run, required: maxWeekends, unit: 'count', citation: exports.CONSECUTIVE_CITATION });
|
|
64
|
+
}
|
|
65
|
+
return (0, support_1.pass)('consecutive-weekends', `${run} weekends in a row, within the ${maxWeekends} allowed`, {
|
|
66
|
+
actual: run,
|
|
67
|
+
required: maxWeekends,
|
|
68
|
+
unit: 'count',
|
|
69
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.consecutiveWeekends = consecutiveWeekends;
|
|
76
|
+
/**
|
|
77
|
+
* Which weekend a minute belongs to, as a consecutive ordinal, or `null` for a
|
|
78
|
+
* weekday.
|
|
79
|
+
*
|
|
80
|
+
* Resolved to the Saturday that opens the weekend first — a Sunday belongs to
|
|
81
|
+
* the weekend whose Saturday was the day before, so an ordinary weekend is one
|
|
82
|
+
* weekend rather than two — and then divided into weeks, so that successive
|
|
83
|
+
* weekends differ by exactly one and the run check is a plain `+ 1`.
|
|
84
|
+
*
|
|
85
|
+
* The division is safe at any period alignment and before the period starts:
|
|
86
|
+
* Saturdays are always seven days apart, so integer division by seven yields
|
|
87
|
+
* consecutive ordinals wherever the period begins, and `Math.floor` carries
|
|
88
|
+
* that through the negative indices history occupies.
|
|
89
|
+
*/
|
|
90
|
+
function weekendKey(clock, minute) {
|
|
91
|
+
const weekday = clock.weekdayOfMinute(minute);
|
|
92
|
+
const dayIndex = clock.dayIndexOfMinute(minute);
|
|
93
|
+
if (weekday === 6)
|
|
94
|
+
return Math.floor(dayIndex / 7);
|
|
95
|
+
if (weekday === 7)
|
|
96
|
+
return Math.floor((dayIndex - 1) / 7);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
36
99
|
function consecutiveDays(maxDays) {
|
|
37
100
|
return (0, support_1.fromVerdict)({
|
|
38
101
|
id: 'consecutive-days',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvF,eAAO,MAAM,uBAAuB,yEAAyE,CAAC;AAE9G,wBAAgB,cAAc,IAAI,oBAAoB,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvF,eAAO,MAAM,uBAAuB,yEAAyE,CAAC;AAE9G,wBAAgB,cAAc,IAAI,oBAAoB,CA8KrD"}
|
|
@@ -28,12 +28,18 @@ function contractLimits() {
|
|
|
28
28
|
weight: 1,
|
|
29
29
|
prune(ctx, eligibility) {
|
|
30
30
|
for (const [employeeId, instances] of eligibility) {
|
|
31
|
-
const
|
|
32
|
-
if (!endDate)
|
|
31
|
+
const contract = ctx.employeeById.get(employeeId)?.contract;
|
|
32
|
+
if (!contract?.startDate && !contract?.endDate)
|
|
33
33
|
continue;
|
|
34
34
|
for (const instanceId of [...instances]) {
|
|
35
35
|
const inst = ctx.instanceById.get(instanceId);
|
|
36
|
-
if (inst
|
|
36
|
+
if (!inst)
|
|
37
|
+
continue;
|
|
38
|
+
// Both ends, one rule: a shift before somebody joins is as
|
|
39
|
+
// unworkable as one after they leave.
|
|
40
|
+
if (contract.endDate && inst.date > contract.endDate)
|
|
41
|
+
instances.delete(instanceId);
|
|
42
|
+
else if (contract.startDate && inst.date < contract.startDate)
|
|
37
43
|
instances.delete(instanceId);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
@@ -46,6 +52,9 @@ function contractLimits() {
|
|
|
46
52
|
if (contract.endDate && inst.date > contract.endDate) {
|
|
47
53
|
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}"'s contract ends ${contract.endDate}, before "${inst.id}"`);
|
|
48
54
|
}
|
|
55
|
+
if (contract.startDate && inst.date < contract.startDate) {
|
|
56
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}"'s contract starts ${contract.startDate}, after "${inst.id}"`);
|
|
57
|
+
}
|
|
49
58
|
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
50
59
|
const probe = {
|
|
51
60
|
start: inst.startMinute,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"employee-scope.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/employee-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,oBAAoB,EAAe,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClH,OAAO,EAA4B,KAAK,wBAAwB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"employee-scope.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/employee-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,oBAAoB,EAAe,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClH,OAAO,EAA4B,KAAK,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAUvF,oGAAoG;AACpG,wBAAgB,wBAAwB,CACpC,OAAO,EAAE,wBAAwB,EACjC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC/C,oBAAoB,EAAE,CA+JxB"}
|