assignment-user-matcher 1.16.1 → 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 +290 -8
- 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/employee-scope.d.ts.map +1 -1
- package/dist/scheduling/constraints/employee-scope.js +10 -2
- 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 +33 -4
- 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 +45 -3
- 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 +9 -1
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +52 -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 +2 -3
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +30 -12
- package/dist/scheduling/operations.d.ts +174 -2
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +513 -15
- 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/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 +107 -1
- 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 +15 -2
|
@@ -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
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";
|
|
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;I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
* 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;
|
|
@@ -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"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.scopeEmployeeConstraints = void 0;
|
|
4
4
|
const constraint_1 = require("./constraint");
|
|
5
5
|
const provenance_1 = require("../provenance");
|
|
6
|
+
const support_1 = require("./support");
|
|
6
7
|
/** Rule families are instantiated once per effective configuration, then dispatched by employee. */
|
|
7
8
|
function scopeEmployeeConstraints(options, rulesByEmployee) {
|
|
8
9
|
const base = (0, constraint_1.createDefaultConstraints)(options);
|
|
@@ -119,7 +120,7 @@ function scopeEmployeeConstraints(options, rulesByEmployee) {
|
|
|
119
120
|
const found = byEmployee.get(pair.employeeId);
|
|
120
121
|
return found && { c: found.constraint, state: { ...state, ctx: found.context(state.ctx) } };
|
|
121
122
|
};
|
|
122
|
-
|
|
123
|
+
const scoped = {
|
|
123
124
|
...prototype,
|
|
124
125
|
delta(state, pair) {
|
|
125
126
|
const d = delegate(state, pair);
|
|
@@ -150,7 +151,14 @@ function scopeEmployeeConstraints(options, rulesByEmployee) {
|
|
|
150
151
|
evaluate: delegates.some((d) => d.constraint.evaluate)
|
|
151
152
|
? (state) => delegates.flatMap((d) => d.constraint.evaluate?.(d.view(state, true)) ?? [])
|
|
152
153
|
: undefined,
|
|
153
|
-
}
|
|
154
|
+
};
|
|
155
|
+
// The wrapper mirrors when every delegate does (a delegate without a
|
|
156
|
+
// verdict has one synthesised from its delta above), and its own
|
|
157
|
+
// no-delegate answer is (0, pass).
|
|
158
|
+
if (delegates.every((d) => !d.constraint.verdict || (0, support_1.deltaMirrorsVerdict)(d.constraint))) {
|
|
159
|
+
(0, support_1.markDeltaMirrorsVerdict)(scoped);
|
|
160
|
+
}
|
|
161
|
+
registry.set(id, scoped);
|
|
154
162
|
}
|
|
155
163
|
return [...registry.values()];
|
|
156
164
|
}
|
|
@@ -33,14 +33,10 @@ export declare function pass(ruleId: string, message: string, extra?: Partial<Ru
|
|
|
33
33
|
export declare function fail(ruleId: string, severity: Severity, message: string, extra?: Partial<RuleVerdict>): RuleVerdict;
|
|
34
34
|
/** Hours, to one decimal, for human-readable messages. */
|
|
35
35
|
export declare function h(minutes: number): string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* `magnitude` converts a failing verdict into a breach size: local search needs
|
|
41
|
-
* to know a rest gap is 10 minutes short rather than merely "short", or it sits
|
|
42
|
-
* on a plateau with no gradient to follow.
|
|
43
|
-
*/
|
|
36
|
+
export declare function markDeltaMirrorsVerdict(constraint: SchedulingConstraint): void;
|
|
37
|
+
export declare function deltaMirrorsVerdict(constraint: SchedulingConstraint): boolean;
|
|
38
|
+
/** Rules the library registered itself, as opposed to `constraints.custom`. */
|
|
39
|
+
export declare const builtInConstraints: WeakSet<SchedulingConstraint>;
|
|
44
40
|
export declare function fromVerdict(spec: Omit<SchedulingConstraint, 'delta' | 'explain' | 'verdict'> & {
|
|
45
41
|
verdict(state: SearchState, pair: AssignmentPair): RuleVerdict;
|
|
46
42
|
magnitude?(v: RuleVerdict): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/support.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACR,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,gBAAgB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,oDAAoD;AACpD,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAElF;AAED,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GA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ACvB,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC,GAAG;IAChE,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,WAAW,CAAC;IAC/D,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CACtC,GACF,oBAAoB,CAgBtB"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* its rule.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.fromVerdict = exports.h = exports.fail = exports.pass = exports.windowAround = exports.instanceOf = exports.entryIdOf = exports.rangeOf = exports.rulesFor = exports.timelineFor = exports.personIdFor = exports.MINUTES_PER_DAY = void 0;
|
|
11
|
+
exports.fromVerdict = exports.builtInConstraints = exports.deltaMirrorsVerdict = exports.markDeltaMirrorsVerdict = exports.h = exports.fail = exports.pass = exports.windowAround = exports.instanceOf = exports.entryIdOf = exports.rangeOf = exports.rulesFor = exports.timelineFor = exports.personIdFor = exports.MINUTES_PER_DAY = void 0;
|
|
12
12
|
const state_1 = require("../engine/state");
|
|
13
13
|
exports.MINUTES_PER_DAY = 1440;
|
|
14
14
|
/** The natural person behind an employee record. */
|
|
@@ -73,9 +73,28 @@ exports.h = h;
|
|
|
73
73
|
* to know a rest gap is 10 minutes short rather than merely "short", or it sits
|
|
74
74
|
* on a plateau with no gradient to follow.
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* `delta` functions that are non-zero exactly when their constraint's
|
|
78
|
+
* `verdict` fails — every `fromVerdict` rule's, and the per-employee scoping
|
|
79
|
+
* wrapper's over them. Lets a hard-breach check read one verdict instead of
|
|
80
|
+
* computing it twice. Keyed by the function, not the constraint, so a rule
|
|
81
|
+
* that replaces its `delta` afterwards (availability keeps soft wishes out of
|
|
82
|
+
* it) is no longer treated as a mirror.
|
|
83
|
+
*/
|
|
84
|
+
const mirroringDeltas = new WeakSet();
|
|
85
|
+
function markDeltaMirrorsVerdict(constraint) {
|
|
86
|
+
mirroringDeltas.add(constraint.delta);
|
|
87
|
+
}
|
|
88
|
+
exports.markDeltaMirrorsVerdict = markDeltaMirrorsVerdict;
|
|
89
|
+
function deltaMirrorsVerdict(constraint) {
|
|
90
|
+
return constraint.verdict !== undefined && mirroringDeltas.has(constraint.delta);
|
|
91
|
+
}
|
|
92
|
+
exports.deltaMirrorsVerdict = deltaMirrorsVerdict;
|
|
93
|
+
/** Rules the library registered itself, as opposed to `constraints.custom`. */
|
|
94
|
+
exports.builtInConstraints = new WeakSet();
|
|
76
95
|
function fromVerdict(spec) {
|
|
77
96
|
const magnitude = spec.magnitude ?? defaultMagnitude;
|
|
78
|
-
|
|
97
|
+
const constraint = {
|
|
79
98
|
...spec,
|
|
80
99
|
verdict: spec.verdict,
|
|
81
100
|
delta(state, pair) {
|
|
@@ -87,6 +106,8 @@ function fromVerdict(spec) {
|
|
|
87
106
|
return v.pass ? null : v.message;
|
|
88
107
|
},
|
|
89
108
|
};
|
|
109
|
+
markDeltaMirrorsVerdict(constraint);
|
|
110
|
+
return constraint;
|
|
90
111
|
}
|
|
91
112
|
exports.fromVerdict = fromVerdict;
|
|
92
113
|
/** Shortfall or excess against the bound, when both are known; 1 otherwise. */
|
|
@@ -17,6 +17,34 @@
|
|
|
17
17
|
* `minMinutes` and both are checked.
|
|
18
18
|
*/
|
|
19
19
|
import type { SchedulingConstraint, WeeklyRestRule } from '../types';
|
|
20
|
+
import type { PersonTimeline } from '../engine/timeline';
|
|
20
21
|
export declare const WEEKLY_REST_CITATION = "Directive 2003/88/EC Art 5";
|
|
21
22
|
export declare function weeklyRest(rule: WeeklyRestRule): SchedulingConstraint;
|
|
23
|
+
/**
|
|
24
|
+
* Rest that counts towards an averaged weekly-rest requirement in the window
|
|
25
|
+
* `[start, start + averagingMinutes)`: each free stretch contributes whole
|
|
26
|
+
* multiples of `minPer`, so two 30h gaps are worth nothing against a 48h
|
|
27
|
+
* requirement and one 100h gap is worth 96h.
|
|
28
|
+
*/
|
|
29
|
+
export declare function qualifyingRestAt(timeline: PersonTimeline, start: number, averagingMinutes: number, minPer: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* The least qualifying rest in any window starting at an integer minute in
|
|
32
|
+
* `[lo, hi]` — exactly, not over a sample of starts.
|
|
33
|
+
*
|
|
34
|
+
* The quantity is a step function of the window start, and its minima are
|
|
35
|
+
* not only where an edge meets a shift boundary: they also sit where the
|
|
36
|
+
* leading or trailing gap crosses a multiple of `minPer`. So the starts are
|
|
37
|
+
* split into segments on which the window's structure is fixed — the same
|
|
38
|
+
* shifts intersect it, and the same edges are free — using every boundary at
|
|
39
|
+
* which that can change. Inside a segment the value is
|
|
40
|
+
*
|
|
41
|
+
* inner + m·⌊(a − s)/m⌋ [leading gap] + m·⌊(s + A − b)/m⌋ [trailing gap]
|
|
42
|
+
*
|
|
43
|
+
* which is falling in `s` with only a leading gap (least at the segment's
|
|
44
|
+
* end), rising with only a trailing one (least at its start), and with both
|
|
45
|
+
* dips one step below `m·⌊C/m⌋` exactly where `(a − s) mod m` exceeds
|
|
46
|
+
* `C mod m`, `C = a + A − b` — the first such start is the only other
|
|
47
|
+
* candidate. Each candidate is then measured directly.
|
|
48
|
+
*/
|
|
49
|
+
export declare function worstQualifyingRest(timeline: PersonTimeline, averagingMinutes: number, lo: number, hi: number, minPer: number): number;
|
|
22
50
|
//# sourceMappingURL=weekly-rest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weekly-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/weekly-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"weekly-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/weekly-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AAEjE,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,oBAAoB,CAuErE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAM1H;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAC/B,QAAQ,EAAE,cAAc,EACxB,gBAAgB,EAAE,MAAM,EACxB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,GACf,MAAM,CA+DR"}
|