assignment-user-matcher 1.10.0 → 1.11.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 +59 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/learning/auto-weights.d.ts +7 -4
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +7 -6
- package/dist/lua/workflow-transition.lua +8 -2
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +47 -0
- package/dist/managers/WorkflowManager.d.ts +7 -1
- package/dist/managers/WorkflowManager.d.ts.map +1 -1
- package/dist/managers/WorkflowManager.js +85 -12
- package/dist/matcher.class.d.ts +35 -3
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +308 -76
- package/dist/queries/users.d.ts +34 -0
- package/dist/queries/users.d.ts.map +1 -0
- package/dist/queries/users.js +227 -0
- package/dist/scheduling/constraints/availability.d.ts +0 -1
- package/dist/scheduling/constraints/availability.d.ts.map +1 -1
- package/dist/scheduling/constraints/availability.js +27 -4
- package/dist/scheduling/constraints/contract.d.ts.map +1 -1
- package/dist/scheduling/constraints/contract.js +17 -3
- package/dist/scheduling/constraints/daily-rest.d.ts.map +1 -1
- package/dist/scheduling/constraints/daily-rest.js +7 -2
- package/dist/scheduling/constraints/hour-budget.d.ts.map +1 -1
- package/dist/scheduling/constraints/hour-budget.js +7 -1
- package/dist/scheduling/constraints/in-shift-breaks.d.ts.map +1 -1
- package/dist/scheduling/constraints/in-shift-breaks.js +4 -2
- package/dist/scheduling/constraints/min-rest.d.ts.map +1 -1
- package/dist/scheduling/constraints/min-rest.js +8 -19
- package/dist/scheduling/constraints/night-work.js +17 -1
- package/dist/scheduling/constraints/no-overlap.d.ts +5 -1
- package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -1
- package/dist/scheduling/constraints/no-overlap.js +11 -12
- package/dist/scheduling/constraints/weekly-rest.js +12 -1
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +7 -0
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +1 -0
- package/dist/scheduling/time.d.ts +6 -0
- package/dist/scheduling/time.d.ts.map +1 -1
- package/dist/scheduling/time.js +20 -9
- package/dist/scheduling/types.d.ts +6 -0
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/types/matcher.d.ts +71 -2
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/utils/keys.d.ts +1 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User status & workload query helpers: paginated user scans with
|
|
3
|
+
* status/backlog filters, batch summaries, and per-user accepted-work reads.
|
|
4
|
+
*
|
|
5
|
+
* All reads are bounded: the users hash is paged with HSCAN, per-page reads
|
|
6
|
+
* are batched into a single multi(), and JSON.parse is always guarded.
|
|
7
|
+
*/
|
|
8
|
+
import type { KeyBuilders } from '../utils/keys';
|
|
9
|
+
import type { RedisClientType, User, ActiveAssignmentInfo, UserQueryOptions, UserQueryResult, UserSummary } from '../matcher.class';
|
|
10
|
+
/**
|
|
11
|
+
* Effective backlog cap for one user. Injected by the facade because the pure
|
|
12
|
+
* module cannot see the matcher-wide default (`backlogLimitFor` is private).
|
|
13
|
+
*/
|
|
14
|
+
export type MaxBacklogSizeFor = (user: User) => number;
|
|
15
|
+
/**
|
|
16
|
+
* Paginated user scan with composable filters. The cursor is an opaque HSCAN
|
|
17
|
+
* cursor — pass `nextCursor` back verbatim. Because a scan page is never
|
|
18
|
+
* split mid-way, a returned page may exceed `limit` by less than one scan
|
|
19
|
+
* page, and filtered scans may return fewer than `limit` users while
|
|
20
|
+
* `hasMore` is still true; keep consuming until `hasMore` is false.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getUsersPaginatedFromStore(redisClient: RedisClientType, keys: KeyBuilders, options: UserQueryOptions | undefined, maxBacklogSizeFor: MaxBacklogSizeFor): Promise<UserQueryResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Order-preserving batch summary read. Missing users are omitted (mirrors
|
|
25
|
+
* getAssignmentsByIds). Chunked multi() keeps pipelines bounded.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getUserSummariesBatch(redisClient: RedisClientType, keys: KeyBuilders, userIds: string[], maxBacklogSizeFor: MaxBacklogSizeFor): Promise<UserSummary[]>;
|
|
28
|
+
/**
|
|
29
|
+
* A user's accepted (in-progress) assignments, newest first. Verified against
|
|
30
|
+
* the accepted hash: members orphaned by a missed index removal are dropped
|
|
31
|
+
* from the result and self-healed with a zRem.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getActiveAssignmentsFromStore(redisClient: RedisClientType, keys: KeyBuilders, userId: string): Promise<ActiveAssignmentInfo[]>;
|
|
34
|
+
//# sourceMappingURL=users.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/queries/users.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EACR,eAAe,EACf,IAAI,EACJ,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,WAAW,EACd,MAAM,kBAAkB,CAAC;AAY1B;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;AAiBvD;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC5C,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,gBAAgB,GAAG,SAAS,EACrC,iBAAiB,EAAE,iBAAiB,GACrC,OAAO,CAAC,eAAe,CAAC,CAiI1B;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACvC,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EAAE,EACjB,iBAAiB,EAAE,iBAAiB,GACrC,OAAO,CAAC,WAAW,EAAE,CAAC,CAyCxB;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CAC/C,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAuBjC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getActiveAssignmentsFromStore = exports.getUserSummariesBatch = exports.getUsersPaginatedFromStore = void 0;
|
|
4
|
+
/** HSCAN page hint, matching the matcher-wide convention. */
|
|
5
|
+
const USER_SCAN_COUNT = 500;
|
|
6
|
+
/** Hard ceiling for a single user-query page. */
|
|
7
|
+
const MAX_USER_QUERY_LIMIT = 1000;
|
|
8
|
+
const DEFAULT_USER_QUERY_LIMIT = 100;
|
|
9
|
+
/** Chunk size for batched multi() reads. */
|
|
10
|
+
const MULTI_CHUNK_SIZE = 500;
|
|
11
|
+
/** Backlog set members are stored as `assignment:{id}`. */
|
|
12
|
+
const BACKLOG_MEMBER_PREFIX = 'assignment:';
|
|
13
|
+
function clampLimit(limit) {
|
|
14
|
+
if (typeof limit !== 'number' || !Number.isFinite(limit))
|
|
15
|
+
return DEFAULT_USER_QUERY_LIMIT;
|
|
16
|
+
return Math.max(1, Math.min(Math.floor(limit), MAX_USER_QUERY_LIMIT));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Paginated user scan with composable filters. The cursor is an opaque HSCAN
|
|
20
|
+
* cursor — pass `nextCursor` back verbatim. Because a scan page is never
|
|
21
|
+
* split mid-way, a returned page may exceed `limit` by less than one scan
|
|
22
|
+
* page, and filtered scans may return fewer than `limit` users while
|
|
23
|
+
* `hasMore` is still true; keep consuming until `hasMore` is false.
|
|
24
|
+
*/
|
|
25
|
+
async function getUsersPaginatedFromStore(redisClient, keys, options, maxBacklogSizeFor) {
|
|
26
|
+
const limit = clampLimit(options?.limit);
|
|
27
|
+
const status = options?.status ?? 'all';
|
|
28
|
+
const hasBacklog = options?.hasBacklog ?? false;
|
|
29
|
+
const atCapacity = options?.atCapacity ?? false;
|
|
30
|
+
const includeAssignments = options?.includeAssignments ?? false;
|
|
31
|
+
// Idle predicate: needs a threshold. 'idle' status without one matches
|
|
32
|
+
// nobody (the facade substitutes idleUserTimeoutMs when configured).
|
|
33
|
+
const idleForMs = options?.idleForMs;
|
|
34
|
+
const idleCutoff = typeof idleForMs === 'number' && Number.isFinite(idleForMs) ? Date.now() - idleForMs : null;
|
|
35
|
+
const idleFilterActive = idleCutoff !== null;
|
|
36
|
+
const idleRequired = status === 'idle';
|
|
37
|
+
// The paused pool is small by design: one read per call, not per user.
|
|
38
|
+
const pausedMembers = new Set(await redisClient.sMembers(keys.pausedUsers()));
|
|
39
|
+
const matches = [];
|
|
40
|
+
let cursor = options?.cursor ?? '0';
|
|
41
|
+
do {
|
|
42
|
+
const { cursor: nextCursor, entries } = await redisClient.hScan(keys.users(), cursor, {
|
|
43
|
+
// Adapt the hint to what's still needed, floored at 100 (don't
|
|
44
|
+
// dribble) and capped at the scan-page convention.
|
|
45
|
+
COUNT: Math.max(Math.min(limit - matches.length, USER_SCAN_COUNT), 100),
|
|
46
|
+
});
|
|
47
|
+
cursor = nextCursor;
|
|
48
|
+
// Cheap pre-filter on fields already in hand (status), so the
|
|
49
|
+
// pipelined reads below only run for survivors.
|
|
50
|
+
const page = [];
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
let user;
|
|
53
|
+
try {
|
|
54
|
+
user = JSON.parse(entry.value);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Skip corrupt entries (same precedent as getAllAssignmentsFromStores)
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const paused = pausedMembers.has(user.id);
|
|
61
|
+
if (status === 'paused' && !paused)
|
|
62
|
+
continue;
|
|
63
|
+
if (status === 'active' && paused)
|
|
64
|
+
continue;
|
|
65
|
+
page.push({ user, paused });
|
|
66
|
+
}
|
|
67
|
+
if (page.length > 0) {
|
|
68
|
+
// One multi() per page: backlog depth, activity score, accepted count.
|
|
69
|
+
const multi = redisClient.multi();
|
|
70
|
+
for (const { user } of page) {
|
|
71
|
+
multi.sCard(keys.userAssignments(user.id));
|
|
72
|
+
multi.zScore(keys.userActivity(), user.id);
|
|
73
|
+
multi.zCard(keys.userAcceptedAssignments(user.id));
|
|
74
|
+
}
|
|
75
|
+
const results = (await multi.exec());
|
|
76
|
+
for (let i = 0; i < page.length; i++) {
|
|
77
|
+
const { user, paused } = page[i];
|
|
78
|
+
const backlog = Number(results[i * 3] ?? 0);
|
|
79
|
+
const activityScore = results[i * 3 + 1];
|
|
80
|
+
const lastActiveAt = activityScore === null || activityScore === undefined ? null : Number(activityScore);
|
|
81
|
+
const acceptedCount = Number(results[i * 3 + 2] ?? 0);
|
|
82
|
+
const maxBacklogSize = maxBacklogSizeFor(user);
|
|
83
|
+
const entry = {
|
|
84
|
+
user,
|
|
85
|
+
paused,
|
|
86
|
+
backlog,
|
|
87
|
+
lastActiveAt,
|
|
88
|
+
acceptedCount,
|
|
89
|
+
maxBacklogSize,
|
|
90
|
+
atCapacity: backlog >= maxBacklogSize,
|
|
91
|
+
};
|
|
92
|
+
// Users with no recorded activity are not idle: idleness needs
|
|
93
|
+
// a reference point (addUser touches on creation, so null only
|
|
94
|
+
// appears for externally-written records).
|
|
95
|
+
const idle = entry.lastActiveAt !== null && idleCutoff !== null && entry.lastActiveAt <= idleCutoff;
|
|
96
|
+
if ((idleRequired || idleFilterActive) && !idle)
|
|
97
|
+
continue;
|
|
98
|
+
if (hasBacklog && entry.backlog === 0)
|
|
99
|
+
continue;
|
|
100
|
+
if (atCapacity && !entry.atCapacity)
|
|
101
|
+
continue;
|
|
102
|
+
matches.push(entry);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// A scan page is never split: stop only at a page boundary.
|
|
106
|
+
} while (matches.length < limit && cursor !== '0');
|
|
107
|
+
const hasMore = cursor !== '0';
|
|
108
|
+
const users = matches.map((entry) => ({
|
|
109
|
+
userId: entry.user.id,
|
|
110
|
+
user: entry.user,
|
|
111
|
+
paused: entry.paused,
|
|
112
|
+
lastActiveAt: entry.lastActiveAt,
|
|
113
|
+
backlog: entry.backlog,
|
|
114
|
+
acceptedCount: entry.acceptedCount,
|
|
115
|
+
maxBacklogSize: entry.maxBacklogSize,
|
|
116
|
+
atCapacity: entry.atCapacity,
|
|
117
|
+
}));
|
|
118
|
+
if (includeAssignments && matches.length > 0) {
|
|
119
|
+
// Per-user assignment ids for the returned page only, chunked.
|
|
120
|
+
for (let start = 0; start < matches.length; start += MULTI_CHUNK_SIZE) {
|
|
121
|
+
const chunk = matches.slice(start, start + MULTI_CHUNK_SIZE);
|
|
122
|
+
const multi = redisClient.multi();
|
|
123
|
+
for (const { user } of chunk) {
|
|
124
|
+
multi.sMembers(keys.userAssignments(user.id));
|
|
125
|
+
multi.zRange(keys.userAcceptedAssignments(user.id), 0, -1, { REV: true });
|
|
126
|
+
}
|
|
127
|
+
const results = (await multi.exec());
|
|
128
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
129
|
+
const summary = users[start + i];
|
|
130
|
+
// Backlog members are `assignment:{id}`; accepted ids are raw.
|
|
131
|
+
// Accepted ids are NOT verified against the accepted hash here
|
|
132
|
+
// (a stale member may appear); getActiveAssignmentsForUser is
|
|
133
|
+
// the verified read.
|
|
134
|
+
summary.pendingAssignmentIds = (results[i * 2] ?? []).map((m) => m.slice(BACKLOG_MEMBER_PREFIX.length));
|
|
135
|
+
summary.acceptedAssignmentIds = results[i * 2 + 1] ?? [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const result = {
|
|
140
|
+
users,
|
|
141
|
+
nextCursor: hasMore ? cursor : null,
|
|
142
|
+
hasMore,
|
|
143
|
+
};
|
|
144
|
+
if (options?.includeTotal) {
|
|
145
|
+
result.total = await redisClient.hLen(keys.users());
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
exports.getUsersPaginatedFromStore = getUsersPaginatedFromStore;
|
|
150
|
+
/**
|
|
151
|
+
* Order-preserving batch summary read. Missing users are omitted (mirrors
|
|
152
|
+
* getAssignmentsByIds). Chunked multi() keeps pipelines bounded.
|
|
153
|
+
*/
|
|
154
|
+
async function getUserSummariesBatch(redisClient, keys, userIds, maxBacklogSizeFor) {
|
|
155
|
+
if (userIds.length === 0)
|
|
156
|
+
return [];
|
|
157
|
+
const summaries = [];
|
|
158
|
+
for (let start = 0; start < userIds.length; start += MULTI_CHUNK_SIZE) {
|
|
159
|
+
const chunk = userIds.slice(start, start + MULTI_CHUNK_SIZE);
|
|
160
|
+
const multi = redisClient.multi();
|
|
161
|
+
for (const userId of chunk) {
|
|
162
|
+
multi.hGet(keys.users(), userId);
|
|
163
|
+
multi.sIsMember(keys.pausedUsers(), userId);
|
|
164
|
+
multi.sCard(keys.userAssignments(userId));
|
|
165
|
+
multi.zCard(keys.userAcceptedAssignments(userId));
|
|
166
|
+
multi.zScore(keys.userActivity(), userId);
|
|
167
|
+
}
|
|
168
|
+
const results = (await multi.exec());
|
|
169
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
170
|
+
const json = results[i * 5];
|
|
171
|
+
if (typeof json !== 'string')
|
|
172
|
+
continue; // missing user: omitted
|
|
173
|
+
let user;
|
|
174
|
+
try {
|
|
175
|
+
user = JSON.parse(json);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
continue; // corrupt entry: omitted
|
|
179
|
+
}
|
|
180
|
+
const activityScore = results[i * 5 + 4];
|
|
181
|
+
const backlog = Number(results[i * 5 + 2] ?? 0);
|
|
182
|
+
const maxBacklogSize = maxBacklogSizeFor(user);
|
|
183
|
+
summaries.push({
|
|
184
|
+
userId: user.id,
|
|
185
|
+
user,
|
|
186
|
+
paused: Boolean(results[i * 5 + 1]),
|
|
187
|
+
lastActiveAt: activityScore === null || activityScore === undefined ? null : Number(activityScore),
|
|
188
|
+
backlog,
|
|
189
|
+
acceptedCount: Number(results[i * 5 + 3] ?? 0),
|
|
190
|
+
maxBacklogSize,
|
|
191
|
+
atCapacity: backlog >= maxBacklogSize,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return summaries;
|
|
196
|
+
}
|
|
197
|
+
exports.getUserSummariesBatch = getUserSummariesBatch;
|
|
198
|
+
/**
|
|
199
|
+
* A user's accepted (in-progress) assignments, newest first. Verified against
|
|
200
|
+
* the accepted hash: members orphaned by a missed index removal are dropped
|
|
201
|
+
* from the result and self-healed with a zRem.
|
|
202
|
+
*/
|
|
203
|
+
async function getActiveAssignmentsFromStore(redisClient, keys, userId) {
|
|
204
|
+
const entries = await redisClient.zRangeWithScores(keys.userAcceptedAssignments(userId), 0, -1, { REV: true });
|
|
205
|
+
if (entries.length === 0)
|
|
206
|
+
return [];
|
|
207
|
+
const multi = redisClient.multi();
|
|
208
|
+
for (const entry of entries) {
|
|
209
|
+
multi.hGet(keys.acceptedAssignments(), entry.value);
|
|
210
|
+
}
|
|
211
|
+
const jsons = (await multi.exec());
|
|
212
|
+
const active = [];
|
|
213
|
+
const stale = [];
|
|
214
|
+
for (let i = 0; i < entries.length; i++) {
|
|
215
|
+
if (jsons[i]) {
|
|
216
|
+
active.push({ assignmentId: entries[i].value, acceptedAt: Number(entries[i].score) });
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
stale.push(entries[i].value);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (stale.length > 0) {
|
|
223
|
+
await redisClient.zRem(keys.userAcceptedAssignments(userId), stale);
|
|
224
|
+
}
|
|
225
|
+
return active;
|
|
226
|
+
}
|
|
227
|
+
exports.getActiveAssignmentsFromStore = getActiveAssignmentsFromStore;
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { AvailabilityRule, SchedulingConstraint, SearchState, ShiftInstance } from '../types';
|
|
19
19
|
export declare function availability(): SchedulingConstraint;
|
|
20
|
-
/** Minutes of `range` covered by one availability rule's clock window. */
|
|
21
20
|
declare function overlapsRule(clock: {
|
|
22
21
|
minutesInClockRange: (r: {
|
|
23
22
|
start: number;
|
|
@@ -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;AAIhH,wBAAgB,YAAY,IAAI,oBAAoB,
|
|
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;AAIhH,wBAAgB,YAAY,IAAI,oBAAoB,CAqFnD;AAkCD,iBAAS,YAAY,CACjB,KAAK,EAAE;IAAE,mBAAmB,EAAE,CAAC,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAA;CAAE,EAC9G,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACrC,IAAI,EAAE,gBAAgB,GACvB,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAW5D;AAED,uFAAuF;AACvF,wBAAgB,eAAe,CAC3B,KAAK,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EACzC,KAAK,EAAE,gBAAgB,EAAE,GAAG,SAAS,EACrC,IAAI,EAAE,aAAa,GACpB,MAAM,CAWR"}
|
|
@@ -42,11 +42,11 @@ function availability() {
|
|
|
42
42
|
// Declaring any 'available' window inverts the default: everything
|
|
43
43
|
// outside every declared window is ineligible, including days no
|
|
44
44
|
// window mentions — a Monday-only declaration bars Tuesdays too.
|
|
45
|
+
// Coverage is the UNION of the declared windows: a shift spanning
|
|
46
|
+
// two contiguous windows lies inside the declaration.
|
|
45
47
|
const allowLists = employee.availability.filter((r) => r.kind === 'available');
|
|
46
48
|
if (allowLists.length > 0) {
|
|
47
|
-
const covered = matching
|
|
48
|
-
.filter((r) => r.kind === 'available')
|
|
49
|
-
.reduce((max, rule) => Math.max(max, overlapsRule(clock, range, rule)), 0);
|
|
49
|
+
const covered = unionCoveredMinutes(clock, range, matching.filter((r) => r.kind === 'available'));
|
|
50
50
|
if (covered < span) {
|
|
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
|
}
|
|
@@ -93,7 +93,30 @@ function availability() {
|
|
|
93
93
|
return constraint;
|
|
94
94
|
}
|
|
95
95
|
exports.availability = availability;
|
|
96
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Minutes of `range` covered by the union of the given windows. A window with
|
|
98
|
+
* no `from`/`to` covers the whole range; timed windows are projected onto the
|
|
99
|
+
* range via the clock (same per-day band semantics as `overlapsRule`) and
|
|
100
|
+
* merged, so contiguous or overlapping declarations never undercount.
|
|
101
|
+
*/
|
|
102
|
+
function unionCoveredMinutes(clock, range, rules) {
|
|
103
|
+
const intervals = [];
|
|
104
|
+
for (const rule of rules) {
|
|
105
|
+
if (rule.from === undefined || rule.to === undefined)
|
|
106
|
+
return range.end - range.start;
|
|
107
|
+
intervals.push(...clock.clockRangeIntervals(range, { from: rule.from, to: rule.to }));
|
|
108
|
+
}
|
|
109
|
+
intervals.sort((a, b) => a.start - b.start);
|
|
110
|
+
let covered = 0;
|
|
111
|
+
let cursor = range.start;
|
|
112
|
+
for (const interval of intervals) {
|
|
113
|
+
if (interval.end <= cursor)
|
|
114
|
+
continue;
|
|
115
|
+
covered += interval.end - Math.max(interval.start, cursor);
|
|
116
|
+
cursor = interval.end;
|
|
117
|
+
}
|
|
118
|
+
return covered;
|
|
119
|
+
}
|
|
97
120
|
function overlapsRule(clock, range, rule) {
|
|
98
121
|
if (rule.from === undefined || rule.to === undefined)
|
|
99
122
|
return range.end - range.start;
|
|
@@ -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,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,wBAAgB,cAAc,IAAI,oBAAoB,CAkHrD"}
|
|
@@ -54,9 +54,19 @@ function contractLimits() {
|
|
|
54
54
|
};
|
|
55
55
|
return timeline.withEntry(probe, (t) => {
|
|
56
56
|
const periodWindow = { start: 0, end: state.ctx.periodDays * support_1.MINUTES_PER_DAY };
|
|
57
|
+
// A contract bounds the employee *record*, not the person (the
|
|
58
|
+
// same per-record reading as the minimum aggregate below and the
|
|
59
|
+
// timeOffInLieu ledger): the person timeline also carries
|
|
60
|
+
// sibling contracts' entries, which must not eat this
|
|
61
|
+
// contract's budget. Roster entries are attributable by their
|
|
62
|
+
// `${employeeId}@@` prefix; history entries are not
|
|
63
|
+
// attributable to either record, so they count conservatively.
|
|
64
|
+
const ownPrefix = `${pair.employeeId}@@`;
|
|
65
|
+
const attributable = t
|
|
66
|
+
.entriesIn(periodWindow)
|
|
67
|
+
.filter((e) => !e.id.includes('@@') || e.id.startsWith(ownPrefix));
|
|
57
68
|
if (contract.kind === 'days' && contract.maxDaysInPeriod !== undefined) {
|
|
58
|
-
const days = new Set(
|
|
59
|
-
.size;
|
|
69
|
+
const days = new Set(attributable.map((e) => state.ctx.clock.dayIndexOfMinute(e.start))).size;
|
|
60
70
|
if (days > contract.maxDaysInPeriod) {
|
|
61
71
|
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
72
|
}
|
|
@@ -68,7 +78,11 @@ function contractLimits() {
|
|
|
68
78
|
});
|
|
69
79
|
}
|
|
70
80
|
if (contract.maxPeriodMinutes !== undefined) {
|
|
71
|
-
const worked =
|
|
81
|
+
const worked = attributable.reduce((sum, e) => {
|
|
82
|
+
const overlap = Math.min(e.end, periodWindow.end) - Math.max(e.start, periodWindow.start);
|
|
83
|
+
const span = e.end - e.start;
|
|
84
|
+
return sum + (span > 0 ? Math.round((e.workingMinutes * Math.max(0, overlap)) / span) : 0);
|
|
85
|
+
}, 0);
|
|
72
86
|
if (worked > contract.maxPeriodMinutes) {
|
|
73
87
|
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
88
|
}
|
|
@@ -1 +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,
|
|
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,CA8FnE"}
|
|
@@ -40,8 +40,13 @@ function dailyRest(rule) {
|
|
|
40
40
|
const gap = timeline.minGapAround(range, (0, support_1.entryIdOf)(pair));
|
|
41
41
|
if (gap === 0) {
|
|
42
42
|
// Overlapping work is `no-overlap`'s business; reporting it here
|
|
43
|
-
// too would double-count the same defect.
|
|
44
|
-
|
|
43
|
+
// too would double-count the same defect. A zero gap without an
|
|
44
|
+
// overlap is back-to-back work, and that IS this rule's business
|
|
45
|
+
// — fall through to the floor check.
|
|
46
|
+
const own = (0, support_1.entryIdOf)(pair);
|
|
47
|
+
const overlapping = timeline.entriesIn(range).some((e) => e.id !== own);
|
|
48
|
+
if (overlapping)
|
|
49
|
+
return (0, support_1.pass)('daily-rest', 'overlap is handled by no-overlap');
|
|
45
50
|
}
|
|
46
51
|
if (gap < floor) {
|
|
47
52
|
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 });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hour-budget.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/hour-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErG,wBAAgB,UAAU,IAAI,oBAAoB,
|
|
1
|
+
{"version":3,"file":"hour-budget.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/hour-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErG,wBAAgB,UAAU,IAAI,oBAAoB,CA8BjD;AAED,sDAAsD;AACtD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAgB9G"}
|
|
@@ -24,8 +24,14 @@ function hourBudget() {
|
|
|
24
24
|
// working time, and the budget is documented as *worked* hours, so
|
|
25
25
|
// the candidate must contribute in the same unit — an unpaid break
|
|
26
26
|
// or a fractional duty must not be double-counted against it.
|
|
27
|
+
// An already-assigned pair's shift is in the total, so it is not
|
|
28
|
+
// added again (the same self-exclusion `withEntry` gives the
|
|
29
|
+
// timeline rules): re-judging a committed roster must ask "is the
|
|
30
|
+
// total over the cap", not "would the cap survive this twice".
|
|
27
31
|
const current = state.minutesByEmployee.get(pair.employeeId) ?? 0;
|
|
28
|
-
|
|
32
|
+
const assigned = state.assignments.get(pair.shiftInstanceId)?.has(pair.employeeId) ?? false;
|
|
33
|
+
const total = assigned ? current : current + inst.workingMinutes;
|
|
34
|
+
return total > employee.maxHoursForPeriod * 60 ? 1 : 0;
|
|
29
35
|
},
|
|
30
36
|
explain(state, pair) {
|
|
31
37
|
const employee = state.ctx.employeeById.get(pair.employeeId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-shift-breaks.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/in-shift-breaks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAoC,oBAAoB,EAAiB,MAAM,UAAU,CAAC;AAGjH,eAAO,MAAM,cAAc,+BAA+B,CAAC;AAE3D,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"in-shift-breaks.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/in-shift-breaks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAoC,oBAAoB,EAAiB,MAAM,UAAU,CAAC;AAGjH,eAAO,MAAM,cAAc,+BAA+B,CAAC;AAE3D,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,oBAAoB,CA6EtE"}
|
|
@@ -33,12 +33,14 @@ function inShiftBreaks(rules) {
|
|
|
33
33
|
// An interruptible break provides nothing towards the entitlement
|
|
34
34
|
// (C-107/19). A `paid: true` entitlement is discharged only by declared
|
|
35
35
|
// paid break minutes — an unpaid break costs the worker wages, which is
|
|
36
|
-
// exactly what the paid entitlement exists to prevent.
|
|
36
|
+
// exactly what the paid entitlement exists to prevent. Declared break
|
|
37
|
+
// minutes, never span − working: on a duty-scaled shift the difference
|
|
38
|
+
// is duty occupation, not rest.
|
|
37
39
|
const provided = applicable.interruptible
|
|
38
40
|
? 0
|
|
39
41
|
: applicable.paid
|
|
40
42
|
? inst.paidBreakMinutes
|
|
41
|
-
: inst.
|
|
43
|
+
: inst.unpaidBreakMinutes + inst.paidBreakMinutes;
|
|
42
44
|
if (provided >= applicable.minMinutes)
|
|
43
45
|
return null;
|
|
44
46
|
return { rule: applicable, provided };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"min-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/min-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAA+B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"min-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/min-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAA+B,MAAM,UAAU,CAAC;AAGlF,0FAA0F;AAC1F,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,wBAAgB,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,oBAAoB,CAuBpE"}
|
|
@@ -18,31 +18,20 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.minRest = exports.DEFAULT_MIN_REST_MINUTES = void 0;
|
|
21
|
+
const support_1 = require("./support");
|
|
21
22
|
/** EU floor: Directive 2003/88/EC Article 3 — 11 consecutive hours per 24-hour period. */
|
|
22
23
|
exports.DEFAULT_MIN_REST_MINUTES = 660;
|
|
23
24
|
function minRest(minRestMinutes) {
|
|
24
25
|
const breach = (state, pair) => {
|
|
25
|
-
const inst =
|
|
26
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
26
27
|
if (!inst)
|
|
27
28
|
return false;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const other = state.ctx.instanceById.get(otherId);
|
|
35
|
-
if (!other)
|
|
36
|
-
continue;
|
|
37
|
-
const gap = inst.startMinute >= other.endMinute
|
|
38
|
-
? inst.startMinute - other.endMinute
|
|
39
|
-
: other.startMinute >= inst.endMinute
|
|
40
|
-
? other.startMinute - inst.endMinute
|
|
41
|
-
: 0; // overlapping: no-overlap owns that, rest sees zero gap
|
|
42
|
-
if (gap < minRestMinutes)
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
29
|
+
// Person timeline, not the per-contract assignment set: rest aggregates
|
|
30
|
+
// on the person (C-585/19), and history is what makes the rule correct
|
|
31
|
+
// at the period boundary. Overlaps read as a zero gap, which breaches
|
|
32
|
+
// here just as it did under the old pairwise arithmetic.
|
|
33
|
+
const gap = (0, support_1.timelineFor)(state, pair.employeeId).minGapAround((0, support_1.rangeOf)(inst), (0, support_1.entryIdOf)(pair));
|
|
34
|
+
return gap < minRestMinutes;
|
|
46
35
|
};
|
|
47
36
|
return {
|
|
48
37
|
id: 'min-rest',
|
|
@@ -148,8 +148,24 @@ function worstNightCount(state, timeline, quota, span, around) {
|
|
|
148
148
|
const threshold = clock.toPeriodMinutes(clock.dateAt(day), quota.endingAfter, 'nightWork.volumeQuotas.endingAfter');
|
|
149
149
|
return entry.end > threshold;
|
|
150
150
|
};
|
|
151
|
+
// Candidate window starts anchored on qualifying-entry boundaries, never a
|
|
152
|
+
// day grid (a grid silently misses straddling breaches — see CLAUDE.md).
|
|
153
|
+
// The count is piecewise constant in the window start: it drops when the
|
|
154
|
+
// left edge passes an entry's end (start = e.end) and gains when the right
|
|
155
|
+
// edge passes an entry's start (start = e.start - span + 1, integer
|
|
156
|
+
// minutes), so those are the only starts that need probing.
|
|
157
|
+
const bounds = { start: around.start - span, end: around.end };
|
|
158
|
+
const starts = new Set([bounds.start, bounds.end]);
|
|
159
|
+
for (const entry of timeline.entriesIn({ start: bounds.start, end: bounds.end + span })) {
|
|
160
|
+
if (!qualifies(entry))
|
|
161
|
+
continue;
|
|
162
|
+
for (const s of [entry.end, entry.start - span + 1]) {
|
|
163
|
+
if (s >= bounds.start && s <= bounds.end)
|
|
164
|
+
starts.add(s);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
151
167
|
let worst = 0;
|
|
152
|
-
for (
|
|
168
|
+
for (const start of starts) {
|
|
153
169
|
const count = timeline.countIn({ start, end: start + span }, qualifies);
|
|
154
170
|
if (count > worst)
|
|
155
171
|
worst = count;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* No-overlap —
|
|
2
|
+
* No-overlap — a person's assignments must never overlap in time, including
|
|
3
3
|
* across midnight for overnight shifts. Hard by default.
|
|
4
|
+
*
|
|
5
|
+
* Judged on the person timeline, not the employee record (CJEU C-585/19): two
|
|
6
|
+
* contracts sharing a `personId` must not put the person in two places at
|
|
7
|
+
* once, and a rostered shift must not overlap a history entry either.
|
|
4
8
|
*/
|
|
5
9
|
import type { SchedulingConstraint } from '../types';
|
|
6
10
|
export declare function noOverlap(): SchedulingConstraint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-overlap.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/no-overlap.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"no-overlap.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/no-overlap.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGrD,wBAAgB,SAAS,IAAI,oBAAoB,CAmBhD"}
|
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* No-overlap —
|
|
3
|
+
* No-overlap — a person's assignments must never overlap in time, including
|
|
4
4
|
* across midnight for overnight shifts. Hard by default.
|
|
5
|
+
*
|
|
6
|
+
* Judged on the person timeline, not the employee record (CJEU C-585/19): two
|
|
7
|
+
* contracts sharing a `personId` must not put the person in two places at
|
|
8
|
+
* once, and a rostered shift must not overlap a history entry either.
|
|
5
9
|
*/
|
|
6
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
11
|
exports.noOverlap = void 0;
|
|
8
|
-
const
|
|
12
|
+
const support_1 = require("./support");
|
|
9
13
|
function noOverlap() {
|
|
10
14
|
return {
|
|
11
15
|
id: 'no-overlap',
|
|
12
16
|
hardness: 'hard',
|
|
13
17
|
delta(state, pair) {
|
|
14
|
-
const inst =
|
|
18
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
15
19
|
if (!inst)
|
|
16
20
|
return 0;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (const otherId of assigned) {
|
|
21
|
-
if (otherId === pair.shiftInstanceId)
|
|
22
|
-
continue;
|
|
23
|
-
const other = state.ctx.instanceById.get(otherId);
|
|
24
|
-
if (other && (0, intervals_1.overlaps)(inst.startMinute, inst.endMinute, other.startMinute, other.endMinute))
|
|
21
|
+
const own = (0, support_1.entryIdOf)(pair);
|
|
22
|
+
for (const entry of (0, support_1.timelineFor)(state, pair.employeeId).entriesIn((0, support_1.rangeOf)(inst))) {
|
|
23
|
+
if (entry.id !== own)
|
|
25
24
|
return 1;
|
|
26
25
|
}
|
|
27
26
|
return 0;
|
|
28
27
|
},
|
|
29
28
|
explain(state, pair) {
|
|
30
29
|
return this.delta(state, pair) > 0
|
|
31
|
-
? `shift "${pair.shiftInstanceId}" overlaps
|
|
30
|
+
? `shift "${pair.shiftInstanceId}" overlaps other work of employee "${pair.employeeId}"'s person`
|
|
32
31
|
: null;
|
|
33
32
|
},
|
|
34
33
|
};
|
|
@@ -77,8 +77,19 @@ exports.weeklyRest = weeklyRest;
|
|
|
77
77
|
* and each contributes at most one qualifying period's worth.
|
|
78
78
|
*/
|
|
79
79
|
function totalQualifyingRest(timeline, averagingMinutes, bounds, minPer) {
|
|
80
|
+
// Window starts anchored on entry boundaries, never a day grid (a grid
|
|
81
|
+
// silently misses straddling windows — see CLAUDE.md). The worst (least
|
|
82
|
+
// rest) windows are the ones aligning their edges with work, so probe
|
|
83
|
+
// every start where a window edge touches an entry boundary.
|
|
84
|
+
const starts = new Set([bounds.start, bounds.end]);
|
|
85
|
+
for (const entry of timeline.entriesIn({ start: bounds.start, end: bounds.end + averagingMinutes })) {
|
|
86
|
+
for (const s of [entry.start, entry.end, entry.start - averagingMinutes + 1, entry.end - averagingMinutes]) {
|
|
87
|
+
if (s >= bounds.start && s <= bounds.end)
|
|
88
|
+
starts.add(s);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
80
91
|
let worst = Infinity;
|
|
81
|
-
for (
|
|
92
|
+
for (const start of starts) {
|
|
82
93
|
const window = { start, end: start + averagingMinutes };
|
|
83
94
|
let total = 0;
|
|
84
95
|
for (const gap of timeline.restGapsIn(window)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAErD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAKtH;AA8CD,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAS7F;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACtB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,IAAI,EAAE,MAAM,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,IAAI,
|
|
1
|
+
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAErD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAKtH;AA8CD,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAS7F;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACtB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,IAAI,EAAE,MAAM,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,IAAI,CA4BN"}
|
|
@@ -89,6 +89,13 @@ function greedyFill(ctx, state, propagation, objective, rand, instanceIds) {
|
|
|
89
89
|
for (const c of candidates) {
|
|
90
90
|
if (need <= 0)
|
|
91
91
|
break;
|
|
92
|
+
// Re-vet against the state as this slot fills: the vet above ran
|
|
93
|
+
// before any of this batch was assigned, so a constraint that
|
|
94
|
+
// depends on the instance's other assignees (tagMaximums, a
|
|
95
|
+
// night-worker cap) could be satisfied for each candidate alone
|
|
96
|
+
// yet breached by the pair of them.
|
|
97
|
+
if (!hardCompliant(ctx, state, c.employeeId, instanceId))
|
|
98
|
+
continue;
|
|
92
99
|
(0, state_1.assign)(state, c.employeeId, instanceId, c.reasons);
|
|
93
100
|
need--;
|
|
94
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACR,gBAAgB,EAChB,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAmE,MAAM,QAAQ,CAAC;AAEvH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,sEAAsE;AACtE,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,SAAS,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAAC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,GACpF,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACR,gBAAgB,EAChB,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAmE,MAAM,QAAQ,CAAC;AAEvH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,sEAAsE;AACtE,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,SAAS,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAAC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,GACpF,aAAa,EAAE,CAyFjB;AA4FD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAAE,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,gBAAgB,CAIvH;AAED,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,KAAK,CAAC,EAAE,gBAAgB,EACxB,UAAU,CAAC,EAAE,gBAAgB,GAC9B,oBAAoB,EAAE,CAexB;AAgCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAiG7D;AAED,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAKxF;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|