@jsb188/schedule 1.1.11 → 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 +34 -14
- package/src/constants/schedule.ts +710 -306
- package/src/modules/Gantt.helpers.ts +11 -30
- package/src/modules/Gantt.tsx +46 -181
- package/src/types/schedule.d.ts +1827 -456
- package/src/ui/ProjectFormUI.tsx +8 -31
- 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
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CoverageViolationDiff,
|
|
3
|
+
CoverageViolationIdentityInput,
|
|
4
|
+
CoverageViolationObj,
|
|
5
|
+
} from '../types/schedule.d.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The one format for violation identities and keys (IMPLEMENTATION
|
|
9
|
+
* §1.5), shared by every engine module and the server:
|
|
10
|
+
*
|
|
11
|
+
* identity = kind|ruleId|resourceId|shiftId|code (absent parts are '')
|
|
12
|
+
* key = identity|<ISO startAt>
|
|
13
|
+
*
|
|
14
|
+
* The identity has no window position, so an acknowledgement attached to it
|
|
15
|
+
* survives re-evaluation; it keeps `code` because ELIGIBILITY emits several
|
|
16
|
+
* codes for one person x seat. The key is unique within one evaluation. A
|
|
17
|
+
* coverage identity (shiftId null) names every stretch of one rule in the
|
|
18
|
+
* window, so diffCoverageViolations compares those stretches per instant.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Build a violation's window-independent identity.
|
|
23
|
+
*/
|
|
24
|
+
export function getCoverageViolationIdentity(
|
|
25
|
+
violation: CoverageViolationIdentityInput,
|
|
26
|
+
): string {
|
|
27
|
+
return [
|
|
28
|
+
violation.kind,
|
|
29
|
+
violation.ruleId ?? '',
|
|
30
|
+
violation.resourceId ?? '',
|
|
31
|
+
violation.shiftId ?? '',
|
|
32
|
+
violation.code ?? '',
|
|
33
|
+
].join('|');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* Build the persisted natural key from an identity and a stretch start.
|
|
38
|
+
*/
|
|
39
|
+
export function getCoverageViolationKey(
|
|
40
|
+
violation: Pick<CoverageViolationObj, 'identity' | 'startAt'>,
|
|
41
|
+
): string {
|
|
42
|
+
return `${violation.identity}|${violation.startAt.toISOString()}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Serialize a value with object keys sorted, so equal details compare equal
|
|
47
|
+
* whatever their insertion order (merge keys, dedupe, detail JSON).
|
|
48
|
+
*/
|
|
49
|
+
export function stableStringify(value: unknown): string {
|
|
50
|
+
if (value === null || typeof value !== 'object')
|
|
51
|
+
return JSON.stringify(value) ?? 'null';
|
|
52
|
+
if (value instanceof Date) return JSON.stringify(value.toISOString());
|
|
53
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(',')}]`;
|
|
54
|
+
return `{${Object.entries(value)
|
|
55
|
+
.filter(([, item]) => item !== undefined)
|
|
56
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
57
|
+
.map(([key, item]) => `${JSON.stringify(key)}:${stableStringify(item)}`)
|
|
58
|
+
.join(',')}}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* Return the highest degree per identity.
|
|
63
|
+
*/
|
|
64
|
+
function getMaxDegreeByIdentity(
|
|
65
|
+
violations: CoverageViolationObj[],
|
|
66
|
+
): Map<string, number> {
|
|
67
|
+
const degrees = new Map<string, number>();
|
|
68
|
+
for (const violation of violations)
|
|
69
|
+
degrees.set(
|
|
70
|
+
violation.identity,
|
|
71
|
+
Math.max(
|
|
72
|
+
degrees.get(violation.identity) ?? Number.NEGATIVE_INFINITY,
|
|
73
|
+
violation.degree,
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
return degrees;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* Group violations by identity, each group sorted by start.
|
|
81
|
+
*/
|
|
82
|
+
function groupStretchesByIdentity(
|
|
83
|
+
violations: CoverageViolationObj[],
|
|
84
|
+
): Map<string, CoverageViolationObj[]> {
|
|
85
|
+
const groups = new Map<string, CoverageViolationObj[]>();
|
|
86
|
+
for (const violation of violations) {
|
|
87
|
+
const group = groups.get(violation.identity);
|
|
88
|
+
if (group) group.push(violation);
|
|
89
|
+
else groups.set(violation.identity, [violation]);
|
|
90
|
+
}
|
|
91
|
+
for (const group of groups.values())
|
|
92
|
+
group.sort((a, b) => a.startAt.getTime() - b.startAt.getTime());
|
|
93
|
+
return groups;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* Check whether stretches (sorted by start) cover every instant of a
|
|
98
|
+
* violation's interval.
|
|
99
|
+
*/
|
|
100
|
+
function isStretchCovered(
|
|
101
|
+
violation: CoverageViolationObj,
|
|
102
|
+
stretches: CoverageViolationObj[],
|
|
103
|
+
): boolean {
|
|
104
|
+
const endMs = violation.endAt.getTime();
|
|
105
|
+
let reached = violation.startAt.getTime();
|
|
106
|
+
for (const stretch of stretches) {
|
|
107
|
+
if (reached >= endMs || stretch.startAt.getTime() > reached) break;
|
|
108
|
+
reached = Math.max(reached, stretch.endAt.getTime());
|
|
109
|
+
}
|
|
110
|
+
return reached >= endMs;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
* Classify one violation of the later evaluation against the earlier one:
|
|
115
|
+
* INTRODUCED, WORSENED or null (unchanged or better). A seat-bound finding
|
|
116
|
+
* (shiftId set) is compared by identity: new, or a higher maximum degree. A
|
|
117
|
+
* coverage stretch (shiftId null, whose identity spans the whole window) is
|
|
118
|
+
* compared per instant: introduced when some instant of it had no violation
|
|
119
|
+
* of that identity before, worsened when some instant had a lower degree.
|
|
120
|
+
*/
|
|
121
|
+
function getViolationChange(
|
|
122
|
+
violation: CoverageViolationObj,
|
|
123
|
+
prior: {
|
|
124
|
+
maxDegrees: Map<string, number>;
|
|
125
|
+
stretches: Map<string, CoverageViolationObj[]>;
|
|
126
|
+
},
|
|
127
|
+
nextMaxDegrees: Map<string, number>,
|
|
128
|
+
): 'INTRODUCED' | 'WORSENED' | null {
|
|
129
|
+
const { identity } = violation;
|
|
130
|
+
if (violation.shiftId !== null) {
|
|
131
|
+
if (!prior.maxDegrees.has(identity)) return 'INTRODUCED';
|
|
132
|
+
return nextMaxDegrees.get(identity)! > prior.maxDegrees.get(identity)!
|
|
133
|
+
? 'WORSENED'
|
|
134
|
+
: null;
|
|
135
|
+
}
|
|
136
|
+
const before = prior.stretches.get(identity) ?? [];
|
|
137
|
+
if (!isStretchCovered(violation, before)) return 'INTRODUCED';
|
|
138
|
+
return before.some(
|
|
139
|
+
(stretch) =>
|
|
140
|
+
stretch.startAt.getTime() < violation.endAt.getTime() &&
|
|
141
|
+
stretch.endAt.getTime() > violation.startAt.getTime() &&
|
|
142
|
+
stretch.degree < violation.degree,
|
|
143
|
+
)
|
|
144
|
+
? 'WORSENED'
|
|
145
|
+
: null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* Compare two evaluations (a request's or a write's impact). Seat-bound
|
|
150
|
+
* findings are compared by identity: introduced = only after, worsened = a
|
|
151
|
+
* higher maximum degree (every stretch of it is returned), resolved = only
|
|
152
|
+
* before. Coverage stretches (shiftId null) are compared per instant, so a
|
|
153
|
+
* new gap at another time of an already-short rule still counts:
|
|
154
|
+
* introduced = some instant newly in violation, worsened = some instant at a
|
|
155
|
+
* higher degree, resolved = a before-stretch with some instant no longer in
|
|
156
|
+
* violation. Acknowledgements are not judged here: they attach to the
|
|
157
|
+
* identity (identityKey) and survive stretches moving.
|
|
158
|
+
*/
|
|
159
|
+
export function diffCoverageViolations(
|
|
160
|
+
before: CoverageViolationObj[],
|
|
161
|
+
after: CoverageViolationObj[],
|
|
162
|
+
): CoverageViolationDiff {
|
|
163
|
+
const prior = {
|
|
164
|
+
maxDegrees: getMaxDegreeByIdentity(before),
|
|
165
|
+
stretches: groupStretchesByIdentity(before),
|
|
166
|
+
};
|
|
167
|
+
const nextMaxDegrees = getMaxDegreeByIdentity(after);
|
|
168
|
+
const nextStretches = groupStretchesByIdentity(after);
|
|
169
|
+
const changes = after.map((violation) =>
|
|
170
|
+
getViolationChange(violation, prior, nextMaxDegrees),
|
|
171
|
+
);
|
|
172
|
+
return {
|
|
173
|
+
introduced: after.filter((_, index) => changes[index] === 'INTRODUCED'),
|
|
174
|
+
worsened: after.filter((_, index) => changes[index] === 'WORSENED'),
|
|
175
|
+
resolved: before.filter((violation) =>
|
|
176
|
+
violation.shiftId !== null
|
|
177
|
+
? !nextMaxDegrees.has(violation.identity)
|
|
178
|
+
: !isStretchCovered(
|
|
179
|
+
violation,
|
|
180
|
+
nextStretches.get(violation.identity) ?? [],
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
};
|
|
184
|
+
}
|