feat: enhance lesson plan handling with new parser and color-coded room assignments
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { test, before, after } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { setTimeout as sleep } from "node:timers/promises";
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { startApi } from "./support/nextcloud.js";
|
||||
|
||||
// The university is asked politely: every request names the service and its owner, and while
|
||||
@@ -62,3 +63,17 @@ test("Источник: пока университет не отвечает,
|
||||
assert.equal(catalog.failingSince, null);
|
||||
assert.ok(!(await (await fetch(api.base + "/api/catalog")).json()).stale);
|
||||
});
|
||||
|
||||
test("Источник: новый парсер перечитывает сохранённый документ, не обращаясь к университету", async () => {
|
||||
const { files } = await (await fetch(api.base + "/api/catalog")).json();
|
||||
const file = files.find((f) => f.name === "23-ЛГ_23-БА.docx");
|
||||
assert.equal((await fetch(api.base + "/api/schedule/" + file.id)).status, 200);
|
||||
// The cache as an older parser left it.
|
||||
const cache = `${process.env.PSU_DATA_DIR}/parsed/${file.id}.json`;
|
||||
writeFileSync(cache, JSON.stringify({ ...JSON.parse(readFileSync(cache, "utf8")), schemaVersion: 1 }));
|
||||
const requests = api.stats.requests;
|
||||
const schedule = await (await fetch(api.base + "/api/schedule/" + file.id)).json();
|
||||
assert.equal(api.stats.requests, requests);
|
||||
assert.notEqual(schedule.schemaVersion, 1);
|
||||
assert.ok(schedule.lessons.length > 0);
|
||||
});
|
||||
|
||||
@@ -53,6 +53,19 @@ test("Преподаватель по неделям и аудитория по
|
||||
const byColor = peopleAndRooms({ raw: lesson.text, room: "", teacher: "", plan: lesson.plan }, "2026");
|
||||
assert.deepEqual(roomsOn(byColor, "2026-11-10", { n: 11, color: "white" }), ["504Н"]);
|
||||
assert.deepEqual(roomsOn(byColor, "2026-11-17", { n: 12, color: "green" }), ["524Н"]);
|
||||
// The colour after each room (25-ДО): "ауд.533н-б.н.,420н-з.н.".
|
||||
const [after] = entries("Теоретические основы воспитания и развития речи детей раннего возраста (п.з.) Савейко В.Л. ауд.533н-б.н.,420н-з.н.");
|
||||
assert.deepEqual(after.plan, [
|
||||
{ weeks: null, color: "white", rooms: ["533Н"], teachers: ["Савейко В.Л."] },
|
||||
{ weeks: null, color: "green", rooms: ["420Н"], teachers: ["Савейко В.Л."] },
|
||||
]);
|
||||
const roomAfter = peopleAndRooms({ raw: after.text, room: "533н", teacher: "Савейко В.Л.", plan: after.plan }, "2026");
|
||||
assert.deepEqual(roomsOn(roomAfter, "2026-10-30", { n: 9, color: "white" }), ["533Н"]);
|
||||
assert.deepEqual(roomsOn(roomAfter, "2026-10-23", { n: 8, color: "green" }), ["420Н"]);
|
||||
assert.deepEqual(weekPlan("ауд. 420н з.н., 533н б.н.").map((p) => [p.color, p.rooms]), [["white", ["533Н"]], ["green", ["420Н"]]]);
|
||||
assert.equal(onlyPlace("533н-б.н.,420н-з.н."), true);
|
||||
// "32н" before its colour is a room, not week 32.
|
||||
assert.deepEqual(weekPlan("Коррекционная дошкольная педагогика (л.) Остапчук С.В. ауд.64н -б.н., 32н-з.н.").map((p) => [p.color, p.rooms]), [["white", ["64Н"]], ["green", ["32Н"]]]);
|
||||
assert.equal(onlyPlace("1-9н. 502н"), true);
|
||||
assert.equal(onlyPlace("13,15 н. РБ (л.з) Сивацкий Д.С.209н"), false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user