feat: enhance lesson plan handling with new parser and color-coded room assignments
This commit is contained in:
@@ -51,8 +51,9 @@ export function roomMoves(text, year) {
|
||||
return { moves, rest };
|
||||
}
|
||||
|
||||
// A week mark opening a part of a line: "1-9н.", "с 10н", "14-17н.", "7,9,11н.".
|
||||
const WEEK_MARK = /(?<=^|[\s,;])(?:(?:с|со)\s*)?\d{1,2}(?:\s*[-–,]\s*\d{1,2})*\s*н(?:ед)?(?![а-яё])\.?/giu;
|
||||
// A week mark opening a part of a line: "1-9н.", "с 10н", "14-17н.", "7,9,11н.". Not a room
|
||||
// with its week's colour: "32н-з.н." is room 32Н in green weeks.
|
||||
const WEEK_MARK = /(?<=^|[\s,;])(?:(?:с|со)\s*)?\d{1,2}(?:\s*[-–,]\s*\d{1,2})*\s*н(?:ед)?(?![а-яё])(?!\.?\s*[-–]?\s*[бз](?:ел)?\.?\s*н)\.?/giu;
|
||||
|
||||
/** A line cut where each week mark begins: "1-13н-332, 14-17н.-502н" → two parts. */
|
||||
export function partsByWeek(text) {
|
||||
@@ -63,6 +64,8 @@ export function partsByWeek(text) {
|
||||
const PART_MARK = /^(?:(?:с|со)\s*)?\d{1,2}(?:\s*[-–,]\s*\d{1,2})*\s*н(?:ед)?\.?/iu;
|
||||
// "бел.н.504н/зел.н.524н", "б.н.301Г/з.н.317Д": a room for white weeks and one for green ones.
|
||||
const BY_COLOR = /б(?:ел)?\.?\s*н(?:ед)?\.?\s*([^/\s]+)\s*\/\s*з(?:ел)?\.?\s*н(?:ед)?\.?\s*([^\s,;]+)/iu;
|
||||
// "ауд.533н-б.н.,420н-з.н.": the colour after each room.
|
||||
const ROOM_COLOR = new RegExp(`(${ROOM_TEXT})\\s*[-–]?\\s*(б|з)(?:ел)?\\.?\\s*н(?:ед)?\\.?(?![а-яё])`, "giu");
|
||||
|
||||
const roomsIn = (text) =>
|
||||
tokens(text.replace(PERSON, " ").replace(/\([^)]*\)/g, " "))
|
||||
@@ -83,9 +86,15 @@ export function weekPlan(text) {
|
||||
const rest = part.slice(mark.length);
|
||||
const teachers = [...rest.matchAll(PERSON)].map((m) => personName(m[0]));
|
||||
const color = rest.match(BY_COLOR);
|
||||
const byRoom = [...rest.matchAll(ROOM_COLOR)];
|
||||
if (color) {
|
||||
plan.push({ weeks, color: "white", rooms: roomsIn(color[1]), teachers });
|
||||
plan.push({ weeks, color: "green", rooms: roomsIn(color[2]), teachers });
|
||||
} else if (byRoom.length) {
|
||||
for (const [name, letter] of [["white", "б"], ["green", "з"]]) {
|
||||
const rooms = byRoom.filter((m) => m[2].toLowerCase() === letter).map((m) => roomKey(m[1]));
|
||||
if (rooms.length) plan.push({ weeks, color: name, rooms, teachers });
|
||||
}
|
||||
} else if (mark) {
|
||||
const rooms = roomsIn(rest);
|
||||
if (rooms.length || teachers.length) plan.push({ weeks, color: null, rooms, teachers });
|
||||
@@ -106,6 +115,7 @@ export function onlyPlace(text) {
|
||||
const left = (text || "")
|
||||
.replace(PERSON, " ")
|
||||
.replace(BY_COLOR, " ")
|
||||
.replace(ROOM_COLOR, " ")
|
||||
.replace(/(?:(?:с|со)\s*)?\d{1,2}(?:\s*[-–,]\s*\d{1,2})*\s*н(?:ед)?\.?/giu, " ")
|
||||
.replace(/ауд\.?|а\./giu, " ")
|
||||
.replace(/[А-ЯA-Z]\d-\d{2}|\d{2,4}\s?[А-Яа-я]{0,2}(?![а-яё])/gu, " ");
|
||||
|
||||
Reference in New Issue
Block a user