chuvsu-js 2.1.0 → 2.1.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.
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tt/client.js +3 -3
- package/dist/tt/parse.d.ts +2 -2
- package/dist/tt/parse.js +6 -5
- package/dist/tt/schedule.d.ts +3 -3
- package/dist/tt/schedule.js +41 -58
- package/dist/tt/utils.d.ts +6 -2
- package/dist/tt/utils.js +47 -0
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Schedule } from "./tt/schedule.js";
|
|
2
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
|
|
2
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
|
|
3
3
|
export { Period, EducationType } from "./common/types.js";
|
|
4
4
|
export type { Time, WeekRange, Teacher, } from "./common/types.js";
|
|
5
5
|
export type { Faculty, Group, ScheduleEntry, FullScheduleSlot, FullScheduleDay, LessonTimeSlot, Lesson, LessonTime, SemesterWeek, } from "./tt/types.js";
|
package/dist/browser.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Schedule } from "./tt/schedule.js";
|
|
2
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
|
|
2
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { LkClient } from "./lk/client.js";
|
|
|
2
2
|
export { TtClient } from "./tt/client.js";
|
|
3
3
|
export { Schedule } from "./tt/schedule.js";
|
|
4
4
|
export type { CacheEntry } from "./common/cache.js";
|
|
5
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
|
|
5
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
|
|
6
6
|
export { Period, EducationType, AuthError, ParseError } from "./common/types.js";
|
|
7
7
|
export type { Time, WeekRange, Teacher, } from "./common/types.js";
|
|
8
8
|
export type { PersonalData, } from "./lk/types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { LkClient } from "./lk/client.js";
|
|
2
2
|
export { TtClient } from "./tt/client.js";
|
|
3
3
|
export { Schedule } from "./tt/schedule.js";
|
|
4
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, } from "./tt/utils.js";
|
|
4
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, } from "./tt/utils.js";
|
|
5
5
|
export { AuthError, ParseError } from "./common/types.js";
|
package/dist/tt/client.js
CHANGED
|
@@ -104,7 +104,7 @@ export class TtClient {
|
|
|
104
104
|
return cached;
|
|
105
105
|
const url = `${BASE}/index/grouptt/gr/${groupId}`;
|
|
106
106
|
const { body } = await this.authPost(url, { htype: String(period) });
|
|
107
|
-
const days = parseFullSchedule(body);
|
|
107
|
+
const days = parseFullSchedule(body, this.educationType);
|
|
108
108
|
this.cache?.set("schedule", cacheKey, days);
|
|
109
109
|
return days;
|
|
110
110
|
}
|
|
@@ -121,7 +121,7 @@ export class TtClient {
|
|
|
121
121
|
for (const { period, days } of results) {
|
|
122
122
|
schedules.set(period, days);
|
|
123
123
|
}
|
|
124
|
-
return new Schedule(groupId, schedules);
|
|
124
|
+
return new Schedule(groupId, schedules, undefined, this.educationType);
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* Get schedule for a specific period only.
|
|
@@ -130,7 +130,7 @@ export class TtClient {
|
|
|
130
130
|
const days = await this.fetchSchedule(opts.groupId, opts.period);
|
|
131
131
|
const schedules = new Map();
|
|
132
132
|
schedules.set(opts.period, days);
|
|
133
|
-
return new Schedule(opts.groupId, schedules, opts.period);
|
|
133
|
+
return new Schedule(opts.groupId, schedules, opts.period, this.educationType);
|
|
134
134
|
}
|
|
135
135
|
// --- Search / Discovery ---
|
|
136
136
|
async getFaculties() {
|
package/dist/tt/parse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Period, EducationType } from "../common/types.js";
|
|
2
2
|
import type { Faculty, Group, FullScheduleDay } from "./types.js";
|
|
3
3
|
export declare function parsePeriodFromPage(html: string): Period | null;
|
|
4
4
|
export declare function parseGroupButtons(html: string): Group[];
|
|
@@ -7,4 +7,4 @@ export declare function parseTeacherButtons(html: string): {
|
|
|
7
7
|
id: number;
|
|
8
8
|
name: string;
|
|
9
9
|
}[];
|
|
10
|
-
export declare function parseFullSchedule(html: string): FullScheduleDay[];
|
|
10
|
+
export declare function parseFullSchedule(html: string, educationType?: EducationType): FullScheduleDay[];
|
package/dist/tt/parse.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseHtml, text, parseTime, parseWeeks, parseTeacher, parseWeekParity, } from "../common/parse.js";
|
|
2
|
+
import { getLessonNumber } from "./utils.js";
|
|
2
3
|
const PERIOD_LABELS = {
|
|
3
4
|
"осенний семестр": 1,
|
|
4
5
|
"зимняя сессия": 2,
|
|
@@ -54,11 +55,12 @@ export function parseTeacherButtons(html) {
|
|
|
54
55
|
}
|
|
55
56
|
return results;
|
|
56
57
|
}
|
|
57
|
-
export function parseFullSchedule(html) {
|
|
58
|
+
export function parseFullSchedule(html, educationType) {
|
|
58
59
|
const doc = parseHtml(html);
|
|
60
|
+
const edType = educationType ?? 1 /* EducationType.HigherEducation */;
|
|
59
61
|
// Session layout has date-based cells with ids like "trd20251224"
|
|
60
62
|
if (doc.querySelector('td[id^="trd2"]')) {
|
|
61
|
-
return parseSessionSchedule(doc);
|
|
63
|
+
return parseSessionSchedule(doc, edType);
|
|
62
64
|
}
|
|
63
65
|
return parseSemesterSchedule(doc);
|
|
64
66
|
}
|
|
@@ -134,7 +136,7 @@ function parseSemesterEntry(el) {
|
|
|
134
136
|
};
|
|
135
137
|
}
|
|
136
138
|
// --- Session schedule parsing (date-based, specific dates) ---
|
|
137
|
-
function parseSessionSchedule(doc) {
|
|
139
|
+
function parseSessionSchedule(doc, educationType) {
|
|
138
140
|
const days = [];
|
|
139
141
|
for (const dateCell of doc.querySelectorAll('td[id^="trd2"]')) {
|
|
140
142
|
// Parse date from cell id: trd20251224 -> 2025-12-24
|
|
@@ -159,14 +161,13 @@ function parseSessionSchedule(doc) {
|
|
|
159
161
|
continue;
|
|
160
162
|
// Parse entries
|
|
161
163
|
const slots = [];
|
|
162
|
-
let slotNumber = 1;
|
|
163
164
|
for (const entryRow of dataCell.querySelectorAll("table tr")) {
|
|
164
165
|
const td = entryRow.querySelector("td") ?? entryRow;
|
|
165
166
|
const entry = parseSessionEntry(td);
|
|
166
167
|
if (!entry)
|
|
167
168
|
continue;
|
|
168
169
|
slots.push({
|
|
169
|
-
number:
|
|
170
|
+
number: getLessonNumber(entry.timeStart, educationType),
|
|
170
171
|
timeStart: entry.timeStart,
|
|
171
172
|
timeEnd: entry.timeEnd,
|
|
172
173
|
entries: [entry.entry],
|
package/dist/tt/schedule.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { FullScheduleDay, SemesterWeek, Lesson } from "./types.js";
|
|
2
|
-
import { Period } from "../common/types.js";
|
|
2
|
+
import { Period, EducationType } from "../common/types.js";
|
|
3
3
|
export declare class Schedule {
|
|
4
4
|
readonly groupId: number;
|
|
5
5
|
readonly scheduleMap: Map<number, FullScheduleDay[]>;
|
|
6
|
+
readonly educationType: EducationType;
|
|
6
7
|
private _period?;
|
|
7
|
-
constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period);
|
|
8
|
+
constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period, educationType?: EducationType);
|
|
8
9
|
/** Current (or fixed) period for this schedule. */
|
|
9
10
|
get period(): Period;
|
|
10
11
|
/** Days for the current period. */
|
|
@@ -16,7 +17,6 @@ export declare class Schedule {
|
|
|
16
17
|
private getSlotsForWeekday;
|
|
17
18
|
private getDateForWeekday;
|
|
18
19
|
private static isSameDay;
|
|
19
|
-
private getSessionLessonsForDate;
|
|
20
20
|
forDay(weekday: number, opts?: {
|
|
21
21
|
subgroup?: number;
|
|
22
22
|
week?: number;
|
package/dist/tt/schedule.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { getCurrentPeriod, isSessionPeriod, getWeekdayName, getMonday, getSemesterStart, getSemesterWeeks, getWeekNumber, filterSlots, slotsToLessons, } from "./utils.js";
|
|
1
|
+
import { getCurrentPeriod, isSessionPeriod, getWeekdayName, getMonday, getSemesterStart, getSemesterWeeks, getWeekNumber, getAdjacentSemester, filterSlots, slotsToLessons, } from "./utils.js";
|
|
2
2
|
export class Schedule {
|
|
3
3
|
groupId;
|
|
4
4
|
scheduleMap;
|
|
5
|
+
educationType;
|
|
5
6
|
_period;
|
|
6
|
-
constructor(groupId, scheduleMap, period) {
|
|
7
|
+
constructor(groupId, scheduleMap, period, educationType) {
|
|
7
8
|
this.groupId = groupId;
|
|
8
9
|
this.scheduleMap = scheduleMap;
|
|
10
|
+
this.educationType = educationType ?? 1 /* EducationType.HigherEducation */;
|
|
9
11
|
this._period = period;
|
|
10
12
|
}
|
|
11
13
|
/** Current (or fixed) period for this schedule. */
|
|
@@ -55,12 +57,6 @@ export class Schedule {
|
|
|
55
57
|
a.getMonth() === b.getMonth() &&
|
|
56
58
|
a.getDate() === b.getDate());
|
|
57
59
|
}
|
|
58
|
-
getSessionLessonsForDate(days, date) {
|
|
59
|
-
const day = days.find((d) => d.date && Schedule.isSameDay(d.date, date));
|
|
60
|
-
if (!day)
|
|
61
|
-
return [];
|
|
62
|
-
return slotsToLessons(day.slots, date);
|
|
63
|
-
}
|
|
64
60
|
// --- Public query methods ---
|
|
65
61
|
forDay(weekday, opts) {
|
|
66
62
|
const period = this.period;
|
|
@@ -82,67 +78,54 @@ export class Schedule {
|
|
|
82
78
|
}
|
|
83
79
|
forDate(date, opts) {
|
|
84
80
|
const period = getCurrentPeriod({ date });
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
const lessons = [];
|
|
82
|
+
// 1. Check all periods for date-based (session) entries matching this date
|
|
83
|
+
for (const [, d] of this.scheduleMap) {
|
|
84
|
+
for (const day of d) {
|
|
85
|
+
if (day.date && Schedule.isSameDay(day.date, date)) {
|
|
86
|
+
lessons.push(...slotsToLessons(day.slots, date));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
90
89
|
}
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
// 2. Check applicable semester for weekday-based entries
|
|
91
|
+
const semesterPeriod = isSessionPeriod(period)
|
|
92
|
+
? getAdjacentSemester(period)
|
|
93
|
+
: period;
|
|
94
|
+
const semesterDays = this.getDays(semesterPeriod);
|
|
95
|
+
if (semesterDays.length > 0) {
|
|
96
|
+
const week = getWeekNumber({ period: semesterPeriod, date });
|
|
97
|
+
if (week >= 0 && week <= 17) {
|
|
98
|
+
const weekday = date.getDay();
|
|
99
|
+
const slots = this.getSlotsForWeekday(weekday, semesterDays, {
|
|
100
|
+
subgroup: opts?.subgroup,
|
|
101
|
+
week,
|
|
102
|
+
});
|
|
103
|
+
lessons.push(...slotsToLessons(slots, date));
|
|
104
|
+
}
|
|
99
105
|
}
|
|
100
|
-
|
|
101
|
-
return [];
|
|
102
|
-
const weekday = date.getDay();
|
|
103
|
-
const week = getWeekNumber({ period, date });
|
|
104
|
-
const slots = this.getSlotsForWeekday(weekday, days, {
|
|
105
|
-
subgroup: opts?.subgroup,
|
|
106
|
-
week,
|
|
107
|
-
});
|
|
108
|
-
return slotsToLessons(slots, date);
|
|
106
|
+
return lessons;
|
|
109
107
|
}
|
|
110
108
|
forWeek(week, opts) {
|
|
111
109
|
const period = this.period;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return lessons;
|
|
110
|
+
// Determine the Monday of the target week
|
|
111
|
+
let mondayDate;
|
|
112
|
+
if (week != null && !isSessionPeriod(period)) {
|
|
113
|
+
const semesterWeeks = getSemesterWeeks({
|
|
114
|
+
period,
|
|
115
|
+
weekCount: week,
|
|
116
|
+
});
|
|
117
|
+
const weekData = semesterWeeks.find((w) => w.week === week);
|
|
118
|
+
mondayDate = weekData ? weekData.start : getMonday(new Date());
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
mondayDate = getMonday(new Date());
|
|
127
122
|
}
|
|
128
|
-
const effectiveWeek = week ?? getWeekNumber({ period });
|
|
129
|
-
const semesterWeeks = getSemesterWeeks({
|
|
130
|
-
period,
|
|
131
|
-
weekCount: effectiveWeek,
|
|
132
|
-
});
|
|
133
|
-
const weekData = semesterWeeks.find((w) => w.week === effectiveWeek);
|
|
134
|
-
const mondayDate = weekData ? weekData.start : new Date();
|
|
135
123
|
const lessons = [];
|
|
136
124
|
for (let i = 0; i < 7; i++) {
|
|
137
125
|
const date = new Date(mondayDate);
|
|
138
126
|
date.setDate(mondayDate.getDate() + i);
|
|
139
127
|
date.setHours(0, 0, 0, 0);
|
|
140
|
-
|
|
141
|
-
const slots = this.getSlotsForWeekday(weekday, days, {
|
|
142
|
-
subgroup: opts?.subgroup,
|
|
143
|
-
week: effectiveWeek,
|
|
144
|
-
});
|
|
145
|
-
lessons.push(...slotsToLessons(slots, date));
|
|
128
|
+
lessons.push(...this.forDate(date, opts));
|
|
146
129
|
}
|
|
147
130
|
return lessons;
|
|
148
131
|
}
|
package/dist/tt/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { FullScheduleSlot, SemesterWeek, Lesson } from "./types.js";
|
|
2
|
-
import { Period } from "../common/types.js";
|
|
1
|
+
import type { FullScheduleSlot, SemesterWeek, Lesson, LessonTimeSlot } from "./types.js";
|
|
2
|
+
import { Period, EducationType } from "../common/types.js";
|
|
3
|
+
import type { Time } from "../common/types.js";
|
|
3
4
|
export declare function getCurrentPeriod(opts?: {
|
|
4
5
|
date?: Date;
|
|
5
6
|
}): Period;
|
|
@@ -36,3 +37,6 @@ export declare function filterSlots(slots: FullScheduleSlot[], opts?: {
|
|
|
36
37
|
week?: number;
|
|
37
38
|
}): FullScheduleSlot[];
|
|
38
39
|
export declare function slotsToLessons(slots: FullScheduleSlot[], date: Date): Lesson[];
|
|
40
|
+
export declare function getTimeSlots(educationType: EducationType): LessonTimeSlot[];
|
|
41
|
+
export declare function getLessonNumber(time: Time, educationType: EducationType): number;
|
|
42
|
+
export declare function getAdjacentSemester(session: Period): Period;
|
package/dist/tt/utils.js
CHANGED
|
@@ -141,3 +141,50 @@ export function slotsToLessons(slots, date) {
|
|
|
141
141
|
}
|
|
142
142
|
return lessons;
|
|
143
143
|
}
|
|
144
|
+
// --- Lesson time slots ---
|
|
145
|
+
const VO_TIME_SLOTS = [
|
|
146
|
+
{ number: 1, start: { hours: 8, minutes: 20 }, end: { hours: 9, minutes: 40 } },
|
|
147
|
+
{ number: 2, start: { hours: 9, minutes: 50 }, end: { hours: 11, minutes: 10 } },
|
|
148
|
+
{ number: 3, start: { hours: 11, minutes: 40 }, end: { hours: 13, minutes: 0 } },
|
|
149
|
+
{ number: 4, start: { hours: 13, minutes: 30 }, end: { hours: 14, minutes: 50 } },
|
|
150
|
+
{ number: 5, start: { hours: 15, minutes: 0 }, end: { hours: 16, minutes: 20 } },
|
|
151
|
+
{ number: 6, start: { hours: 16, minutes: 40 }, end: { hours: 18, minutes: 0 } },
|
|
152
|
+
{ number: 7, start: { hours: 18, minutes: 10 }, end: { hours: 19, minutes: 30 } },
|
|
153
|
+
{ number: 8, start: { hours: 19, minutes: 40 }, end: { hours: 21, minutes: 0 } },
|
|
154
|
+
];
|
|
155
|
+
const SPO_TIME_SLOTS = [
|
|
156
|
+
{ number: 1, start: { hours: 8, minutes: 10 }, end: { hours: 9, minutes: 40 } },
|
|
157
|
+
{ number: 2, start: { hours: 9, minutes: 55 }, end: { hours: 11, minutes: 25 } },
|
|
158
|
+
{ number: 3, start: { hours: 11, minutes: 55 }, end: { hours: 13, minutes: 25 } },
|
|
159
|
+
{ number: 4, start: { hours: 13, minutes: 40 }, end: { hours: 15, minutes: 10 } },
|
|
160
|
+
{ number: 5, start: { hours: 15, minutes: 25 }, end: { hours: 16, minutes: 55 } },
|
|
161
|
+
{ number: 6, start: { hours: 17, minutes: 10 }, end: { hours: 18, minutes: 40 } },
|
|
162
|
+
{ number: 7, start: { hours: 18, minutes: 55 }, end: { hours: 20, minutes: 25 } },
|
|
163
|
+
];
|
|
164
|
+
export function getTimeSlots(educationType) {
|
|
165
|
+
return educationType === 2 /* EducationType.VocationalEducation */
|
|
166
|
+
? SPO_TIME_SLOTS
|
|
167
|
+
: VO_TIME_SLOTS;
|
|
168
|
+
}
|
|
169
|
+
function timeToMinutes(t) {
|
|
170
|
+
return t.hours * 60 + t.minutes;
|
|
171
|
+
}
|
|
172
|
+
export function getLessonNumber(time, educationType) {
|
|
173
|
+
const slots = getTimeSlots(educationType);
|
|
174
|
+
const target = timeToMinutes(time);
|
|
175
|
+
let closest = slots[0];
|
|
176
|
+
let minDiff = Math.abs(timeToMinutes(closest.start) - target);
|
|
177
|
+
for (let i = 1; i < slots.length; i++) {
|
|
178
|
+
const diff = Math.abs(timeToMinutes(slots[i].start) - target);
|
|
179
|
+
if (diff < minDiff) {
|
|
180
|
+
minDiff = diff;
|
|
181
|
+
closest = slots[i];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return closest.number;
|
|
185
|
+
}
|
|
186
|
+
export function getAdjacentSemester(session) {
|
|
187
|
+
return session === 2 /* Period.WinterSession */
|
|
188
|
+
? 1 /* Period.FallSemester */
|
|
189
|
+
: 3 /* Period.SpringSemester */;
|
|
190
|
+
}
|