Compare commits
6 Commits
abddc62f8c
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
1c6023beab
|
|||
|
f559d3a91b
|
|||
|
1e971a0601
|
|||
|
32b31814e2
|
|||
|
1f9543909a
|
|||
|
b4118f7b25
|
@@ -2,8 +2,9 @@ const API_BASE_URL = process.env.ANNOUNCEMENT_API || "http://localhost:3000";
|
||||
|
||||
export type Announcement = {
|
||||
id: number;
|
||||
text_content: string;
|
||||
text_content?: string;
|
||||
author: string;
|
||||
classes: string[];
|
||||
flags: Flag[];
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
+33
-5
@@ -18,7 +18,7 @@ import parseTeachers from "../utils/parseTeachers.js"
|
||||
import ExcelJS, { Worksheet, Cell, Row, Workbook } from "exceljs"
|
||||
import JSZip from "jszip";
|
||||
import { parseStringPromise } from "xml2js";
|
||||
import getAnnouncements, { Flag } from "../api/annoucements.js";
|
||||
import getAnnouncements, { Flag } from "../api/announcements.js";
|
||||
|
||||
interface ThemeColors {
|
||||
[key: number]: string | null;
|
||||
@@ -124,13 +124,21 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
|
||||
|
||||
const upcoming = getUpcomingSheets(workbook);
|
||||
const resolvedDays = groupSheetsByDate(upcoming);
|
||||
const getDates = resolvedDays.map((d) => d.dateKey);
|
||||
const annoucements = await getAnnouncements(getDates);
|
||||
|
||||
const sheetDates = resolvedDays.map((d) => d.dateKey);
|
||||
const announcementDates = getWeekDates().concat(sheetDates);
|
||||
if (new Date().getDay() === 0) {
|
||||
announcementDates.push(...getWeekDates(7));
|
||||
}
|
||||
const announcements = await getAnnouncements([...new Set(announcementDates)]);
|
||||
|
||||
const schedule: any = {};
|
||||
|
||||
for (const { dateKey, sheet } of resolvedDays) {
|
||||
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, annoucements[dateKey].map(a => a.flags).flat());
|
||||
const ann = announcements[dateKey];
|
||||
const allFlags = ann.map(a => a.flags).flat();
|
||||
|
||||
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, allFlags);
|
||||
|
||||
schedule[dateKey] = {
|
||||
info: { inWork },
|
||||
@@ -143,7 +151,7 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
|
||||
|
||||
const data = {
|
||||
status: { lastUpdated: formatNowTime() },
|
||||
annoucements,
|
||||
announcements,
|
||||
schedule,
|
||||
};
|
||||
|
||||
@@ -231,6 +239,7 @@ function isPripravaSheet(name: string) {
|
||||
//
|
||||
|
||||
function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null, flags: Flag[]) {
|
||||
console.log(flags)
|
||||
const ignoreColors = flags.includes(Flag.SHOW_ALL_ENTRIES)
|
||||
const classRegex = /[AEC][0-4][a-c]?\s*\/.*/s;
|
||||
const prefixRegex = /[AEC][0-4][a-c]?/;
|
||||
@@ -420,6 +429,25 @@ function letterToNumber(letter: string) {
|
||||
return letter.toLowerCase().charCodeAt(0) - 97;
|
||||
}
|
||||
|
||||
function getWeekDates(offset: number = 0): string[] {
|
||||
const today = new Date();
|
||||
const day = today.getDay();
|
||||
const monday = new Date(today);
|
||||
monday.setDate(today.getDate() + (day === 0 ? -6 : 1 - day) + offset);
|
||||
|
||||
const dates: string[] = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const d = new Date(monday);
|
||||
d.setDate(monday.getDate() + i);
|
||||
dates.push(formatDateKey(d));
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
function formatDateKey(date: Date): string {
|
||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function formatNowTime() {
|
||||
const now = new Date();
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user