mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
Улучшение конвертера расписания для групп в расписание для преподавателей
This commit is contained in:
11
package-lock.json
generated
11
package-lock.json
generated
@@ -30,6 +30,7 @@
|
||||
"firebase-admin": "^13.0.2",
|
||||
"jsdom": "^26.0.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash": "^4.17.21",
|
||||
"object-hash": "^3.0.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
@@ -49,6 +50,7 @@
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@types/lodash": "^4.17.16",
|
||||
"@types/multer": "^1.4.12",
|
||||
"@types/node": "^22.10.9",
|
||||
"@types/object-hash": "^3.0.6",
|
||||
@@ -3946,6 +3948,13 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.17.16",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.16.tgz",
|
||||
"integrity": "sha512-HX7Em5NYQAXKW+1T+FiuG27NGwzJfCX3s1GjOa7ujxZa52kjJLOr4FUxT+giF6Tgxv1e+/czV/iTtBw27WTU9g==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/long": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz",
|
||||
@@ -9602,6 +9611,8 @@
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.camelcase": {
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
"firebase-admin": "^13.0.2",
|
||||
"jsdom": "^26.0.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash": "^4.17.21",
|
||||
"object-hash": "^3.0.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
@@ -61,6 +62,7 @@
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@types/lodash": "^4.17.16",
|
||||
"@types/multer": "^1.4.12",
|
||||
"@types/node": "^22.10.9",
|
||||
"@types/object-hash": "^3.0.6",
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
} from "class-validator";
|
||||
import { ClassProperties } from "../../../utility/class-trasformer/class-transformer-ctor";
|
||||
import { ToMap } from "create-map-transform-fn";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
|
||||
type InternalId = {
|
||||
/**
|
||||
@@ -353,74 +354,53 @@ export class ScheduleParser {
|
||||
private static convertGroupsToTeachers(
|
||||
groups: Map<string, Group>,
|
||||
): Map<string, Teacher> {
|
||||
const result = new Map<string, Teacher>();
|
||||
const teachers = new Map<string, Teacher>();
|
||||
|
||||
for (const groupName of groups.keys()) {
|
||||
const group = groups.get(groupName);
|
||||
const days = (() => {
|
||||
const group = groups.values().next().value as Group;
|
||||
|
||||
for (const day of group.days) {
|
||||
for (const lesson of day.lessons) {
|
||||
if (lesson.type !== LessonType.DEFAULT) continue;
|
||||
return group.days.map((day) => {
|
||||
return new TeacherDay({
|
||||
name: day.name,
|
||||
street: day.street,
|
||||
date: day.date,
|
||||
lessons: [],
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
for (const subGroup of lesson.subGroups) {
|
||||
let teacherDto: Teacher = result.get(subGroup.teacher);
|
||||
const cloneDays = () => cloneDeep(days);
|
||||
|
||||
if (!teacherDto) {
|
||||
teacherDto = new Teacher({
|
||||
name: subGroup.teacher,
|
||||
days: [],
|
||||
});
|
||||
for (const group of groups.values()) {
|
||||
group.days.forEach((day, dayIndex) => {
|
||||
for (const groupLesson of day.lessons) {
|
||||
if (groupLesson.type !== LessonType.DEFAULT) continue;
|
||||
|
||||
result.set(subGroup.teacher, teacherDto);
|
||||
for (const subGroup of groupLesson.subGroups) {
|
||||
if (!teachers.has(subGroup.teacher)) {
|
||||
teachers.set(
|
||||
subGroup.teacher,
|
||||
new Teacher({
|
||||
name: subGroup.teacher,
|
||||
days: cloneDays(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
let teacherDay = teacherDto.days[
|
||||
day.name
|
||||
] as TeacherDay;
|
||||
const teacherDay = teachers.get(subGroup.teacher).days[
|
||||
dayIndex
|
||||
];
|
||||
|
||||
if (!teacherDay) {
|
||||
teacherDay = teacherDto.days[day.name] =
|
||||
new TeacherDay({
|
||||
name: day.name,
|
||||
date: day.date,
|
||||
lessons: [],
|
||||
});
|
||||
}
|
||||
const lesson = cloneDeep(groupLesson) as TeacherLesson;
|
||||
lesson.group = group.name;
|
||||
|
||||
const teacherLesson = structuredClone(
|
||||
lesson,
|
||||
) as TeacherLesson;
|
||||
teacherLesson.group = groupName;
|
||||
|
||||
teacherDay.lessons.push(teacherLesson);
|
||||
teacherDay.lessons.push(lesson);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (const teacherName of result.keys()) {
|
||||
const teacher = result.get(teacherName);
|
||||
|
||||
const days = teacher.days;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-for-in-array
|
||||
for (const dayName in days) {
|
||||
const day = days[dayName];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-array-delete
|
||||
delete days[dayName];
|
||||
|
||||
day.lessons.sort(
|
||||
(a, b) => a.time.start.valueOf() - b.time.start.valueOf(),
|
||||
);
|
||||
|
||||
days.push(day);
|
||||
}
|
||||
|
||||
days.sort((a, b) => a.date.valueOf() - b.date.valueOf());
|
||||
}
|
||||
|
||||
return result;
|
||||
return teachers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user