mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
Исправление краша при обновлении расписания.
Исправление отсутствия субботы из-за изменившегося формата расписания.
This commit is contained in:
@@ -42,21 +42,10 @@ describe("V2ScheduleParser", () => {
|
||||
expect(name.length).toBeGreaterThan(0);
|
||||
};
|
||||
|
||||
describe("Старое расписание", () => {
|
||||
describe("Расписание", () => {
|
||||
beforeEach(async () => {
|
||||
await setLink(
|
||||
"https://politehnikum-eng.ru/2024/poltavskaja_06_s_07_po_13_10.xls",
|
||||
);
|
||||
});
|
||||
|
||||
it("Должен вернуть расписание", defaultTest);
|
||||
it("Название дня не должно быть пустым или null", nameTest);
|
||||
});
|
||||
|
||||
describe("Новое расписание", () => {
|
||||
beforeEach(async () => {
|
||||
await setLink(
|
||||
"https://politehnikum-eng.ru/2024/poltavskaja_07_s_14_po_20_10-8-1-.xls",
|
||||
"https://politehnikum-eng.ru/2024/poltavskaja_11_s_11_11_po_17_11-5-.xls",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -112,5 +101,15 @@ describe("V2ScheduleParser", () => {
|
||||
"МДК.05.01 Проектирование и дизайн информационных систем",
|
||||
);
|
||||
});
|
||||
|
||||
it("Суббота не должна отсутствовать", async () => {
|
||||
const schedule = await parser.getSchedule();
|
||||
expect(schedule).toBeDefined();
|
||||
|
||||
const group: V2GroupDto | undefined = schedule.groups["ИС-214/23"];
|
||||
expect(group).toBeDefined();
|
||||
|
||||
expect(group.days.length).toBe(6);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -303,16 +303,11 @@ export class V2ScheduleParser {
|
||||
++row;
|
||||
}
|
||||
|
||||
if (
|
||||
days.length == 0 ||
|
||||
!days[days.length - 1].name.startsWith("Суббота")
|
||||
) {
|
||||
const dayMonthIdx = /[А-Яа-я]+\s(\d+)\.\d+\.\d+/.exec(
|
||||
trimAll(dayName),
|
||||
);
|
||||
|
||||
if (dayMonthIdx === null) continue;
|
||||
}
|
||||
|
||||
days.push({
|
||||
row: row,
|
||||
@@ -320,11 +315,7 @@ export class V2ScheduleParser {
|
||||
name: dayName,
|
||||
});
|
||||
|
||||
if (
|
||||
days.length > 2 &&
|
||||
days[days.length - 2].name.startsWith("Суббота")
|
||||
)
|
||||
break;
|
||||
if (days.length > 2 && dayName.startsWith("Суббота")) break;
|
||||
}
|
||||
|
||||
return { daySkeletons: days, groupSkeletons: groups };
|
||||
@@ -452,12 +443,15 @@ export class V2ScheduleParser {
|
||||
const daysTimes: Array<Array<InternalTime>> = [];
|
||||
let daysTimesFilled = false;
|
||||
|
||||
const saturdayEndRow = XLSX.utils.decode_range(workSheet["!ref"] || "")
|
||||
.e.r;
|
||||
|
||||
for (const groupSkeleton of groupSkeletons) {
|
||||
const group = new V2GroupDto();
|
||||
group.name = groupSkeleton.name;
|
||||
group.days = [];
|
||||
|
||||
for (let dayIdx = 0; dayIdx < daySkeletons.length - 1; ++dayIdx) {
|
||||
for (let dayIdx = 0; dayIdx < daySkeletons.length; ++dayIdx) {
|
||||
const daySkeleton = daySkeletons[dayIdx];
|
||||
const day = new V2DayDto();
|
||||
{
|
||||
@@ -475,7 +469,9 @@ export class V2ScheduleParser {
|
||||
|
||||
const lessonTimeColumn = daySkeletons[0].column + 1;
|
||||
const rowDistance =
|
||||
daySkeletons[dayIdx + 1].row - daySkeleton.row;
|
||||
(dayIdx !== daySkeletons.length - 1
|
||||
? daySkeletons[dayIdx + 1].row
|
||||
: saturdayEndRow) - daySkeleton.row;
|
||||
|
||||
const dayTimes: Array<InternalTime> = daysTimesFilled
|
||||
? daysTimes[day.name]
|
||||
@@ -573,11 +569,6 @@ export class V2ScheduleParser {
|
||||
|
||||
const teachers = V2ScheduleParser.convertGroupsToTeachers(groups);
|
||||
|
||||
const updatedTeachers = V2ScheduleParser.getUpdatedTeachers(
|
||||
this.lastResult?.teachers,
|
||||
teachers,
|
||||
);
|
||||
|
||||
return (this.lastResult = {
|
||||
downloadedAt: headData.requestedAt,
|
||||
uploadedAt: headData.uploadedAt,
|
||||
@@ -593,10 +584,7 @@ export class V2ScheduleParser {
|
||||
? (this.lastResult?.updatedGroups ?? [])
|
||||
: updatedGroups,
|
||||
|
||||
updatedTeachers:
|
||||
updatedTeachers.length === 0
|
||||
? (this.lastResult?.updatedTeachers ?? [])
|
||||
: updatedTeachers,
|
||||
updatedTeachers: [], // TODO: Вернуть эту фичу
|
||||
});
|
||||
}
|
||||
|
||||
@@ -760,32 +748,4 @@ export class V2ScheduleParser {
|
||||
|
||||
return updatedGroups;
|
||||
}
|
||||
|
||||
private static getUpdatedTeachers(
|
||||
cachedTeachers: Array<V2TeacherDto> | null,
|
||||
currentTeachers: Array<V2TeacherDto>,
|
||||
): Array<Array<number>> {
|
||||
if (!cachedTeachers) return [];
|
||||
|
||||
const updatedTeachers = [];
|
||||
|
||||
for (const name in cachedTeachers) {
|
||||
const cachedTeacher = cachedTeachers[name];
|
||||
const currentTeacher = currentTeachers[name];
|
||||
|
||||
const affectedTeacherDays: Array<number> = [];
|
||||
|
||||
for (const dayIdx in currentTeacher.days) {
|
||||
if (
|
||||
objectHash.sha1(currentTeacher.days[dayIdx]) !==
|
||||
objectHash.sha1(cachedTeacher.days[dayIdx])
|
||||
)
|
||||
affectedTeacherDays.push(+dayIdx);
|
||||
}
|
||||
|
||||
updatedTeachers[name] = affectedTeacherDays;
|
||||
}
|
||||
|
||||
return updatedTeachers;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user