@jsb188/schedule 1.1.12 → 1.1.13
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/LICENSE +21 -0
- package/package.json +33 -14
- package/src/constants/schedule.ts +710 -306
- package/src/types/schedule.d.ts +1827 -456
- package/src/ui/ScheduleSettingsUI.tsx +21 -23
- package/src/utils/autofill.ts +469 -0
- package/src/utils/availability.ts +167 -0
- package/src/utils/candidates.ts +447 -0
- package/src/utils/coverage.helpers.ts +509 -554
- package/src/utils/coverage.ts +1121 -526
- package/src/utils/cpm.helpers.ts +27 -29
- package/src/utils/cpm.ts +53 -41
- package/src/utils/cpmLeveling.helpers.ts +89 -16
- package/src/utils/cpmLeveling.ts +28 -26
- package/src/utils/cycle.ts +325 -0
- package/src/utils/demand.ts +239 -0
- package/src/utils/eligibility.ts +553 -400
- package/src/utils/ids.ts +47 -0
- package/src/utils/laborRules.ts +740 -0
- package/src/utils/localTime.ts +312 -0
- package/src/utils/offer.ts +300 -0
- package/src/utils/planCsv.ts +73 -19
- package/src/utils/predicate.ts +111 -0
- package/src/utils/request.ts +212 -114
- package/src/utils/resource.ts +412 -112
- package/src/utils/rule.ts +697 -163
- package/src/utils/rulePresets.ts +116 -0
- package/src/utils/run.ts +0 -8
- package/src/utils/scheduleText.ts +4074 -0
- package/src/utils/shiftChange.ts +279 -0
- package/src/utils/standing.ts +730 -0
- package/src/utils/template.ts +619 -0
- package/src/utils/violation.ts +184 -0
- package/src/utils/workTime.ts +341 -120
- package/src/utils/defaults.ts +0 -8
- package/src/utils/recurrence.ts +0 -616
- package/src/utils/series.ts +0 -161
- package/src/utils/slot.ts +0 -208
- package/tests/coverage.fixtures.ts +0 -111
- package/tests/coverage.test.ts +0 -503
- package/tests/cpm.bench.test.ts +0 -154
- package/tests/cpm.test.ts +0 -354
- package/tests/cpmCorrectness.test.ts +0 -327
- package/tests/cpmLeveling.test.ts +0 -471
- package/tests/eligibility.test.ts +0 -320
- package/tests/gantt-geometry.test.ts +0 -367
- package/tests/gantt-histogram.test.ts +0 -78
- package/tests/gantt-keyboard.test.ts +0 -69
- package/tests/helpers/cpmFixtures.ts +0 -101
- package/tests/projectInputs.test.ts +0 -165
- package/tests/recurrence.test.ts +0 -68
- package/tests/request.test.ts +0 -99
- package/tests/resource.test.ts +0 -95
- package/tests/rule.test.ts +0 -98
- package/tests/series.test.ts +0 -120
- package/tests/workTime.test.ts +0 -1007
- package/tests/workTimeContracts.test.ts +0 -111
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -8
package/src/utils/series.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
2
|
-
import type {
|
|
3
|
-
ScheduleExpandedInstance,
|
|
4
|
-
ScheduleSlotTemplateObj,
|
|
5
|
-
} from '../types/schedule.d.ts';
|
|
6
|
-
import {
|
|
7
|
-
expandScheduleSeriesInstances,
|
|
8
|
-
type ScheduleExpandableSeries,
|
|
9
|
-
} from './recurrence.ts';
|
|
10
|
-
|
|
11
|
-
export interface SeriesExistingInstance {
|
|
12
|
-
id: string;
|
|
13
|
-
recurrenceDate: string;
|
|
14
|
-
startAt: Date;
|
|
15
|
-
endAt: Date;
|
|
16
|
-
detached: boolean;
|
|
17
|
-
hasLiveAssignments: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface SeriesRegenerationPlan {
|
|
20
|
-
create: Array<
|
|
21
|
-
ScheduleExpandedInstance & { slotTemplate: ScheduleSlotTemplateObj[] }
|
|
22
|
-
>;
|
|
23
|
-
update: Array<{
|
|
24
|
-
id: string;
|
|
25
|
-
startAt?: Date;
|
|
26
|
-
endAt?: Date;
|
|
27
|
-
slotTemplate?: ScheduleSlotTemplateObj[];
|
|
28
|
-
}>;
|
|
29
|
-
labels: {
|
|
30
|
-
title: string;
|
|
31
|
-
note: string | null;
|
|
32
|
-
location: string | null;
|
|
33
|
-
resourceId: string | null;
|
|
34
|
-
} | null;
|
|
35
|
-
detach: Array<{ id: string; reason: 'DATE_REMOVED' | 'SERIES_DELETED' }>;
|
|
36
|
-
delete: string[];
|
|
37
|
-
skipped: Array<{
|
|
38
|
-
recurrenceDate: string;
|
|
39
|
-
reason: 'DETACHED_EXISTS' | 'ALREADY_STARTED';
|
|
40
|
-
}>;
|
|
41
|
-
materializedThrough: Date;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/* Return an instant's calendar date in the explicit series timezone. */
|
|
45
|
-
export function getLocalDateKey(at: Date, timeZone: string): string {
|
|
46
|
-
const local = DateTime.fromJSDate(at, { zone: timeZone });
|
|
47
|
-
if (!local.isValid) throw new Error('SCHEDULE_SERIES_TIME_ZONE_INVALID');
|
|
48
|
-
return local.toFormat('yyyy-LL-dd');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/* Preserve staffed and detached instances while planning future series edits by local date. */
|
|
52
|
-
export function planScheduleSeriesRegeneration(args: {
|
|
53
|
-
series: ScheduleExpandableSeries & {
|
|
54
|
-
active: boolean;
|
|
55
|
-
slotTemplate: ScheduleSlotTemplateObj[];
|
|
56
|
-
title: string;
|
|
57
|
-
note?: string | null;
|
|
58
|
-
location?: string | null;
|
|
59
|
-
resourceId?: string | null;
|
|
60
|
-
};
|
|
61
|
-
existing: SeriesExistingInstance[];
|
|
62
|
-
fromDate: string;
|
|
63
|
-
now: Date;
|
|
64
|
-
horizon: Date;
|
|
65
|
-
slotTemplateChanged: boolean;
|
|
66
|
-
labelsChanged: boolean;
|
|
67
|
-
}): SeriesRegenerationPlan {
|
|
68
|
-
const { series, existing, now, horizon, slotTemplateChanged, labelsChanged } =
|
|
69
|
-
args;
|
|
70
|
-
const fromDate =
|
|
71
|
-
args.fromDate < getLocalDateKey(now, series.timeZone)
|
|
72
|
-
? getLocalDateKey(now, series.timeZone)
|
|
73
|
-
: args.fromDate;
|
|
74
|
-
const localFrom = DateTime.fromISO(fromDate, {
|
|
75
|
-
zone: series.timeZone,
|
|
76
|
-
}).startOf('day');
|
|
77
|
-
if (
|
|
78
|
-
!/^\d{4}-\d{2}-\d{2}$/.test(fromDate) ||
|
|
79
|
-
!localFrom.isValid ||
|
|
80
|
-
localFrom.toISODate() !== fromDate
|
|
81
|
-
)
|
|
82
|
-
throw new Error('SCHEDULE_SERIES_FROM_DATE_INVALID');
|
|
83
|
-
const from = new Date(
|
|
84
|
-
Math.max(localFrom.toMillis(), new Date(series.startsAt).getTime()),
|
|
85
|
-
);
|
|
86
|
-
const next = new Map(
|
|
87
|
-
(series.active
|
|
88
|
-
? expandScheduleSeriesInstances(series, { from, to: horizon })
|
|
89
|
-
: []
|
|
90
|
-
).map((instance) => [instance.recurrenceDate, instance]),
|
|
91
|
-
);
|
|
92
|
-
const plan: SeriesRegenerationPlan = {
|
|
93
|
-
create: [],
|
|
94
|
-
update: [],
|
|
95
|
-
labels: labelsChanged
|
|
96
|
-
? {
|
|
97
|
-
title: series.title,
|
|
98
|
-
note: series.note ?? null,
|
|
99
|
-
location: series.location ?? null,
|
|
100
|
-
resourceId: series.resourceId ?? null,
|
|
101
|
-
}
|
|
102
|
-
: null,
|
|
103
|
-
detach: [],
|
|
104
|
-
delete: [],
|
|
105
|
-
skipped: [],
|
|
106
|
-
materializedThrough: horizon,
|
|
107
|
-
};
|
|
108
|
-
const frozen = new Set<string>();
|
|
109
|
-
for (const instance of next.values()) {
|
|
110
|
-
if (instance.startAt < now) {
|
|
111
|
-
frozen.add(instance.recurrenceDate);
|
|
112
|
-
next.delete(instance.recurrenceDate);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
for (const row of [...existing].sort(
|
|
116
|
-
(a, b) =>
|
|
117
|
-
a.recurrenceDate.localeCompare(b.recurrenceDate) ||
|
|
118
|
-
a.id.localeCompare(b.id),
|
|
119
|
-
)) {
|
|
120
|
-
if (row.recurrenceDate < fromDate) continue;
|
|
121
|
-
if (row.startAt < now || frozen.has(row.recurrenceDate)) {
|
|
122
|
-
frozen.add(row.recurrenceDate);
|
|
123
|
-
next.delete(row.recurrenceDate);
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (row.detached) {
|
|
127
|
-
if (next.has(row.recurrenceDate))
|
|
128
|
-
plan.skipped.push({
|
|
129
|
-
recurrenceDate: row.recurrenceDate,
|
|
130
|
-
reason: 'DETACHED_EXISTS',
|
|
131
|
-
});
|
|
132
|
-
next.delete(row.recurrenceDate);
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const instance = next.get(row.recurrenceDate);
|
|
136
|
-
if (instance) {
|
|
137
|
-
next.delete(row.recurrenceDate);
|
|
138
|
-
plan.update.push({
|
|
139
|
-
id: row.id,
|
|
140
|
-
...(instance.startAt.getTime() !== row.startAt.getTime() ||
|
|
141
|
-
instance.endAt.getTime() !== row.endAt.getTime()
|
|
142
|
-
? { startAt: instance.startAt, endAt: instance.endAt }
|
|
143
|
-
: {}),
|
|
144
|
-
...(slotTemplateChanged ? { slotTemplate: series.slotTemplate } : {}),
|
|
145
|
-
});
|
|
146
|
-
} else if (row.hasLiveAssignments)
|
|
147
|
-
plan.detach.push({
|
|
148
|
-
id: row.id,
|
|
149
|
-
reason: series.active ? 'DATE_REMOVED' : 'SERIES_DELETED',
|
|
150
|
-
});
|
|
151
|
-
else plan.delete.push(row.id);
|
|
152
|
-
}
|
|
153
|
-
for (const recurrenceDate of frozen)
|
|
154
|
-
plan.skipped.push({ recurrenceDate, reason: 'ALREADY_STARTED' });
|
|
155
|
-
plan.skipped.sort((a, b) => a.recurrenceDate.localeCompare(b.recurrenceDate));
|
|
156
|
-
plan.create = [...next.values()].map((instance) => ({
|
|
157
|
-
...instance,
|
|
158
|
-
slotTemplate: series.slotTemplate,
|
|
159
|
-
}));
|
|
160
|
-
return plan;
|
|
161
|
-
}
|
package/src/utils/slot.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SCHEDULE_KEY_MAX_LENGTH,
|
|
3
|
-
SCHEDULE_SLOT_LABEL_MAX_LENGTH,
|
|
4
|
-
} from '../constants/schedule.ts';
|
|
5
|
-
import { validateScheduleKeyList } from './resource.ts';
|
|
6
|
-
import type {
|
|
7
|
-
ScheduleResourceConfigObj,
|
|
8
|
-
ScheduleSlotPredicateObj,
|
|
9
|
-
ScheduleSlotTemplateObj,
|
|
10
|
-
} from '../types/schedule.d.ts';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Slot requirements: what a shift needs ("2 infant-qualified teachers") and
|
|
14
|
-
* whether a given resource satisfies it.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Validate one slot predicate object. Unknown keys are rejected; an empty
|
|
19
|
-
* predicate is returned as null (anyone may fill the slot).
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export function validateScheduleSlotPredicate(input: unknown): {
|
|
23
|
-
predicate?: ScheduleSlotPredicateObj | null;
|
|
24
|
-
error?: string;
|
|
25
|
-
} {
|
|
26
|
-
if (input === undefined || input === null) {
|
|
27
|
-
return { predicate: null };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof input !== 'object' || Array.isArray(input)) {
|
|
31
|
-
return { error: 'A slot predicate must be an object.' };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const raw = input as Record<string, unknown>;
|
|
35
|
-
const unknown = Object.keys(raw).find(
|
|
36
|
-
(key) => !['roles', 'qualifications', 'tags'].includes(key),
|
|
37
|
-
);
|
|
38
|
-
if (unknown) return { error: `Unknown slot predicate key: ${unknown}.` };
|
|
39
|
-
const predicate: ScheduleSlotPredicateObj = {};
|
|
40
|
-
|
|
41
|
-
for (const key of ['roles', 'qualifications', 'tags'] as const) {
|
|
42
|
-
if (raw[key] === undefined || raw[key] === null) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const list = validateScheduleKeyList(raw[key], 50);
|
|
47
|
-
if (
|
|
48
|
-
list === null &&
|
|
49
|
-
Array.isArray(raw[key]) &&
|
|
50
|
-
(raw[key] as unknown[]).length === 0
|
|
51
|
-
) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (list === null) {
|
|
56
|
-
return { error: `Slot predicate "${key}" must be a list of names.` };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
predicate[key] = list;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return { predicate: Object.keys(predicate).length ? predicate : null };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Validate one slot template list (schedule_series."slotTemplate", and the
|
|
67
|
-
* slot rows stamped onto each generated occurrence).
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
export function validateScheduleSlotTemplate(input: unknown): {
|
|
71
|
-
slotTemplate?: ScheduleSlotTemplateObj[];
|
|
72
|
-
error?: string;
|
|
73
|
-
} {
|
|
74
|
-
if (input === undefined || input === null) {
|
|
75
|
-
return { slotTemplate: [] };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!Array.isArray(input)) {
|
|
79
|
-
return { error: 'Slot requirements must be a list.' };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const slotTemplate: ScheduleSlotTemplateObj[] = [];
|
|
83
|
-
const usedKeys = new Set<string>();
|
|
84
|
-
|
|
85
|
-
for (let i = 0; i < input.length; i++) {
|
|
86
|
-
const raw = input[i];
|
|
87
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
88
|
-
return { error: 'Each slot requirement must be an object.' };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const unknown = Object.keys(raw).find(
|
|
92
|
-
(key) =>
|
|
93
|
-
!['key', 'label', 'requiredCount', 'predicate', 'ordinal'].includes(
|
|
94
|
-
key,
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
if (unknown) return { error: `Unknown slot requirement key: ${unknown}.` };
|
|
98
|
-
const key = typeof raw.key === 'string' ? raw.key.trim() : '';
|
|
99
|
-
if (!key) {
|
|
100
|
-
return { error: 'Each slot requirement needs a key.' };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Rejected rather than truncated: two long keys sharing a prefix would
|
|
104
|
-
// silently collapse into one
|
|
105
|
-
if (key.length > SCHEDULE_KEY_MAX_LENGTH) {
|
|
106
|
-
return {
|
|
107
|
-
error: `Slot requirement key is too long (max ${SCHEDULE_KEY_MAX_LENGTH} characters): "${key}".`,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
raw.label &&
|
|
113
|
-
String(raw.label).length > SCHEDULE_SLOT_LABEL_MAX_LENGTH
|
|
114
|
-
) {
|
|
115
|
-
return {
|
|
116
|
-
error: `Slot requirement label is too long (max ${SCHEDULE_SLOT_LABEL_MAX_LENGTH} characters).`,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (usedKeys.has(key)) {
|
|
121
|
-
return {
|
|
122
|
-
error: `Slot requirement keys must be unique; "${key}" is repeated.`,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const requiredCount =
|
|
127
|
-
raw.requiredCount === undefined || raw.requiredCount === null
|
|
128
|
-
? 1
|
|
129
|
-
: raw.requiredCount;
|
|
130
|
-
if (!Number.isInteger(requiredCount) || requiredCount < 0) {
|
|
131
|
-
return {
|
|
132
|
-
error: `Slot requirement "${key}" needs a whole required count of 0 or more.`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const predicateResult = validateScheduleSlotPredicate(raw.predicate);
|
|
137
|
-
if (predicateResult.error) {
|
|
138
|
-
return { error: predicateResult.error };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
usedKeys.add(key);
|
|
142
|
-
|
|
143
|
-
slotTemplate.push({
|
|
144
|
-
key,
|
|
145
|
-
label: raw.label ? String(raw.label) : null,
|
|
146
|
-
requiredCount,
|
|
147
|
-
predicate: predicateResult.predicate || null,
|
|
148
|
-
ordinal: i,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return { slotTemplate };
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Check whether a resource's configuration satisfies a slot predicate: every
|
|
157
|
-
* listed role, tag and qualification key must be present. Qualification
|
|
158
|
-
* EXPIRY is judged separately by the ELIGIBILITY rule, because a
|
|
159
|
-
* lapsed certificate is a different message from a missing one.
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
export function doesResourceMatchSlotPredicate(
|
|
163
|
-
config: ScheduleResourceConfigObj | null | undefined,
|
|
164
|
-
predicate: ScheduleSlotPredicateObj | null | undefined,
|
|
165
|
-
): boolean {
|
|
166
|
-
if (!predicate) {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const roles = new Set(config?.roles || []);
|
|
171
|
-
const tags = new Set(config?.tags || []);
|
|
172
|
-
const qualifications = new Set(
|
|
173
|
-
(config?.qualifications || []).map((qualification) => qualification.key),
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
return (
|
|
177
|
-
(predicate.roles || []).every((role) => roles.has(role)) &&
|
|
178
|
-
(predicate.tags || []).every((tag) => tags.has(tag)) &&
|
|
179
|
-
(predicate.qualifications || []).every((qualification) =>
|
|
180
|
-
qualifications.has(qualification),
|
|
181
|
-
)
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/* Return the distinct predicate keys missing from a resource, independently of expiry. */
|
|
186
|
-
export function getSlotPredicateMissing(
|
|
187
|
-
config: ScheduleResourceConfigObj | null | undefined,
|
|
188
|
-
predicate: ScheduleSlotPredicateObj | null | undefined,
|
|
189
|
-
): { roles: string[]; tags: string[]; qualifications: string[] } {
|
|
190
|
-
const held = {
|
|
191
|
-
roles: new Set(config?.roles ?? []),
|
|
192
|
-
tags: new Set(config?.tags ?? []),
|
|
193
|
-
qualifications: new Set(
|
|
194
|
-
(config?.qualifications ?? []).map((item) => item.key),
|
|
195
|
-
),
|
|
196
|
-
};
|
|
197
|
-
return {
|
|
198
|
-
roles: [...new Set(predicate?.roles ?? [])]
|
|
199
|
-
.filter((key) => !held.roles.has(key))
|
|
200
|
-
.sort(),
|
|
201
|
-
tags: [...new Set(predicate?.tags ?? [])]
|
|
202
|
-
.filter((key) => !held.tags.has(key))
|
|
203
|
-
.sort(),
|
|
204
|
-
qualifications: [...new Set(predicate?.qualifications ?? [])]
|
|
205
|
-
.filter((key) => !held.qualifications.has(key))
|
|
206
|
-
.sort(),
|
|
207
|
-
};
|
|
208
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CoverageEvaluationInput,
|
|
3
|
-
CoverageOccurrenceInput,
|
|
4
|
-
CoverageResourceInput,
|
|
5
|
-
CoverageRuleInput,
|
|
6
|
-
CoverageSlotInput,
|
|
7
|
-
} from '../src/types/schedule.d.ts';
|
|
8
|
-
|
|
9
|
-
/* Build a UTC fixture instant on a Monday. */
|
|
10
|
-
export function at(hour: number, day = 7): string {
|
|
11
|
-
return new Date(Date.UTC(2026, 8, day, 0, hour * 60)).toISOString();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/* Build a validated resource with explicit nullability and empty configuration. */
|
|
15
|
-
export function person(
|
|
16
|
-
id: string,
|
|
17
|
-
extra: Partial<CoverageResourceInput> = {},
|
|
18
|
-
): CoverageResourceInput {
|
|
19
|
-
return {
|
|
20
|
-
id,
|
|
21
|
-
kind: 'LABOR',
|
|
22
|
-
capacity: null,
|
|
23
|
-
retiredAt: null,
|
|
24
|
-
config: {
|
|
25
|
-
roles: [],
|
|
26
|
-
tags: [],
|
|
27
|
-
qualifications: [],
|
|
28
|
-
ageGroup: null,
|
|
29
|
-
notify: null,
|
|
30
|
-
},
|
|
31
|
-
...extra,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/* Build a staff slot with no predicate by default. */
|
|
36
|
-
export function slot(
|
|
37
|
-
key = 'teacher',
|
|
38
|
-
extra: Partial<CoverageSlotInput> = {},
|
|
39
|
-
): CoverageSlotInput {
|
|
40
|
-
return {
|
|
41
|
-
key,
|
|
42
|
-
label: null,
|
|
43
|
-
requiredCount: 1,
|
|
44
|
-
predicate: null,
|
|
45
|
-
ordinal: 0,
|
|
46
|
-
...extra,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/* Build one shift with pinned assignments for the given resources. */
|
|
51
|
-
export function shift(
|
|
52
|
-
id = '10',
|
|
53
|
-
people: string[] = [],
|
|
54
|
-
extra: Partial<CoverageOccurrenceInput> = {},
|
|
55
|
-
): CoverageOccurrenceInput {
|
|
56
|
-
return {
|
|
57
|
-
id,
|
|
58
|
-
kind: 'SHIFT',
|
|
59
|
-
resourceId: 'room',
|
|
60
|
-
startAt: at(8),
|
|
61
|
-
endAt: at(12),
|
|
62
|
-
slots: [slot()],
|
|
63
|
-
assignments: people.map((resourceId) => ({
|
|
64
|
-
id: `${id}-${resourceId}`,
|
|
65
|
-
resourceId,
|
|
66
|
-
slotKey: 'teacher',
|
|
67
|
-
})),
|
|
68
|
-
...extra,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/* Build one active rule row at organization scope. */
|
|
73
|
-
export function rule(
|
|
74
|
-
kind: CoverageRuleInput['kind'],
|
|
75
|
-
config: CoverageRuleInput['config'],
|
|
76
|
-
extra: Partial<CoverageRuleInput> = {},
|
|
77
|
-
): CoverageRuleInput {
|
|
78
|
-
return {
|
|
79
|
-
id: `r-${kind}`,
|
|
80
|
-
kind,
|
|
81
|
-
calendarId: null,
|
|
82
|
-
resourceId: null,
|
|
83
|
-
config,
|
|
84
|
-
severity: 'BLOCK',
|
|
85
|
-
...extra,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/* Build a complete coverage snapshot for deterministic regression probes. */
|
|
90
|
-
export function snapshot(
|
|
91
|
-
extra: Partial<CoverageEvaluationInput> = {},
|
|
92
|
-
): CoverageEvaluationInput {
|
|
93
|
-
return {
|
|
94
|
-
calendarId: 'calendar',
|
|
95
|
-
window: { from: at(7), to: at(18) },
|
|
96
|
-
timeZone: 'UTC',
|
|
97
|
-
operatingHours: null,
|
|
98
|
-
occurrences: [],
|
|
99
|
-
external: [],
|
|
100
|
-
resources: [
|
|
101
|
-
person('room', { kind: 'SPACE', capacity: 20 }),
|
|
102
|
-
person('1'),
|
|
103
|
-
person('2'),
|
|
104
|
-
person('3'),
|
|
105
|
-
],
|
|
106
|
-
demand: [],
|
|
107
|
-
timeOff: [],
|
|
108
|
-
rules: [],
|
|
109
|
-
...extra,
|
|
110
|
-
};
|
|
111
|
-
}
|