API-33: Adjusting filter logic
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2021-10-08 11:51:14 +02:00
parent f45b8a9967
commit 7622416a2f
Signed by: Paddy
GPG Key ID: 3433DBC617B195CA
2 changed files with 72 additions and 1805 deletions

1804
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -50,11 +50,14 @@ export const parseIcal = function (icalContents: string): iCalFile {
header = header.substr(0, header.lastIndexOf('\n'));
let events: string[] = [];
let events: iCalEvent[] = [];
let match: any;
while (match = eventRegex.exec(icalContents)) {
if (match) {
events.push(match[0]);
events.push({
content: match[0],
duration: getDuration(match[0])
});
}
}
@ -64,10 +67,51 @@ export const parseIcal = function (icalContents: string): iCalFile {
};
};
export const getDuration = function(event: string): number {
let startRegex: RegExp = /DTSTART.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm; // Fix this, doesnt match \n but matching Z doesnt work all the time
let endRegex: RegExp = /DTEND.*?(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z?\r/gm; // s.o.
// localhost:3000/rapla-middleware?user=eisenbiegler&file=TINF19B4&blockers=0&wahl=4&pflicht=2
let startMatch = startRegex.exec(event);
let startDtYear = 0;
let startDtMonth = 0;
let startDtDay = 0;
let startDtHour = 0;
let startDtMinute = 0;
if(startMatch) {
startDtYear = parseInt(startMatch[1]);
startDtMonth = parseInt(startMatch[2]);
startDtDay = parseInt(startMatch[3]);
startDtHour = parseInt(startMatch[4]);
startDtMinute = parseInt(startMatch[5]);
}
let endMatch = endRegex.exec(event);
let endDtYear = 0;
let endDtMonth = 0;
let endDtDay = 0;
let endDtHour = 0;
let endDtMinute = 0;
if(endMatch) {
endDtYear = parseInt(endMatch[1]);
endDtMonth = parseInt(endMatch[2]);
endDtDay = parseInt(endMatch[3]);
endDtHour = parseInt(endMatch[4]);
endDtMinute = parseInt(endMatch[5]);
}
let startDt = new Date(startDtYear, startDtMonth - 1, startDtDay, startDtHour, startDtMinute);
let endDt = new Date(endDtYear, endDtMonth - 1, endDtDay, endDtHour, endDtMinute);
return endDt.getHours() - startDt.getHours();
}
export const serializeIcal = function (ical: iCalFile): string {
let resString = ical.head;
ical.body.forEach((event) => {
resString += event + '\n';
resString += event.content + '\n';
});
resString += 'END:VCALENDAR';
@ -75,10 +119,14 @@ export const serializeIcal = function (ical: iCalFile): string {
};
export const removeBlockers = function (ical: iCalFile): iCalFile {
let remainingEvents: string[] = [];
let remainingEvents: iCalEvent[] = [];
ical.body.forEach((event) => {
if (!event.includes('CATEGORIES:Sonstiger Termin') && !event.includes('SUMMARY:Präsenz')) {
if (
!event.content.includes('SUMMARY:Beginn Theorie')
&& !event.content.includes('SUMMARY:Präsenz')
&& event.duration < 10
) {
remainingEvents.push(event);
}
});
@ -89,7 +137,7 @@ export const removeBlockers = function (ical: iCalFile): iCalFile {
};
export const removeElective = function (ical: iCalFile, chosenElective: string): iCalFile {
let remainingEvents: string[] = [];
let remainingEvents: iCalEvent[] = [];
let electiveToRemove = [
{name: 'ERP-Systeme'},
@ -105,7 +153,7 @@ export const removeElective = function (ical: iCalFile, chosenElective: string):
ical.body.forEach((event) => {
let addEvent = true;
electiveToRemove.forEach((module) => {
if (event.includes(module.name)) {
if (event.content.includes(module.name)) {
addEvent = false;
}
});
@ -121,7 +169,7 @@ export const removeElective = function (ical: iCalFile, chosenElective: string):
};
export const removeProfile = function (ical: iCalFile, chosenProfile: string): iCalFile {
let remainingEvents: string[] = [];
let remainingEvents: iCalEvent[] = [];
let profileToRemove = [
{names: ['.Grundlagen der KI (KI und BV)', 'Bildverarbeitung (KI und BV)']},
@ -136,7 +184,7 @@ export const removeProfile = function (ical: iCalFile, chosenProfile: string): i
let addEvent = true;
profileToRemove.forEach((module) => {
module.names.forEach((name) => {
if (event.includes(name)) {
if (event.content.includes(name)) {
addEvent = false;
}
});
@ -154,5 +202,10 @@ export const removeProfile = function (ical: iCalFile, chosenProfile: string): i
export interface iCalFile {
head: string;
body: string[];
body: iCalEvent[];
}
export interface iCalEvent {
content: string;
duration: number; // Duration in hours
}