chuvsu-js 5.5.2 → 5.5.4
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 +6 -9
- package/dist/common/http.js +2 -4
- package/dist/common/lesson-type.js +6 -1
- package/dist/common/parse.js +3 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/lk/client.js +10 -4
- package/dist/lk/parse/grade-value.js +5 -1
- package/dist/lk/parse/portfolio-content.js +58 -16
- package/dist/lk/parse/portfolio-grades.js +37 -9
- package/dist/lk/parse/portfolio-performance.js +26 -8
- package/dist/lk/parse/portfolio.js +31 -13
- package/dist/lk/parse/webinar-lesson.js +4 -2
- package/dist/lk/parse/webinars.js +7 -3
- package/dist/lk/webinars.js +3 -1
- package/dist/tt/client.js +15 -7
- package/dist/tt/domain/directory.js +2 -4
- package/dist/tt/domain/index.d.ts +2 -2
- package/dist/tt/domain/index.js +2 -2
- package/dist/tt/domain/repository.js +67 -35
- package/dist/tt/domain/schedule-snapshot.js +51 -24
- package/dist/tt/domain/schedule.js +7 -3
- package/dist/tt/observations.js +7 -2
- package/dist/tt/parse/audience.js +3 -1
- package/dist/tt/parse/entry-parts.js +2 -3
- package/dist/tt/parse/full-schedule.js +1 -1
- package/dist/tt/parse/groups.js +1 -3
- package/dist/tt/parse/index.d.ts +2 -2
- package/dist/tt/parse/index.js +2 -2
- package/dist/tt/parse/lists.js +3 -3
- package/dist/tt/parse/overlays.js +7 -2
- package/dist/tt/utils/date.js +2 -2
- package/dist/tt/utils/period.js +2 -1
- package/dist/tt/utils/semester.js +2 -2
- package/dist/tt/utils/time-slots.js +81 -15
- package/dist/webinar/chat-subscription.js +2 -1
- package/dist/webinar/client.d.ts +11 -0
- package/dist/webinar/client.js +136 -33
- package/dist/webinar/ddp.js +40 -13
- package/dist/webinar/events.js +7 -2
- package/dist/webinar/gateway.js +57 -16
- package/dist/webinar/media-protocol.d.ts +2 -1
- package/dist/webinar/media-protocol.js +30 -5
- package/dist/webinar/media.js +10 -4
- package/dist/webinar/parse.js +62 -14
- package/dist/webinar/playback.d.ts +3 -0
- package/dist/webinar/playback.js +67 -15
- package/dist/webinar/socket.js +4 -1
- package/dist/webinar/state.js +73 -26
- package/dist/webinar/types.d.ts +14 -0
- package/dist/webinar/typing.d.ts +8 -0
- package/dist/webinar/typing.js +36 -0
- package/docs/fixture-review.md +44 -44
- package/docs/student-portal.md +11 -2
- package/docs/v5-migration.md +85 -88
- package/docs/webinar.md +19 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ const after = groupSchedule.on(date);
|
|
|
108
108
|
Связи имеют вид `RelationSet<T>`:
|
|
109
109
|
|
|
110
110
|
```ts
|
|
111
|
-
lesson.rooms // { values: RoomRef[], completeness: "unknown" | "partial" | "complete" }
|
|
111
|
+
lesson.rooms; // { values: RoomRef[], completeness: "unknown" | "partial" | "complete" }
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
`unknown` означает, что страница ничего не сообщила. `complete` с пустым
|
|
@@ -121,8 +121,8 @@ lesson.rooms // { values: RoomRef[], completeness: "unknown" | "partial" | "comp
|
|
|
121
121
|
утверждения:
|
|
122
122
|
|
|
123
123
|
```ts
|
|
124
|
-
lesson.slotNumber // 6
|
|
125
|
-
lesson.time
|
|
124
|
+
lesson.slotNumber; // 6
|
|
125
|
+
lesson.time; // { start: { hours: 16, minutes: 40 }, end: ... }
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
Номер не вычисляется из времени, а время — из номера. При объединении одна
|
|
@@ -197,10 +197,7 @@ const snapshot = await client.exportRepository();
|
|
|
197
197
|
Для одного процесса есть память:
|
|
198
198
|
|
|
199
199
|
```ts
|
|
200
|
-
import {
|
|
201
|
-
MemoryTimetableRepositoryAdapter,
|
|
202
|
-
TimetableClient,
|
|
203
|
-
} from "chuvsu-js";
|
|
200
|
+
import { MemoryTimetableRepositoryAdapter, TimetableClient } from "chuvsu-js";
|
|
204
201
|
|
|
205
202
|
const repositoryAdapter = new MemoryTimetableRepositoryAdapter();
|
|
206
203
|
const client = new TimetableClient({ repositoryAdapter });
|
|
@@ -228,8 +225,8 @@ const lessons = schedule.on(new Date(2026, 8, 7));
|
|
|
228
225
|
портала нельзя надежно перенести в чистый браузерный пакет.
|
|
229
226
|
|
|
230
227
|
```ts
|
|
231
|
-
import { TimetableClient } from "chuvsu-js";
|
|
232
|
-
import { TimetableClient } from "chuvsu-js/node";
|
|
228
|
+
import { TimetableClient } from "chuvsu-js"; // Node + ядро
|
|
229
|
+
import { TimetableClient } from "chuvsu-js/node"; // явно Node
|
|
233
230
|
import { TimetableRepository } from "chuvsu-js/browser";
|
|
234
231
|
import { parseGroupSchedule } from "chuvsu-js/parsers";
|
|
235
232
|
```
|
package/dist/common/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent, fetch, WebSocket } from "undici";
|
|
1
|
+
import { Agent, fetch, WebSocket, } from "undici";
|
|
2
2
|
import { CHUVSU_CA_CERTS } from "./certs.js";
|
|
3
3
|
const agent = new Agent({
|
|
4
4
|
connect: { ca: CHUVSU_CA_CERTS },
|
|
@@ -6,9 +6,7 @@ const agent = new Agent({
|
|
|
6
6
|
export class HttpClient {
|
|
7
7
|
cookies = new Map();
|
|
8
8
|
cookieHeader() {
|
|
9
|
-
return [...this.cookies.entries()]
|
|
10
|
-
.map(([k, v]) => `${k}=${v}`)
|
|
11
|
-
.join("; ");
|
|
9
|
+
return [...this.cookies.entries()].map(([k, v]) => `${k}=${v}`).join("; ");
|
|
12
10
|
}
|
|
13
11
|
saveCookies(headers) {
|
|
14
12
|
const raw = headers.getSetCookie?.() ?? [];
|
|
@@ -44,5 +44,10 @@ const TYPE_BY_CODE = {
|
|
|
44
44
|
};
|
|
45
45
|
/** Convert portal short code or full assessment label into a domain identifier. */
|
|
46
46
|
export function parseLessonType(code) {
|
|
47
|
-
return TYPE_BY_CODE[code
|
|
47
|
+
return (TYPE_BY_CODE[code
|
|
48
|
+
.trim()
|
|
49
|
+
.toLocaleLowerCase("ru-RU")
|
|
50
|
+
.replace(/ё/gu, "е")
|
|
51
|
+
.replace(/\s+/gu, " ")
|
|
52
|
+
.replace(/\.$/u, "")] ?? LessonType.Unknown);
|
|
48
53
|
}
|
package/dist/common/parse.js
CHANGED
|
@@ -34,7 +34,9 @@ export function parseTeacher(s) {
|
|
|
34
34
|
const posMatch = trimmed.match(/^(доц\.|проф\.|ст\.преп\.|ст\. преп\.|преп\.|асс\.|зав\.каф\.)\s*/);
|
|
35
35
|
const afterPos = posMatch ? trimmed.slice(posMatch[0].length) : trimmed;
|
|
36
36
|
const degMatch = afterPos.match(/^((?:[кд]\.[а-яё.-]+н\.|к\.иск\.))\s*/);
|
|
37
|
-
const name = degMatch
|
|
37
|
+
const name = degMatch
|
|
38
|
+
? afterPos.slice(degMatch[0].length).trim()
|
|
39
|
+
: afterPos.trim();
|
|
38
40
|
const result = { name };
|
|
39
41
|
if (posMatch)
|
|
40
42
|
result.position = posMatch[1];
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { LessonType, parseLessonType } from "./common/lesson-type.js";
|
|
2
|
+
export { parseTeacher } from "./common/parse.js";
|
|
2
3
|
export * from "./tt/domain/index.js";
|
|
3
4
|
export { attachWebinars, findWebinar, findWebinars } from "./lk/webinars.js";
|
|
4
5
|
export type { LessonWithWebinar } from "./lk/webinars.js";
|
|
@@ -7,7 +8,7 @@ export { WebinarClient } from "./webinar/client.js";
|
|
|
7
8
|
export { WebinarMediaClient } from "./webinar/media.js";
|
|
8
9
|
export { WebinarPlayback } from "./webinar/playback.js";
|
|
9
10
|
export type * from "./webinar/media-types.js";
|
|
10
|
-
export { WebinarPermissionError, WebinarProtocolError } from "./webinar/types.js";
|
|
11
|
+
export { WebinarPermissionError, WebinarProtocolError, } from "./webinar/types.js";
|
|
11
12
|
export type * from "./webinar/types.js";
|
|
12
13
|
export { getAdjacentSemester, getCompensatingWorkDays, getCurrentPeriod, getEffectiveHolidays, formatLocalDate, getHolidayTransfers, getSemesterStart, getSemesterWeeks, getStandardScheduleBlocks, getWeekNumber, getWeekdayName, isHoliday, isLocalDate, isSessionPeriod, parseLocalDate, RUSSIAN_HOLIDAYS, } from "./tt/utils/index.js";
|
|
13
14
|
export type { Holiday, HolidayTransfer } from "./tt/utils/index.js";
|
package/dist/core.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Runtime-safe core for Node.js, browsers, Deno, and workers.
|
|
2
2
|
export { LessonType, parseLessonType } from "./common/lesson-type.js";
|
|
3
|
+
export { parseTeacher } from "./common/parse.js";
|
|
3
4
|
export * from "./tt/domain/index.js";
|
|
4
5
|
export { attachWebinars, findWebinar, findWebinars } from "./lk/webinars.js";
|
|
5
6
|
export { WebinarClient } from "./webinar/client.js";
|
|
6
7
|
export { WebinarMediaClient } from "./webinar/media.js";
|
|
7
8
|
export { WebinarPlayback } from "./webinar/playback.js";
|
|
8
|
-
export { WebinarPermissionError, WebinarProtocolError } from "./webinar/types.js";
|
|
9
|
+
export { WebinarPermissionError, WebinarProtocolError, } from "./webinar/types.js";
|
|
9
10
|
export { getAdjacentSemester, getCompensatingWorkDays, getCurrentPeriod, getEffectiveHolidays, formatLocalDate, getHolidayTransfers, getSemesterStart, getSemesterWeeks, getStandardScheduleBlocks, getWeekNumber, getWeekdayName, isHoliday, isLocalDate, isSessionPeriod, parseLocalDate, RUSSIAN_HOLIDAYS, } from "./tt/utils/index.js";
|
|
10
11
|
export { AuthError, EducationLevel, ParseError, AcademicPeriod, } from "./common/types.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { StudentPortalClient } from "./lk/client.js";
|
|
|
3
3
|
export { WebinarGateway } from "./webinar/gateway.js";
|
|
4
4
|
export { TimetableClient } from "./tt/client.js";
|
|
5
5
|
export * from "./parsers.js";
|
|
6
|
-
export type { BlobAdapter, BlobPutOptions
|
|
6
|
+
export type { BlobAdapter, BlobPutOptions } from "./common/cache.js";
|
package/dist/lk/client.js
CHANGED
|
@@ -106,7 +106,7 @@ export class StudentPortalClient {
|
|
|
106
106
|
}
|
|
107
107
|
async getProfilePhoto() {
|
|
108
108
|
const cached = this.cache?.getLocal("profilePhoto", "self") ??
|
|
109
|
-
await this.cache?.get("profilePhoto", "self");
|
|
109
|
+
(await this.cache?.get("profilePhoto", "self"));
|
|
110
110
|
if (cached !== null && cached !== undefined) {
|
|
111
111
|
const entry = cached;
|
|
112
112
|
if (typeof entry === "string")
|
|
@@ -117,7 +117,9 @@ export class StudentPortalClient {
|
|
|
117
117
|
if (entry.blobKey && this.blobAdapter) {
|
|
118
118
|
const photo = await this.blobAdapter.get(entry.blobKey);
|
|
119
119
|
if (photo) {
|
|
120
|
-
this.cache?.setLocal("profilePhoto", "self", {
|
|
120
|
+
this.cache?.setLocal("profilePhoto", "self", {
|
|
121
|
+
data: photo.toString("base64"),
|
|
122
|
+
});
|
|
121
123
|
return photo;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
@@ -125,7 +127,9 @@ export class StudentPortalClient {
|
|
|
125
127
|
const photo = await this.authGetBuffer(`${STUDENT_BASE}/face.php`);
|
|
126
128
|
if (this.blobAdapter) {
|
|
127
129
|
const blobKey = "lk/photo/self";
|
|
128
|
-
this.cache?.setLocal("profilePhoto", "self", {
|
|
130
|
+
this.cache?.setLocal("profilePhoto", "self", {
|
|
131
|
+
data: photo.toString("base64"),
|
|
132
|
+
});
|
|
129
133
|
await this.blobAdapter.put(blobKey, photo, {
|
|
130
134
|
ttl: this.cache?.ttl("profilePhoto"),
|
|
131
135
|
});
|
|
@@ -151,7 +155,9 @@ export class StudentPortalClient {
|
|
|
151
155
|
if (opts?.date !== undefined && !isLocalDate(opts.date)) {
|
|
152
156
|
throw new RangeError("Invalid webinar date");
|
|
153
157
|
}
|
|
154
|
-
const today = new Intl.DateTimeFormat("sv-SE", {
|
|
158
|
+
const today = new Intl.DateTimeFormat("sv-SE", {
|
|
159
|
+
timeZone: "Europe/Moscow",
|
|
160
|
+
}).format(new Date());
|
|
155
161
|
const key = `v2:${opts?.date ?? `today:${today}`}`;
|
|
156
162
|
const cached = await this.cache?.get("webinars", key);
|
|
157
163
|
if (cached)
|
|
@@ -7,7 +7,11 @@ export function parseNumericGrade(value) {
|
|
|
7
7
|
return Number.isFinite(grade) ? grade : null;
|
|
8
8
|
}
|
|
9
9
|
export function parseGradeValue(value) {
|
|
10
|
-
const normalized = value
|
|
10
|
+
const normalized = value
|
|
11
|
+
.trim()
|
|
12
|
+
.toLocaleLowerCase("ru-RU")
|
|
13
|
+
.replace(/ё/gu, "е")
|
|
14
|
+
.replace(/\s+/gu, " ");
|
|
11
15
|
if (normalized === "зачтено")
|
|
12
16
|
return true;
|
|
13
17
|
if (normalized === "не зачтено")
|
|
@@ -17,7 +17,10 @@ export function displayedText(element) {
|
|
|
17
17
|
node.remove();
|
|
18
18
|
for (const br of clone.querySelectorAll("br"))
|
|
19
19
|
br.replaceWith("\n");
|
|
20
|
-
return text(clone)
|
|
20
|
+
return text(clone)
|
|
21
|
+
.replace(/[^\S\n]+/gu, " ")
|
|
22
|
+
.replace(/ *\n */gu, "\n")
|
|
23
|
+
.trim();
|
|
21
24
|
}
|
|
22
25
|
export function portfolioLinks(element, base) {
|
|
23
26
|
return [...element.querySelectorAll("a[href]")].flatMap((anchor) => {
|
|
@@ -25,13 +28,25 @@ export function portfolioLinks(element, base) {
|
|
|
25
28
|
if (raw?.startsWith("#"))
|
|
26
29
|
return [];
|
|
27
30
|
const url = resolvePortfolioUrl(raw, base);
|
|
28
|
-
return url
|
|
31
|
+
return url
|
|
32
|
+
? [
|
|
33
|
+
{
|
|
34
|
+
text: displayedText(anchor),
|
|
35
|
+
url,
|
|
36
|
+
title: anchor.getAttribute("title") ?? undefined,
|
|
37
|
+
content: parsePortfolioContent(anchor, base),
|
|
38
|
+
},
|
|
39
|
+
]
|
|
40
|
+
: [];
|
|
29
41
|
});
|
|
30
42
|
}
|
|
31
43
|
export function portfolioNotes(element) {
|
|
32
|
-
return [
|
|
44
|
+
return [
|
|
45
|
+
...new Set([element, ...element.querySelectorAll("[title]")]
|
|
33
46
|
.filter((node) => !node.matches("button,input,select,textarea"))
|
|
34
|
-
.map((node) => node.getAttribute("title")?.trim())
|
|
47
|
+
.map((node) => node.getAttribute("title")?.trim())
|
|
48
|
+
.filter((value) => !!value)),
|
|
49
|
+
];
|
|
35
50
|
}
|
|
36
51
|
function span(element, name) {
|
|
37
52
|
const value = Number(element.getAttribute(name) ?? 1);
|
|
@@ -39,24 +54,31 @@ function span(element, name) {
|
|
|
39
54
|
}
|
|
40
55
|
export function parsePortfolioTable(table, base) {
|
|
41
56
|
const rows = [...table.querySelectorAll("tr")].filter((row) => row.closest("table") === table);
|
|
42
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
rows: rows.map((row) => [...row.children]
|
|
59
|
+
.filter((cell) => cell.matches("td,th"))
|
|
43
60
|
.map((cell) => ({
|
|
44
|
-
text: displayedText(cell),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
text: displayedText(cell),
|
|
62
|
+
header: cell.tagName === "TH",
|
|
63
|
+
colspan: span(cell, "colspan"),
|
|
64
|
+
rowspan: span(cell, "rowspan"),
|
|
65
|
+
links: portfolioLinks(cell, base),
|
|
66
|
+
notes: portfolioNotes(cell),
|
|
67
|
+
content: parsePortfolioContent(cell, base),
|
|
68
|
+
}))),
|
|
69
|
+
};
|
|
48
70
|
}
|
|
49
71
|
/** Expand both spans so month/day/slot headers align with attendance cells. */
|
|
50
72
|
export function expandPortfolioRows(rows) {
|
|
51
73
|
const grid = [];
|
|
52
74
|
rows.forEach((row, rowIndex) => {
|
|
53
|
-
const target = grid[rowIndex] ??= [];
|
|
75
|
+
const target = (grid[rowIndex] ??= []);
|
|
54
76
|
let column = 0;
|
|
55
77
|
for (const cell of row) {
|
|
56
78
|
while (target[column])
|
|
57
79
|
column++;
|
|
58
80
|
for (let r = 0; r < cell.rowspan; r++) {
|
|
59
|
-
const output = grid[rowIndex + r] ??= [];
|
|
81
|
+
const output = (grid[rowIndex + r] ??= []);
|
|
60
82
|
for (let c = 0; c < cell.colspan; c++)
|
|
61
83
|
output[column + c] = cell;
|
|
62
84
|
}
|
|
@@ -81,24 +103,44 @@ export function parsePortfolioContent(parent, base) {
|
|
|
81
103
|
continue;
|
|
82
104
|
const tag = element.tagName.toLowerCase();
|
|
83
105
|
if (/^h[1-6]$/u.test(tag)) {
|
|
84
|
-
result.push({
|
|
106
|
+
result.push({
|
|
107
|
+
kind: "heading",
|
|
108
|
+
level: Number(tag[1]),
|
|
109
|
+
text: displayedText(element),
|
|
110
|
+
});
|
|
85
111
|
}
|
|
86
112
|
else if (tag === "table") {
|
|
87
113
|
result.push({ kind: "table", table: parsePortfolioTable(element, base) });
|
|
88
114
|
}
|
|
89
115
|
else if (tag === "a" || tag === "button") {
|
|
90
|
-
const raw = tag === "a"
|
|
91
|
-
element.getAttribute("
|
|
116
|
+
const raw = tag === "a"
|
|
117
|
+
? element.getAttribute("href")
|
|
118
|
+
: element
|
|
119
|
+
.getAttribute("onclick")
|
|
120
|
+
?.match(/^\s*window\.open\(\s*['"]([^'"]+)['"]\s*\);?\s*$/u)?.[1];
|
|
92
121
|
if (!raw || raw.startsWith("#"))
|
|
93
122
|
continue;
|
|
94
123
|
const url = resolvePortfolioUrl(raw, base);
|
|
95
124
|
if (url)
|
|
96
|
-
result.push({
|
|
125
|
+
result.push({
|
|
126
|
+
kind: "link",
|
|
127
|
+
link: {
|
|
128
|
+
text: displayedText(element),
|
|
129
|
+
url,
|
|
130
|
+
title: element.getAttribute("title") ?? undefined,
|
|
131
|
+
content: parsePortfolioContent(element, base),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
97
134
|
}
|
|
98
135
|
else if (tag === "img") {
|
|
99
136
|
const url = resolvePortfolioUrl(element.getAttribute("src"), base);
|
|
100
137
|
if (url)
|
|
101
|
-
result.push({
|
|
138
|
+
result.push({
|
|
139
|
+
kind: "image",
|
|
140
|
+
url,
|
|
141
|
+
alt: element.getAttribute("alt") ?? "",
|
|
142
|
+
title: element.getAttribute("title") ?? undefined,
|
|
143
|
+
});
|
|
102
144
|
}
|
|
103
145
|
else {
|
|
104
146
|
// Tab labels are retained as group labels rather than duplicate fragment links.
|
|
@@ -3,12 +3,20 @@ import { displayedText, portfolioNotes } from "./portfolio-content.js";
|
|
|
3
3
|
import { parseLessonType } from "../../common/lesson-type.js";
|
|
4
4
|
import { parseGradeValue, parseNumericGrade } from "./grade-value.js";
|
|
5
5
|
function referral(row) {
|
|
6
|
-
const onclick = row
|
|
6
|
+
const onclick = row
|
|
7
|
+
.querySelector('[onclick*="iexlist"]')
|
|
8
|
+
?.getAttribute("onclick");
|
|
7
9
|
const match = onclick?.match(/iexlist\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*['"]([^'"]*)['"]\s*\)/u);
|
|
8
|
-
return match
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
return match
|
|
11
|
+
? {
|
|
12
|
+
semester: Number(match[1]),
|
|
13
|
+
disciplineId: Number(match[2]),
|
|
14
|
+
lessonTypeId: Number(match[3]),
|
|
15
|
+
type: Number(match[4]),
|
|
16
|
+
key: Number(match[5]),
|
|
17
|
+
code: match[6],
|
|
18
|
+
}
|
|
19
|
+
: undefined;
|
|
12
20
|
}
|
|
13
21
|
/** Accordion sections are headed with Семестр N; IDs are randomly generated. */
|
|
14
22
|
export function semesterBlocks(panel) {
|
|
@@ -26,9 +34,21 @@ export function parsePortfolioGrades(panel) {
|
|
|
26
34
|
const code = text(cells[0].querySelector(".red"));
|
|
27
35
|
const raw = displayedText(cells[0]);
|
|
28
36
|
const assessment = parseLessonType(raw.match(/\(([^()]*)\)\s*$/u)?.[1] ?? "");
|
|
29
|
-
const subject = raw
|
|
30
|
-
.
|
|
31
|
-
|
|
37
|
+
const subject = raw
|
|
38
|
+
.slice(code && raw.startsWith(code) ? code.length : 0)
|
|
39
|
+
.replace(/\s*\([^()]*\)\s*$/u, "")
|
|
40
|
+
.trim();
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
semester,
|
|
44
|
+
code,
|
|
45
|
+
subject,
|
|
46
|
+
assessment,
|
|
47
|
+
grade: parseGradeValue(displayedText(cells[2])),
|
|
48
|
+
notes: portfolioNotes(cells[2]),
|
|
49
|
+
referral: referral(row),
|
|
50
|
+
},
|
|
51
|
+
];
|
|
32
52
|
}));
|
|
33
53
|
}
|
|
34
54
|
export function parsePortfolioControlWeeks(panel) {
|
|
@@ -36,6 +56,14 @@ export function parsePortfolioControlWeeks(panel) {
|
|
|
36
56
|
const cells = [...row.children];
|
|
37
57
|
if (!cells.length || cells.some((cell) => cell.tagName === "TH"))
|
|
38
58
|
return [];
|
|
39
|
-
return [
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
semester,
|
|
62
|
+
subject: displayedText(cells[0]),
|
|
63
|
+
grades: cells
|
|
64
|
+
.slice(1)
|
|
65
|
+
.map((cell) => parseNumericGrade(displayedText(cell))),
|
|
66
|
+
},
|
|
67
|
+
];
|
|
40
68
|
}));
|
|
41
69
|
}
|
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
import { text } from "../../common/parse.js";
|
|
2
|
-
import { expandPortfolioRows, parsePortfolioTable } from "./portfolio-content.js";
|
|
2
|
+
import { expandPortfolioRows, parsePortfolioTable, } from "./portfolio-content.js";
|
|
3
3
|
import { parseLessonType } from "../../common/lesson-type.js";
|
|
4
4
|
export function parsePortfolioPerformance(panel, base) {
|
|
5
5
|
return [...panel.querySelectorAll("h3")].flatMap((heading) => {
|
|
6
6
|
const body = heading.nextElementSibling;
|
|
7
7
|
if (!body?.querySelector("table.journtable"))
|
|
8
8
|
return [];
|
|
9
|
-
const performance = {
|
|
9
|
+
const performance = {
|
|
10
|
+
subject: text(heading),
|
|
11
|
+
attendance: [],
|
|
12
|
+
activities: [],
|
|
13
|
+
};
|
|
10
14
|
for (const table of body.querySelectorAll("table.journtable")) {
|
|
11
15
|
const parsed = parsePortfolioTable(table, base);
|
|
12
16
|
const headerCount = [...table.querySelectorAll("thead > tr")].length;
|
|
13
17
|
const headers = expandPortfolioRows(parsed.rows.slice(0, headerCount));
|
|
14
|
-
const values = parsed.rows
|
|
15
|
-
|
|
18
|
+
const values = parsed.rows
|
|
19
|
+
.slice(headerCount)
|
|
20
|
+
.filter((row) => row.some((cell) => !cell.header));
|
|
21
|
+
if (/Пропуски занятий/iu.test(headers[0]?.[0]?.text ?? "") &&
|
|
22
|
+
headers.length >= 5) {
|
|
16
23
|
for (const row of values) {
|
|
17
24
|
row.forEach((cell, index) => {
|
|
18
25
|
const day = Number(headers[2]?.[index]?.text);
|
|
19
26
|
const slotNumber = Number(headers[3]?.[index]?.text);
|
|
20
|
-
if (!Number.isInteger(day) ||
|
|
27
|
+
if (!Number.isInteger(day) ||
|
|
28
|
+
day < 1 ||
|
|
29
|
+
day > 31 ||
|
|
30
|
+
!Number.isInteger(slotNumber) ||
|
|
31
|
+
slotNumber < 1)
|
|
21
32
|
return;
|
|
22
33
|
const typeRaw = headers[4]?.[index]?.text ?? "";
|
|
23
34
|
const subgroup = typeRaw.match(/\((\d+)\)/u)?.[1];
|
|
24
35
|
performance.attendance.push({
|
|
25
|
-
month: headers[1]?.[index]?.text ?? "",
|
|
36
|
+
month: headers[1]?.[index]?.text ?? "",
|
|
37
|
+
day,
|
|
38
|
+
slotNumber,
|
|
26
39
|
type: parseLessonType(typeRaw.replace(/\s*\(\d+\)/u, "")),
|
|
27
40
|
subgroup: subgroup ? Number(subgroup) : undefined,
|
|
28
|
-
mark: cell.text,
|
|
41
|
+
mark: cell.text,
|
|
42
|
+
notes: cell.notes,
|
|
29
43
|
});
|
|
30
44
|
});
|
|
31
45
|
}
|
|
@@ -34,7 +48,11 @@ export function parsePortfolioPerformance(panel, base) {
|
|
|
34
48
|
performance.activities.push({
|
|
35
49
|
teacher: headers[1]?.[0]?.text ?? "",
|
|
36
50
|
items: values.flatMap((row) => row.map((cell, index) => ({
|
|
37
|
-
title: headers.at(-1)?.[index]?.text ?? "",
|
|
51
|
+
title: headers.at(-1)?.[index]?.text ?? "",
|
|
52
|
+
value: cell.text,
|
|
53
|
+
notes: cell.notes,
|
|
54
|
+
links: cell.links,
|
|
55
|
+
content: cell.content,
|
|
38
56
|
}))),
|
|
39
57
|
});
|
|
40
58
|
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { parseHtml, text } from "../../common/parse.js";
|
|
2
2
|
import { ParseError } from "../../common/types.js";
|
|
3
|
-
import { displayedText, parsePortfolioContent, resolvePortfolioUrl } from "./portfolio-content.js";
|
|
4
|
-
import { parsePortfolioControlWeeks, parsePortfolioGrades } from "./portfolio-grades.js";
|
|
3
|
+
import { displayedText, parsePortfolioContent, resolvePortfolioUrl, } from "./portfolio-content.js";
|
|
4
|
+
import { parsePortfolioControlWeeks, parsePortfolioGrades, } from "./portfolio-grades.js";
|
|
5
5
|
import { parsePortfolioPerformance } from "./portfolio-performance.js";
|
|
6
6
|
const BASE = "https://lk.chuvsu.ru";
|
|
7
7
|
/** Only the portfolio landing route or index.php?id=N can be discovered. */
|
|
8
8
|
export function parsePortfolioUrl(html) {
|
|
9
9
|
const doc = parseHtml(html);
|
|
10
10
|
for (const element of doc.querySelectorAll("a[href],button[onclick]")) {
|
|
11
|
-
const raw = element.getAttribute("href") ??
|
|
12
|
-
|
|
11
|
+
const raw = element.getAttribute("href") ??
|
|
12
|
+
element
|
|
13
|
+
.getAttribute("onclick")
|
|
14
|
+
?.match(/window\.open\(\s*['"]([^'"]+)['"]/u)?.[1];
|
|
13
15
|
const value = resolvePortfolioUrl(raw ?? null, `${BASE}/student/`);
|
|
14
16
|
if (!value)
|
|
15
17
|
continue;
|
|
16
18
|
const url = new URL(value);
|
|
17
|
-
if (url.origin !== BASE ||
|
|
19
|
+
if (url.origin !== BASE ||
|
|
20
|
+
!["/portfolio", "/portfolio/", "/portfolio/index.php"].includes(url.pathname))
|
|
18
21
|
continue;
|
|
19
22
|
if ([...url.searchParams.keys()].some((key) => key !== "id"))
|
|
20
23
|
continue;
|
|
@@ -30,12 +33,16 @@ export function parsePortfolio(html, opts) {
|
|
|
30
33
|
const fullName = text(doc.querySelector(".port_name"));
|
|
31
34
|
if (!fullName)
|
|
32
35
|
throw new ParseError("LK portfolio response has no student identity");
|
|
33
|
-
const photo = doc.querySelector(
|
|
36
|
+
const photo = doc.querySelector(".port_pic[src]");
|
|
34
37
|
const photoUrl = resolvePortfolioUrl(photo?.getAttribute("src") ?? null, `${BASE}/portfolio/`);
|
|
35
38
|
const photoId = photoUrl ? new URL(photoUrl).searchParams.get("id") : null;
|
|
36
|
-
const requestedId = opts?.url
|
|
39
|
+
const requestedId = opts?.url
|
|
40
|
+
? new URL(opts.url).searchParams.get("id")
|
|
41
|
+
: null;
|
|
37
42
|
const rawId = photoId ?? requestedId;
|
|
38
|
-
if (!rawId ||
|
|
43
|
+
if (!rawId ||
|
|
44
|
+
!/^[1-9]\d*$/u.test(rawId) ||
|
|
45
|
+
!Number.isSafeInteger(Number(rawId))) {
|
|
39
46
|
throw new ParseError("LK portfolio response has no valid student ID");
|
|
40
47
|
}
|
|
41
48
|
if (requestedId && photoId && requestedId !== photoId) {
|
|
@@ -44,7 +51,9 @@ export function parsePortfolio(html, opts) {
|
|
|
44
51
|
const url = `${BASE}/portfolio/index.php?id=${rawId}`;
|
|
45
52
|
const fields = {};
|
|
46
53
|
for (const label of doc.querySelectorAll(".port_param")) {
|
|
47
|
-
fields[text(label).replace(/:\s*$/u, "")] = label.nextElementSibling
|
|
54
|
+
fields[text(label).replace(/:\s*$/u, "")] = label.nextElementSibling
|
|
55
|
+
? displayedText(label.nextElementSibling)
|
|
56
|
+
: "";
|
|
48
57
|
}
|
|
49
58
|
const panels = [...doc.querySelectorAll('[role="tabpanel"]')].filter((panel) => !panel.parentElement?.closest('[role="tabpanel"]'));
|
|
50
59
|
if (!panels.length)
|
|
@@ -55,10 +64,19 @@ export function parsePortfolio(html, opts) {
|
|
|
55
64
|
const controlsPanel = panels.find((panel) => titleFor(panel) === "Контрольные недели");
|
|
56
65
|
const performancePanel = panels.find((panel) => titleFor(panel) === "Текущая успеваемость");
|
|
57
66
|
return {
|
|
58
|
-
id: Number(rawId),
|
|
67
|
+
id: Number(rawId),
|
|
68
|
+
url,
|
|
69
|
+
student: { fullName, photoUrl, fields },
|
|
59
70
|
grades: gradesPanel ? parsePortfolioGrades(gradesPanel) : [],
|
|
60
|
-
controlWeeks: controlsPanel
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
controlWeeks: controlsPanel
|
|
72
|
+
? parsePortfolioControlWeeks(controlsPanel)
|
|
73
|
+
: [],
|
|
74
|
+
performance: performancePanel
|
|
75
|
+
? parsePortfolioPerformance(performancePanel, url)
|
|
76
|
+
: [],
|
|
77
|
+
sections: panels.map((panel) => ({
|
|
78
|
+
title: titleFor(panel),
|
|
79
|
+
content: parsePortfolioContent(panel, url),
|
|
80
|
+
})),
|
|
63
81
|
};
|
|
64
82
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { FLEXIBLE_LESSON_TYPE_RE_I, SUBGROUP_RE } from "../../tt/parse/patterns.js";
|
|
1
|
+
import { FLEXIBLE_LESSON_TYPE_RE_I, SUBGROUP_RE, } from "../../tt/parse/patterns.js";
|
|
2
2
|
const GROUP_CODE_RE = /[A-ZА-ЯЁ]{1,}(?:-[A-ZА-ЯЁa-zа-яё0-9]+)+(?:\s*ин)?/u;
|
|
3
3
|
export function splitWebinarLesson(raw) {
|
|
4
|
-
const typeMatches = [
|
|
4
|
+
const typeMatches = [
|
|
5
|
+
...raw.matchAll(new RegExp(FLEXIBLE_LESSON_TYPE_RE_I, "gi")),
|
|
6
|
+
];
|
|
5
7
|
const typeMatch = typeMatches.at(-1);
|
|
6
8
|
if (!typeMatch || typeMatch.index == null) {
|
|
7
9
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseHtml, parseTeacher, parseTime, text } from "../../common/parse.js";
|
|
1
|
+
import { parseHtml, parseTeacher, parseTime, text, } from "../../common/parse.js";
|
|
2
2
|
import { ParseError } from "../../common/types.js";
|
|
3
3
|
import { isLocalDate } from "../../tt/utils/date.js";
|
|
4
4
|
import { parseLessonType } from "../../common/lesson-type.js";
|
|
@@ -17,7 +17,9 @@ export function parseWebinarPage(html) {
|
|
|
17
17
|
throw new ParseError("LK response has no webinar page");
|
|
18
18
|
}
|
|
19
19
|
const scriptDate = html.match(/\$\(['"]#day['"]\)\.val\(['"]([^'"]+)['"]\)/u)?.[1];
|
|
20
|
-
const date = dateValue(scriptDate) ??
|
|
20
|
+
const date = dateValue(scriptDate) ??
|
|
21
|
+
dateValue(select?.querySelector("option[selected]")?.getAttribute("value")) ??
|
|
22
|
+
dateValue(select?.querySelector("option")?.getAttribute("value"));
|
|
21
23
|
const availableDates = [...(select?.querySelectorAll("option") ?? [])]
|
|
22
24
|
.map((option) => dateValue(option.getAttribute("value")))
|
|
23
25
|
.filter((value) => value !== undefined);
|
|
@@ -36,7 +38,9 @@ export function parseWebinarPage(html) {
|
|
|
36
38
|
const raw = text(cells[3]);
|
|
37
39
|
const lesson = splitWebinarLesson(raw);
|
|
38
40
|
const button = cells[5].querySelector('[onclick*="jointo"]');
|
|
39
|
-
const id = button
|
|
41
|
+
const id = button
|
|
42
|
+
?.getAttribute("onclick")
|
|
43
|
+
?.match(/jointo\(\s*['"]?(\d+)['"]?\s*\)/u)?.[1] ?? null;
|
|
40
44
|
const server = cells[5].cloneNode(true);
|
|
41
45
|
for (const control of server.querySelectorAll("button"))
|
|
42
46
|
control.remove();
|
package/dist/lk/webinars.js
CHANGED
|
@@ -35,7 +35,9 @@ export function findWebinars(lesson, webinars) {
|
|
|
35
35
|
: groups;
|
|
36
36
|
if (groups.length && !attendance.length)
|
|
37
37
|
return false;
|
|
38
|
-
if (webinar.subgroup != null &&
|
|
38
|
+
if (webinar.subgroup != null &&
|
|
39
|
+
attendance.length &&
|
|
40
|
+
!attendance.some((entry) => entry.subgroup == null || entry.subgroup === webinar.subgroup))
|
|
39
41
|
return false;
|
|
40
42
|
return true;
|
|
41
43
|
});
|