chuvsu-js 5.4.0 → 5.4.1
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.
|
@@ -2,6 +2,7 @@ import { AcademicPeriod } from "../../common/types.js";
|
|
|
2
2
|
import { getAdjacentSemester, getCurrentPeriod, getMonday, getSemesterStart, getSemesterWeeks, getWeekNumber, formatLocalDate, isHoliday, parseLocalDate, RUSSIAN_HOLIDAYS, } from "../utils/index.js";
|
|
3
3
|
import { occurrenceIdForSeries } from "./ids.js";
|
|
4
4
|
import { entityKey, normalizeScheduleText } from "./normalize.js";
|
|
5
|
+
import { coalesceSubstitutionOccurrences } from "./substitution-occurrences.js";
|
|
5
6
|
function dateAt(date, time) {
|
|
6
7
|
const value = new Date(date);
|
|
7
8
|
value.setHours(time.hours, time.minutes, 0, 0);
|
|
@@ -202,7 +203,10 @@ export class Schedule {
|
|
|
202
203
|
}
|
|
203
204
|
occurrences.push(structuredClone(occurrence));
|
|
204
205
|
}
|
|
205
|
-
|
|
206
|
+
const substitutedSeriesIds = new Set(recurringSeries
|
|
207
|
+
.filter((series) => series.substitutions.some((value) => value.date === localDate))
|
|
208
|
+
.map((series) => series.id));
|
|
209
|
+
return coalesceSubstitutionOccurrences(occurrences, substitutedSeriesIds).sort(sortOccurrences);
|
|
206
210
|
}
|
|
207
211
|
week(week, options) {
|
|
208
212
|
const period = this.period === AcademicPeriod.WinterSession ||
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LessonOccurrence } from "./types.js";
|
|
2
|
+
/** Keep the recurring ID and substitution history when a dated projection repeats it. */
|
|
3
|
+
export declare function coalesceSubstitutionOccurrences(occurrences: LessonOccurrence[], substitutedSeriesIds: ReadonlySet<string>): LessonOccurrence[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { entityKey, mergeGroups, normalizeScheduleText } from "./normalize.js";
|
|
2
|
+
function sameEntity(left, right) {
|
|
3
|
+
return left.id != null && right.id != null
|
|
4
|
+
? entityKey(left) === entityKey(right)
|
|
5
|
+
: normalizeScheduleText(left.name) === normalizeScheduleText(right.name);
|
|
6
|
+
}
|
|
7
|
+
function compatibleSets(left, right, equal) {
|
|
8
|
+
if (!left.length || !right.length)
|
|
9
|
+
return false;
|
|
10
|
+
return (left.every((value) => right.some((other) => equal(value, other))) ||
|
|
11
|
+
right.every((value) => left.some((other) => equal(value, other))));
|
|
12
|
+
}
|
|
13
|
+
function sameEntities(left, right) {
|
|
14
|
+
return (left.length === right.length &&
|
|
15
|
+
left.every((value) => right.some((other) => sameEntity(value, other))));
|
|
16
|
+
}
|
|
17
|
+
function sameAttendance(left, right) {
|
|
18
|
+
return (sameEntity(left.group, right.group) && left.subgroup === right.subgroup);
|
|
19
|
+
}
|
|
20
|
+
function sameSlot(left, right) {
|
|
21
|
+
if (left.slotNumber != null &&
|
|
22
|
+
right.slotNumber != null &&
|
|
23
|
+
left.slotNumber !== right.slotNumber) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (left.time && right.time) {
|
|
27
|
+
return (left.time.start.hours === right.time.start.hours &&
|
|
28
|
+
left.time.start.minutes === right.time.start.minutes &&
|
|
29
|
+
left.time.end.hours === right.time.end.hours &&
|
|
30
|
+
left.time.end.minutes === right.time.end.minutes);
|
|
31
|
+
}
|
|
32
|
+
return left.slotNumber != null && left.slotNumber === right.slotNumber;
|
|
33
|
+
}
|
|
34
|
+
function sameReplacement(left, right) {
|
|
35
|
+
return (left.scheduledDate === right.scheduledDate &&
|
|
36
|
+
left.period === right.period &&
|
|
37
|
+
left.academicYearStartYear === right.academicYearStartYear &&
|
|
38
|
+
normalizeScheduleText(left.subject) ===
|
|
39
|
+
normalizeScheduleText(right.subject) &&
|
|
40
|
+
left.type === right.type &&
|
|
41
|
+
left.retakeAttempt === right.retakeAttempt &&
|
|
42
|
+
left.isDistance === right.isDistance &&
|
|
43
|
+
sameSlot(left, right) &&
|
|
44
|
+
compatibleSets(left.groups.values, right.groups.values, sameAttendance) &&
|
|
45
|
+
left.teachers.values.length > 0 &&
|
|
46
|
+
sameEntities(left.teachers.values, right.teachers.values) &&
|
|
47
|
+
((left.isDistance &&
|
|
48
|
+
!left.rooms.values.length &&
|
|
49
|
+
!right.rooms.values.length) ||
|
|
50
|
+
(left.rooms.values.length > 0 &&
|
|
51
|
+
sameEntities(left.rooms.values, right.rooms.values))));
|
|
52
|
+
}
|
|
53
|
+
/** Keep the recurring ID and substitution history when a dated projection repeats it. */
|
|
54
|
+
export function coalesceSubstitutionOccurrences(occurrences, substitutedSeriesIds) {
|
|
55
|
+
const recurring = occurrences.filter((value) => value.seriesId != null && substitutedSeriesIds.has(value.seriesId));
|
|
56
|
+
return occurrences.filter((value) => {
|
|
57
|
+
if (value.seriesId || value.movedFrom || value.status !== "scheduled")
|
|
58
|
+
return true;
|
|
59
|
+
const matches = recurring.filter((candidate) => sameReplacement(candidate, value));
|
|
60
|
+
// Multiple candidates or incomplete evidence must not hide a real lesson.
|
|
61
|
+
if (matches.length !== 1)
|
|
62
|
+
return true;
|
|
63
|
+
const target = matches[0];
|
|
64
|
+
target.groups.values = mergeGroups([
|
|
65
|
+
...target.groups.values,
|
|
66
|
+
...value.groups.values,
|
|
67
|
+
]);
|
|
68
|
+
for (const source of value.sources) {
|
|
69
|
+
if (!target.sources.some((existing) => existing.sourceKey === source.sourceKey &&
|
|
70
|
+
existing.observationKey === source.observationKey))
|
|
71
|
+
target.sources.push(source);
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
});
|
|
75
|
+
}
|