From 7cd4559fea46f0b9be5c9604fa45644fd084a281 Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Mon, 8 Aug 2022 01:41:56 -0500 Subject: `parseOfficeHours` works correctly now. PT office hours can now be automatically parsed (if using strawpoll). Also displaying office hours in TAMU HTML Output page --- src/util/parser.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/parser.ts b/src/util/parser.ts index 1daf113..0e2ebbf 100644 --- a/src/util/parser.ts +++ b/src/util/parser.ts @@ -266,10 +266,32 @@ export function parseOfficeHours(csv: string) { for (let i = begin + 1; i < end; i++) { const pt_uin = parseInt(sheet[i][0]); const pt = pts.get(pt_uin); - if (pt != undefined || pt != null) { + if (pt != undefined && pt != null) pt.office_hours = parseStrawpollTimesEntry(sheet[i], sheet[begin]); - } } + + + // Merge office hours that take place during the same time of day + pts.forEach((pt) => { + if (pt.office_hours != undefined && pt.office_hours != null) { + const flag = {}; + const unique: EventInfo[] = []; + pt.office_hours.forEach((curr_event) => { + const key = `${curr_event.start}${curr_event.end}`; + if (!flag[key]) { + flag[key] = true; + unique.push(curr_event); + } + else { + const head_event = unique.find((val) => { + return val.start === curr_event.start && val.end === curr_event.end; + }) + head_event.days += curr_event.days; + } + }) + pt.office_hours = unique; + } + }); } /** -- cgit v1.2.3