chuvsu-js 5.4.0 → 5.5.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 +32 -3
- package/dist/common/http.d.ts +3 -1
- package/dist/common/http.js +9 -2
- package/dist/{tt/utils → common}/lesson-type.d.ts +4 -2
- package/dist/{tt/utils → common}/lesson-type.js +17 -2
- package/dist/core.d.ts +13 -5
- package/dist/core.js +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lk/client.d.ts +23 -1
- package/dist/lk/client.js +95 -0
- package/dist/lk/parse/grade-value.d.ts +4 -0
- package/dist/lk/parse/grade-value.js +16 -0
- package/dist/lk/parse/portfolio-content.d.ts +10 -0
- package/dist/lk/parse/portfolio-content.js +116 -0
- package/dist/lk/parse/portfolio-grades.d.ts +8 -0
- package/dist/lk/parse/portfolio-grades.js +41 -0
- package/dist/lk/parse/portfolio-performance.d.ts +2 -0
- package/dist/lk/parse/portfolio-performance.js +44 -0
- package/dist/lk/parse/portfolio.d.ts +6 -0
- package/dist/lk/parse/portfolio.js +64 -0
- package/dist/lk/parse/webinar-lesson.d.ts +7 -0
- package/dist/lk/parse/webinar-lesson.js +28 -0
- package/dist/lk/parse/webinars.d.ts +3 -0
- package/dist/lk/parse/webinars.js +67 -0
- package/dist/lk/portfolio-types.d.ts +113 -0
- package/dist/lk/portfolio-types.js +1 -0
- package/dist/lk/types.d.ts +29 -0
- package/dist/{tt → lk}/webinars.d.ts +3 -1
- package/dist/lk/webinars.js +52 -0
- package/dist/parsers.d.ts +3 -1
- package/dist/parsers.js +3 -1
- package/dist/tt/client.d.ts +1 -11
- package/dist/tt/client.js +1 -45
- package/dist/tt/domain/schedule.js +5 -1
- package/dist/tt/domain/substitution-occurrences.d.ts +3 -0
- package/dist/tt/domain/substitution-occurrences.js +75 -0
- package/dist/tt/domain/types.d.ts +1 -1
- package/dist/tt/observations.js +2 -1
- package/dist/tt/parse/index.d.ts +0 -1
- package/dist/tt/parse/index.js +0 -1
- package/dist/tt/types.d.ts +0 -21
- package/dist/tt/utils/index.d.ts +0 -1
- package/dist/tt/utils/index.js +0 -1
- package/dist/webinar/client.d.ts +52 -0
- package/dist/webinar/client.js +184 -0
- package/dist/webinar/ddp.d.ts +31 -0
- package/dist/webinar/ddp.js +208 -0
- package/dist/webinar/events.d.ts +6 -0
- package/dist/webinar/events.js +38 -0
- package/dist/webinar/gateway.d.ts +30 -0
- package/dist/webinar/gateway.js +114 -0
- package/dist/webinar/media-protocol.d.ts +9 -0
- package/dist/webinar/media-protocol.js +24 -0
- package/dist/webinar/media-types.d.ts +10 -0
- package/dist/webinar/media-types.js +1 -0
- package/dist/webinar/media.d.ts +21 -0
- package/dist/webinar/media.js +76 -0
- package/dist/webinar/parse.d.ts +14 -0
- package/dist/webinar/parse.js +113 -0
- package/dist/webinar/playback.d.ts +32 -0
- package/dist/webinar/playback.js +188 -0
- package/dist/webinar/socket.d.ts +3 -0
- package/dist/webinar/socket.js +18 -0
- package/dist/webinar/state.d.ts +4 -0
- package/dist/webinar/state.js +98 -0
- package/dist/webinar/types.d.ts +148 -0
- package/dist/webinar/types.js +12 -0
- package/docs/student-portal.md +151 -0
- package/docs/testing.md +13 -0
- package/docs/v5-migration.md +25 -2
- package/docs/webinar.md +145 -0
- package/package.json +2 -2
- package/dist/tt/parse/webinars.d.ts +0 -2
- package/dist/tt/parse/webinars.js +0 -97
- package/dist/tt/webinars.js +0 -39
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { parseHtml, text } from "../../common/parse.js";
|
|
2
|
+
import { ParseError } from "../../common/types.js";
|
|
3
|
+
import { displayedText, parsePortfolioContent, resolvePortfolioUrl } from "./portfolio-content.js";
|
|
4
|
+
import { parsePortfolioControlWeeks, parsePortfolioGrades } from "./portfolio-grades.js";
|
|
5
|
+
import { parsePortfolioPerformance } from "./portfolio-performance.js";
|
|
6
|
+
const BASE = "https://lk.chuvsu.ru";
|
|
7
|
+
/** Only the portfolio landing route or index.php?id=N can be discovered. */
|
|
8
|
+
export function parsePortfolioUrl(html) {
|
|
9
|
+
const doc = parseHtml(html);
|
|
10
|
+
for (const element of doc.querySelectorAll("a[href],button[onclick]")) {
|
|
11
|
+
const raw = element.getAttribute("href") ?? element.getAttribute("onclick")
|
|
12
|
+
?.match(/window\.open\(\s*['"]([^'"]+)['"]/u)?.[1];
|
|
13
|
+
const value = resolvePortfolioUrl(raw ?? null, `${BASE}/student/`);
|
|
14
|
+
if (!value)
|
|
15
|
+
continue;
|
|
16
|
+
const url = new URL(value);
|
|
17
|
+
if (url.origin !== BASE || !["/portfolio", "/portfolio/", "/portfolio/index.php"].includes(url.pathname))
|
|
18
|
+
continue;
|
|
19
|
+
if ([...url.searchParams.keys()].some((key) => key !== "id"))
|
|
20
|
+
continue;
|
|
21
|
+
const id = url.searchParams.get("id");
|
|
22
|
+
if (id !== null && !/^[1-9]\d*$/u.test(id))
|
|
23
|
+
continue;
|
|
24
|
+
return url.href;
|
|
25
|
+
}
|
|
26
|
+
throw new ParseError("LK home response has no portfolio link");
|
|
27
|
+
}
|
|
28
|
+
export function parsePortfolio(html, opts) {
|
|
29
|
+
const doc = parseHtml(html);
|
|
30
|
+
const fullName = text(doc.querySelector(".port_name"));
|
|
31
|
+
if (!fullName)
|
|
32
|
+
throw new ParseError("LK portfolio response has no student identity");
|
|
33
|
+
const photo = doc.querySelector('.port_pic[src]');
|
|
34
|
+
const photoUrl = resolvePortfolioUrl(photo?.getAttribute("src") ?? null, `${BASE}/portfolio/`);
|
|
35
|
+
const photoId = photoUrl ? new URL(photoUrl).searchParams.get("id") : null;
|
|
36
|
+
const requestedId = opts?.url ? new URL(opts.url).searchParams.get("id") : null;
|
|
37
|
+
const rawId = photoId ?? requestedId;
|
|
38
|
+
if (!rawId || !/^[1-9]\d*$/u.test(rawId) || !Number.isSafeInteger(Number(rawId))) {
|
|
39
|
+
throw new ParseError("LK portfolio response has no valid student ID");
|
|
40
|
+
}
|
|
41
|
+
if (requestedId && photoId && requestedId !== photoId) {
|
|
42
|
+
throw new ParseError("LK portfolio student ID differs from requested ID");
|
|
43
|
+
}
|
|
44
|
+
const url = `${BASE}/portfolio/index.php?id=${rawId}`;
|
|
45
|
+
const fields = {};
|
|
46
|
+
for (const label of doc.querySelectorAll(".port_param")) {
|
|
47
|
+
fields[text(label).replace(/:\s*$/u, "")] = label.nextElementSibling ? displayedText(label.nextElementSibling) : "";
|
|
48
|
+
}
|
|
49
|
+
const panels = [...doc.querySelectorAll('[role="tabpanel"]')].filter((panel) => !panel.parentElement?.closest('[role="tabpanel"]'));
|
|
50
|
+
if (!panels.length)
|
|
51
|
+
throw new ParseError("LK portfolio response has no sections");
|
|
52
|
+
const anchors = [...doc.querySelectorAll('a[href^="#"]')];
|
|
53
|
+
const titleFor = (panel) => text(anchors.find((anchor) => anchor.getAttribute("href") === `#${panel.id}`) ?? panel.querySelector("h2"));
|
|
54
|
+
const gradesPanel = panels.find((panel) => titleFor(panel) === "Зачетная книжка");
|
|
55
|
+
const controlsPanel = panels.find((panel) => titleFor(panel) === "Контрольные недели");
|
|
56
|
+
const performancePanel = panels.find((panel) => titleFor(panel) === "Текущая успеваемость");
|
|
57
|
+
return {
|
|
58
|
+
id: Number(rawId), url, student: { fullName, photoUrl, fields },
|
|
59
|
+
grades: gradesPanel ? parsePortfolioGrades(gradesPanel) : [],
|
|
60
|
+
controlWeeks: controlsPanel ? parsePortfolioControlWeeks(controlsPanel) : [],
|
|
61
|
+
performance: performancePanel ? parsePortfolioPerformance(performancePanel, url) : [],
|
|
62
|
+
sections: panels.map((panel) => ({ title: titleFor(panel), content: parsePortfolioContent(panel, url) })),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FLEXIBLE_LESSON_TYPE_RE_I, SUBGROUP_RE } from "../../tt/parse/patterns.js";
|
|
2
|
+
const GROUP_CODE_RE = /[A-ZА-ЯЁ]{1,}(?:-[A-ZА-ЯЁa-zа-яё0-9]+)+(?:\s*ин)?/u;
|
|
3
|
+
export function splitWebinarLesson(raw) {
|
|
4
|
+
const typeMatches = [...raw.matchAll(new RegExp(FLEXIBLE_LESSON_TYPE_RE_I, "gi"))];
|
|
5
|
+
const typeMatch = typeMatches.at(-1);
|
|
6
|
+
if (!typeMatch || typeMatch.index == null) {
|
|
7
|
+
return {
|
|
8
|
+
subject: raw,
|
|
9
|
+
type: "",
|
|
10
|
+
teacherRaw: "",
|
|
11
|
+
groupsRaw: "",
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const subject = raw.slice(0, typeMatch.index).trim();
|
|
15
|
+
const type = typeMatch[1].replace(/\.$/, "").toLowerCase();
|
|
16
|
+
const rest = raw.slice(typeMatch.index + typeMatch[0].length).trim();
|
|
17
|
+
const groupMatch = rest.match(GROUP_CODE_RE);
|
|
18
|
+
const teacherRaw = groupMatch?.index == null ? rest : rest.slice(0, groupMatch.index).trim();
|
|
19
|
+
const groupsRaw = groupMatch?.index == null ? "" : rest.slice(groupMatch.index).trim();
|
|
20
|
+
const subgroupMatch = raw.match(SUBGROUP_RE);
|
|
21
|
+
return {
|
|
22
|
+
subject,
|
|
23
|
+
type,
|
|
24
|
+
teacherRaw,
|
|
25
|
+
groupsRaw,
|
|
26
|
+
subgroup: subgroupMatch ? parseInt(subgroupMatch[1]) : undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parseHtml, parseTeacher, parseTime, text } from "../../common/parse.js";
|
|
2
|
+
import { ParseError } from "../../common/types.js";
|
|
3
|
+
import { isLocalDate } from "../../tt/utils/date.js";
|
|
4
|
+
import { parseLessonType } from "../../common/lesson-type.js";
|
|
5
|
+
import { parseGroupsString } from "../../tt/parse/groups.js";
|
|
6
|
+
import { splitWebinarLesson } from "./webinar-lesson.js";
|
|
7
|
+
function dateValue(value) {
|
|
8
|
+
return value && isLocalDate(value) ? value : undefined;
|
|
9
|
+
}
|
|
10
|
+
function timeValue(value) {
|
|
11
|
+
return value.match(/\b(?:[01]\d|2[0-3]):[0-5]\d\b/u)?.[0];
|
|
12
|
+
}
|
|
13
|
+
export function parseWebinarPage(html) {
|
|
14
|
+
const doc = parseHtml(html);
|
|
15
|
+
const select = doc.querySelector('select[name="day"]');
|
|
16
|
+
if (!select && !doc.querySelector("table.webtable")) {
|
|
17
|
+
throw new ParseError("LK response has no webinar page");
|
|
18
|
+
}
|
|
19
|
+
const scriptDate = html.match(/\$\(['"]#day['"]\)\.val\(['"]([^'"]+)['"]\)/u)?.[1];
|
|
20
|
+
const date = dateValue(scriptDate) ?? dateValue(select?.querySelector("option[selected]")?.getAttribute("value")) ?? dateValue(select?.querySelector("option")?.getAttribute("value"));
|
|
21
|
+
const availableDates = [...(select?.querySelectorAll("option") ?? [])]
|
|
22
|
+
.map((option) => dateValue(option.getAttribute("value")))
|
|
23
|
+
.filter((value) => value !== undefined);
|
|
24
|
+
const webinars = [];
|
|
25
|
+
for (const table of doc.querySelectorAll("table.webtable")) {
|
|
26
|
+
const heading = text(table.parentElement?.querySelector("h3") ?? null);
|
|
27
|
+
const scheduled = /по расписанию/iu.test(heading);
|
|
28
|
+
for (const row of table.querySelectorAll("tbody > tr")) {
|
|
29
|
+
const cells = [...row.children];
|
|
30
|
+
if (cells.length < 6)
|
|
31
|
+
continue;
|
|
32
|
+
const start = timeValue(text(cells[0]));
|
|
33
|
+
const end = timeValue(text(cells[1]));
|
|
34
|
+
if (!start || !end)
|
|
35
|
+
continue;
|
|
36
|
+
const raw = text(cells[3]);
|
|
37
|
+
const lesson = splitWebinarLesson(raw);
|
|
38
|
+
const button = cells[5].querySelector('[onclick*="jointo"]');
|
|
39
|
+
const id = button?.getAttribute("onclick")?.match(/jointo\(\s*['"]?(\d+)['"]?\s*\)/u)?.[1] ?? null;
|
|
40
|
+
const server = cells[5].cloneNode(true);
|
|
41
|
+
for (const control of server.querySelectorAll("button"))
|
|
42
|
+
control.remove();
|
|
43
|
+
const slot = text(cells[0]).match(/\((\d+)\)/u)?.[1];
|
|
44
|
+
webinars.push({
|
|
45
|
+
id,
|
|
46
|
+
scheduled,
|
|
47
|
+
scheduledDate: date,
|
|
48
|
+
slotNumber: slot ? Number(slot) : undefined,
|
|
49
|
+
time: { start: parseTime(start), end: parseTime(end) },
|
|
50
|
+
subject: lesson.subject,
|
|
51
|
+
type: parseLessonType(lesson.type),
|
|
52
|
+
teacher: parseTeacher(lesson.teacherRaw),
|
|
53
|
+
groups: parseGroupsString(lesson.groupsRaw),
|
|
54
|
+
subgroup: lesson.subgroup,
|
|
55
|
+
title: text(cells[2]),
|
|
56
|
+
raw,
|
|
57
|
+
server: text(server),
|
|
58
|
+
completedAt: text(cells[4]) || null,
|
|
59
|
+
joinAvailable: id !== null && !button?.hasAttribute("disabled"),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { date, availableDates: [...new Set(availableDates)], webinars };
|
|
64
|
+
}
|
|
65
|
+
export function parseWebinars(html) {
|
|
66
|
+
return parseWebinarPage(html).webinars;
|
|
67
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { LessonType } from "../common/lesson-type.js";
|
|
2
|
+
export type PortfolioGradeValue = number | boolean | null;
|
|
3
|
+
/** Displayed content only; scripts and profile-changing controls are excluded. */
|
|
4
|
+
export interface PortfolioLink {
|
|
5
|
+
text: string;
|
|
6
|
+
url: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
content?: PortfolioContent[];
|
|
9
|
+
}
|
|
10
|
+
export interface PortfolioCell {
|
|
11
|
+
text: string;
|
|
12
|
+
header: boolean;
|
|
13
|
+
colspan: number;
|
|
14
|
+
rowspan: number;
|
|
15
|
+
links: PortfolioLink[];
|
|
16
|
+
/** Tooltips often contain department names or grade details. */
|
|
17
|
+
notes: string[];
|
|
18
|
+
content: PortfolioContent[];
|
|
19
|
+
}
|
|
20
|
+
export interface PortfolioTable {
|
|
21
|
+
rows: PortfolioCell[][];
|
|
22
|
+
}
|
|
23
|
+
export type PortfolioContent = {
|
|
24
|
+
kind: "text";
|
|
25
|
+
text: string;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "heading";
|
|
28
|
+
level: number;
|
|
29
|
+
text: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "link";
|
|
32
|
+
link: PortfolioLink;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "image";
|
|
35
|
+
url: string;
|
|
36
|
+
alt: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "table";
|
|
40
|
+
table: PortfolioTable;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "group";
|
|
43
|
+
label?: string;
|
|
44
|
+
content: PortfolioContent[];
|
|
45
|
+
};
|
|
46
|
+
export interface PortfolioSection {
|
|
47
|
+
title: string;
|
|
48
|
+
content: PortfolioContent[];
|
|
49
|
+
}
|
|
50
|
+
/** Referral metadata is parsed only. No order is submitted. */
|
|
51
|
+
export interface PortfolioReferral {
|
|
52
|
+
semester: number;
|
|
53
|
+
disciplineId: number;
|
|
54
|
+
lessonTypeId: number;
|
|
55
|
+
type: number;
|
|
56
|
+
key: number;
|
|
57
|
+
code: string;
|
|
58
|
+
}
|
|
59
|
+
export interface PortfolioGrade {
|
|
60
|
+
semester: number;
|
|
61
|
+
code: string;
|
|
62
|
+
subject: string;
|
|
63
|
+
assessment: LessonType;
|
|
64
|
+
/** Numeric grade, credit result, or null when no recognized grade is reported. */
|
|
65
|
+
grade: PortfolioGradeValue;
|
|
66
|
+
notes: string[];
|
|
67
|
+
referral?: PortfolioReferral;
|
|
68
|
+
}
|
|
69
|
+
export interface PortfolioControlWeek {
|
|
70
|
+
semester: number;
|
|
71
|
+
subject: string;
|
|
72
|
+
grades: (number | null)[];
|
|
73
|
+
}
|
|
74
|
+
export interface PortfolioAttendance {
|
|
75
|
+
month: string;
|
|
76
|
+
day: number;
|
|
77
|
+
slotNumber: number;
|
|
78
|
+
type: LessonType;
|
|
79
|
+
subgroup?: number;
|
|
80
|
+
/** Preserve +, Н, numeric grades and empty cells without reinterpretation. */
|
|
81
|
+
mark: string;
|
|
82
|
+
notes: string[];
|
|
83
|
+
}
|
|
84
|
+
export interface PortfolioActivity {
|
|
85
|
+
title: string;
|
|
86
|
+
value: string;
|
|
87
|
+
notes: string[];
|
|
88
|
+
links: PortfolioLink[];
|
|
89
|
+
content: PortfolioContent[];
|
|
90
|
+
}
|
|
91
|
+
export interface PortfolioPerformance {
|
|
92
|
+
subject: string;
|
|
93
|
+
attendance: PortfolioAttendance[];
|
|
94
|
+
activities: {
|
|
95
|
+
teacher: string;
|
|
96
|
+
items: PortfolioActivity[];
|
|
97
|
+
}[];
|
|
98
|
+
}
|
|
99
|
+
export interface StudentPortfolio {
|
|
100
|
+
id: number;
|
|
101
|
+
url: string;
|
|
102
|
+
student: {
|
|
103
|
+
fullName: string;
|
|
104
|
+
photoUrl?: string;
|
|
105
|
+
/** All displayed identity fields keyed by their original LK labels. */
|
|
106
|
+
fields: Record<string, string>;
|
|
107
|
+
};
|
|
108
|
+
grades: PortfolioGrade[];
|
|
109
|
+
controlWeeks: PortfolioControlWeek[];
|
|
110
|
+
performance: PortfolioPerformance[];
|
|
111
|
+
/** All tabs, including achievements, interests, practices, coursework and thesis. */
|
|
112
|
+
sections: PortfolioSection[];
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/lk/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { LocalDate, Teacher, TimeRange } from "../common/types.js";
|
|
1
2
|
import type { BlobAdapter, CacheAdapter } from "../common/cache.js";
|
|
3
|
+
import type { LessonType } from "../common/lesson-type.js";
|
|
2
4
|
export interface StudentProfile {
|
|
3
5
|
lastName: string;
|
|
4
6
|
firstName: string;
|
|
@@ -18,9 +20,36 @@ export interface StudentPortalCacheConfig {
|
|
|
18
20
|
profile?: number;
|
|
19
21
|
profilePhoto?: number;
|
|
20
22
|
timetableGroupId?: number;
|
|
23
|
+
webinars?: number;
|
|
24
|
+
portfolio?: number;
|
|
21
25
|
}
|
|
22
26
|
export interface StudentPortalClientOptions {
|
|
23
27
|
cache?: number | StudentPortalCacheConfig;
|
|
24
28
|
cacheAdapter?: CacheAdapter;
|
|
25
29
|
blobAdapter?: BlobAdapter;
|
|
26
30
|
}
|
|
31
|
+
/** A row from LK's personal webinar page, including unavailable meetings. */
|
|
32
|
+
export interface Webinar {
|
|
33
|
+
/** Null when LK does not expose a join button. Never a timetable ID. */
|
|
34
|
+
id: string | null;
|
|
35
|
+
scheduled: boolean;
|
|
36
|
+
scheduledDate?: LocalDate;
|
|
37
|
+
slotNumber?: number;
|
|
38
|
+
time: TimeRange;
|
|
39
|
+
subject: string;
|
|
40
|
+
type: LessonType;
|
|
41
|
+
teacher: Teacher;
|
|
42
|
+
groups: string[];
|
|
43
|
+
subgroup?: number;
|
|
44
|
+
title: string;
|
|
45
|
+
raw: string;
|
|
46
|
+
server: string;
|
|
47
|
+
completedAt: string | null;
|
|
48
|
+
joinAvailable: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface WebinarPage {
|
|
51
|
+
/** Selected date reported by LK; never inferred from the machine timezone. */
|
|
52
|
+
date?: LocalDate;
|
|
53
|
+
availableDates: LocalDate[];
|
|
54
|
+
webinars: Webinar[];
|
|
55
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { LessonOccurrence } from "
|
|
1
|
+
import type { LessonOccurrence } from "../tt/domain/types.js";
|
|
2
2
|
import type { Webinar } from "./types.js";
|
|
3
3
|
export type LessonWithWebinar = LessonOccurrence & {
|
|
4
4
|
webinar?: Webinar;
|
|
5
5
|
};
|
|
6
6
|
export declare function findWebinar(lesson: LessonOccurrence, webinars: Webinar[]): Webinar | undefined;
|
|
7
|
+
/** All compatible rows; callers can resolve ambiguity explicitly. */
|
|
8
|
+
export declare function findWebinars(lesson: LessonOccurrence, webinars: Webinar[]): Webinar[];
|
|
7
9
|
export declare function attachWebinars(lessons: LessonOccurrence[], webinars: Webinar[]): LessonWithWebinar[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LessonType } from "../common/lesson-type.js";
|
|
2
|
+
function normalize(value) {
|
|
3
|
+
return value
|
|
4
|
+
.toLocaleLowerCase("ru-RU")
|
|
5
|
+
.replace(/ё/gu, "е")
|
|
6
|
+
.replace(/\s+/gu, " ")
|
|
7
|
+
.trim();
|
|
8
|
+
}
|
|
9
|
+
export function findWebinar(lesson, webinars) {
|
|
10
|
+
const matches = findWebinars(lesson, webinars);
|
|
11
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** All compatible rows; callers can resolve ambiguity explicitly. */
|
|
14
|
+
export function findWebinars(lesson, webinars) {
|
|
15
|
+
if (lesson.status === "cancelled")
|
|
16
|
+
return [];
|
|
17
|
+
return webinars.filter((webinar) => {
|
|
18
|
+
if (!webinar.scheduled)
|
|
19
|
+
return false;
|
|
20
|
+
if (webinar.scheduledDate !== lesson.scheduledDate)
|
|
21
|
+
return false;
|
|
22
|
+
if (webinar.slotNumber != null &&
|
|
23
|
+
webinar.slotNumber !== lesson.slotNumber) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!lesson.time ||
|
|
27
|
+
webinar.time.start.hours !== lesson.time.start.hours ||
|
|
28
|
+
webinar.time.start.minutes !== lesson.time.start.minutes ||
|
|
29
|
+
webinar.time.end.hours !== lesson.time.end.hours ||
|
|
30
|
+
webinar.time.end.minutes !== lesson.time.end.minutes) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (normalize(webinar.subject) !== normalize(lesson.subject))
|
|
34
|
+
return false;
|
|
35
|
+
if (webinar.type !== LessonType.Unknown && lesson.type !== LessonType.Unknown && webinar.type !== lesson.type)
|
|
36
|
+
return false;
|
|
37
|
+
const groups = lesson.groups.values;
|
|
38
|
+
if (groups.length && webinar.groups.length && !groups.some((attendance) => webinar.groups.some((group) => normalize(group) === normalize(attendance.group.name)) &&
|
|
39
|
+
(webinar.subgroup == null || attendance.subgroup == null || webinar.subgroup === attendance.subgroup)))
|
|
40
|
+
return false;
|
|
41
|
+
const teachers = lesson.teachers.values.filter((teacher) => teacher.name.trim());
|
|
42
|
+
if (teachers.length && webinar.teacher.name.trim() && !teachers.some((teacher) => normalize(teacher.name) === normalize(webinar.teacher.name)))
|
|
43
|
+
return false;
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function attachWebinars(lessons, webinars) {
|
|
48
|
+
return lessons.map((lesson) => {
|
|
49
|
+
const webinar = findWebinar(lesson, webinars);
|
|
50
|
+
return webinar ? { ...lesson, webinar } : lesson;
|
|
51
|
+
});
|
|
52
|
+
}
|
package/dist/parsers.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo,
|
|
1
|
+
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo, } from "./tt/parse/index.js";
|
|
2
2
|
export { createScheduleSourceSnapshot } from "./tt/observations.js";
|
|
3
3
|
export type { ParsedScheduleDay, ParsedLesson, ParsedScheduleBlock, } from "./tt/types.js";
|
|
4
|
+
export { parseWebinars, parseWebinarPage } from "./lk/parse/webinars.js";
|
|
5
|
+
export { parsePortfolio, parsePortfolioUrl } from "./lk/parse/portfolio.js";
|
package/dist/parsers.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo,
|
|
1
|
+
export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseFacultyButtons, parseGroupSchedule, parseGroupName, parseGroupButtons, parseGroupsString, parsePeriodFromPage, parseTeacherButtons, parseTeacherSchedule, parseTeacherInfo, } from "./tt/parse/index.js";
|
|
2
2
|
export { createScheduleSourceSnapshot } from "./tt/observations.js";
|
|
3
|
+
export { parseWebinars, parseWebinarPage } from "./lk/parse/webinars.js";
|
|
4
|
+
export { parsePortfolio, parsePortfolioUrl } from "./lk/parse/portfolio.js";
|
package/dist/tt/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CacheEntry } from "../common/cache.js";
|
|
|
2
2
|
import { Schedule } from "./domain/schedule.js";
|
|
3
3
|
import { TimetableRepository } from "./domain/repository.js";
|
|
4
4
|
import type { GroupRef, RoomRef, ScheduleOwner, TeacherRef, TimetableRepositorySnapshot } from "./domain/types.js";
|
|
5
|
-
import type { Room, RoomInfo, Faculty, Group, TeacherInfo, TimetableClientOptions, CacheConfig, DirectoryPreloadOptions, EntityResolutionStrategy, GetScheduleOptions
|
|
5
|
+
import type { Room, RoomInfo, Faculty, Group, TeacherInfo, TimetableClientOptions, CacheConfig, DirectoryPreloadOptions, EntityResolutionStrategy, GetScheduleOptions } from "./types.js";
|
|
6
6
|
export declare class TimetableClient {
|
|
7
7
|
private http;
|
|
8
8
|
private educationLevel;
|
|
@@ -48,16 +48,6 @@ export declare class TimetableClient {
|
|
|
48
48
|
private fetchOwnerSchedule;
|
|
49
49
|
getSchedule(owner: ScheduleOwner, options?: GetScheduleOptions): Promise<Schedule>;
|
|
50
50
|
getGroupSchedule(groupId: number, options?: GetScheduleOptions): Promise<Schedule>;
|
|
51
|
-
getWebinars(opts?: {
|
|
52
|
-
date?: Date;
|
|
53
|
-
facultyId?: number;
|
|
54
|
-
}): Promise<Webinar[]>;
|
|
55
|
-
getWebinarJoinUrl(opts: {
|
|
56
|
-
webinarId: string | number;
|
|
57
|
-
idType?: number;
|
|
58
|
-
email: string;
|
|
59
|
-
password: string;
|
|
60
|
-
}): Promise<string>;
|
|
61
51
|
getFaculties(): Promise<Faculty[]>;
|
|
62
52
|
getFacultyGroups(facultyId: number): Promise<Group[]>;
|
|
63
53
|
searchGroups(name: string): Promise<GroupRef[]>;
|
package/dist/tt/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpClient, } from "../common/http.js";
|
|
2
2
|
import { HybridCache } from "../common/cache.js";
|
|
3
3
|
import { AcademicPeriod, AuthError, EducationLevel, ParseError, } from "../common/types.js";
|
|
4
|
-
import { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseGroupButtons, parseGroupName, parseFacultyButtons, parseTeacherButtons, parseGroupSchedule, parseTeacherSchedule, parseTeacherInfo, parsePeriodFromPage,
|
|
4
|
+
import { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButtons, parseRoomSchedule, parseRoomInfo, parseRoomName, parseGroupButtons, parseGroupName, parseFacultyButtons, parseTeacherButtons, parseGroupSchedule, parseTeacherSchedule, parseTeacherInfo, parsePeriodFromPage, } from "./parse/index.js";
|
|
5
5
|
import { Schedule } from "./domain/schedule.js";
|
|
6
6
|
import { TimetableRepository } from "./domain/repository.js";
|
|
7
7
|
import { createScheduleSourceSnapshot } from "./observations.js";
|
|
@@ -57,15 +57,8 @@ function makeUniformCacheConfig(ttl) {
|
|
|
57
57
|
teacherPhotos: ttl,
|
|
58
58
|
roomInfo: ttl,
|
|
59
59
|
roomImages: ttl,
|
|
60
|
-
webinars: ttl,
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
|
-
function formatDate(date) {
|
|
64
|
-
const year = date.getFullYear();
|
|
65
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
66
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
67
|
-
return `${year}-${month}-${day}`;
|
|
68
|
-
}
|
|
69
62
|
export class TimetableClient {
|
|
70
63
|
http = new HttpClient();
|
|
71
64
|
educationLevel;
|
|
@@ -400,43 +393,6 @@ export class TimetableClient {
|
|
|
400
393
|
group: this._repository.directory.resolveGroup({ id: groupId, name: "" }),
|
|
401
394
|
}, options);
|
|
402
395
|
}
|
|
403
|
-
async getWebinars(opts) {
|
|
404
|
-
const date = opts?.date ?? new Date();
|
|
405
|
-
const facultyId = opts?.facultyId ?? 0;
|
|
406
|
-
const cacheKey = `${formatDate(date)}:${facultyId}:${this.pertt}`;
|
|
407
|
-
const cached = await this.cache?.get("webinars", cacheKey);
|
|
408
|
-
if (cached)
|
|
409
|
-
return cached;
|
|
410
|
-
const { body } = await this.authPost(`${BASE}/webinar`, {
|
|
411
|
-
seldate: formatDate(date),
|
|
412
|
-
selfac: String(facultyId),
|
|
413
|
-
pertt: this.pertt,
|
|
414
|
-
});
|
|
415
|
-
const data = parseWebinars(body);
|
|
416
|
-
await this.cache?.set("webinars", cacheKey, data);
|
|
417
|
-
return data;
|
|
418
|
-
}
|
|
419
|
-
async getWebinarJoinUrl(opts) {
|
|
420
|
-
const { body } = await this.authPost(`${BASE}/webinar/getjoin`, {
|
|
421
|
-
idw: String(opts.webinarId),
|
|
422
|
-
idwt: String(opts.idType ?? 1),
|
|
423
|
-
name: opts.email,
|
|
424
|
-
pass: opts.password,
|
|
425
|
-
auto: "1",
|
|
426
|
-
});
|
|
427
|
-
let parsed;
|
|
428
|
-
try {
|
|
429
|
-
parsed = JSON.parse(body);
|
|
430
|
-
}
|
|
431
|
-
catch {
|
|
432
|
-
throw new AuthError("TT webinar join failed: invalid response");
|
|
433
|
-
}
|
|
434
|
-
const data = parsed;
|
|
435
|
-
if (data.mes !== "SUCCESS" || !data.url?.startsWith("http")) {
|
|
436
|
-
throw new AuthError(data.mes ?? "TT webinar join failed");
|
|
437
|
-
}
|
|
438
|
-
return data.url;
|
|
439
|
-
}
|
|
440
396
|
// --- Search / Discovery ---
|
|
441
397
|
async getFaculties() {
|
|
442
398
|
const cached = await this.cache?.get("faculties", "all");
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AcademicPeriod, LocalDate, TimeRange, WeekRange } from "../../common/types.js";
|
|
2
|
-
import type { LessonType } from "
|
|
2
|
+
import type { LessonType } from "../../common/lesson-type.js";
|
|
3
3
|
export type LessonSeriesId = string;
|
|
4
4
|
export type LessonId = string;
|
|
5
5
|
export interface NamedEntityRef {
|
package/dist/tt/observations.js
CHANGED
package/dist/tt/parse/index.d.ts
CHANGED
|
@@ -3,4 +3,3 @@ export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButt
|
|
|
3
3
|
export { parseGroupSchedule } from "./full-schedule.js";
|
|
4
4
|
export { parseRoomSchedule, parseRoomInfo, } from "./audience.js";
|
|
5
5
|
export { parseTeacherSchedule, parseTeacherInfo, } from "./teacher.js";
|
|
6
|
-
export { parseWebinars } from "./webinars.js";
|
package/dist/tt/parse/index.js
CHANGED
|
@@ -3,4 +3,3 @@ export { parseAcademicYearFromPage, parseAvailablePeriodsFromPage, parseRoomButt
|
|
|
3
3
|
export { parseGroupSchedule } from "./full-schedule.js";
|
|
4
4
|
export { parseRoomSchedule, parseRoomInfo, } from "./audience.js";
|
|
5
5
|
export { parseTeacherSchedule, parseTeacherInfo, } from "./teacher.js";
|
|
6
|
-
export { parseWebinars } from "./webinars.js";
|