Added holiday detection resolves #2
This commit is contained in:
parent
26a05a8d8c
commit
2f7c089c0b
@ -13,7 +13,7 @@ class VirtuellerStundenplan {
|
|||||||
this.#password = config.password;
|
this.#password = config.password;
|
||||||
if(config.key) this.key = config.key;
|
if(config.key) this.key = config.key;
|
||||||
|
|
||||||
//this.teacherList = config.teachers;
|
this.holidays = config.holidays;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchKey(returnKey=false) {
|
async fetchKey(returnKey=false) {
|
||||||
@ -189,7 +189,7 @@ class VirtuellerStundenplan {
|
|||||||
|
|
||||||
const hasContent = /[\da-zA-Z]/.test(JSON.stringify(day));
|
const hasContent = /[\da-zA-Z]/.test(JSON.stringify(day));
|
||||||
|
|
||||||
res.content[i] = hasContent ? new TimetableDay(day) : null;
|
res.content[i] = hasContent ? new TimetableDay(day, this.holidays) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -3,12 +3,11 @@ const TimetableHour = require("./TimetableHour");
|
|||||||
class TimetableDay {
|
class TimetableDay {
|
||||||
first = null;
|
first = null;
|
||||||
last = null;
|
last = null;
|
||||||
|
holiday = false;
|
||||||
|
|
||||||
constructor(data) {
|
constructor(data, holidays=defaultHolidays) {
|
||||||
this.hours = [];
|
this.hours = [];
|
||||||
|
|
||||||
//console.log(data)
|
|
||||||
|
|
||||||
for (let i = 0; i < data[0].length; i++) {
|
for (let i = 0; i < data[0].length; i++) {
|
||||||
const hour = [
|
const hour = [
|
||||||
data[0][i],
|
data[0][i],
|
||||||
@ -16,7 +15,16 @@ class TimetableDay {
|
|||||||
data[2][i],
|
data[2][i],
|
||||||
data[3][i],
|
data[3][i],
|
||||||
data[4][i],
|
data[4][i],
|
||||||
]
|
];
|
||||||
|
|
||||||
|
const allSame = sameHours(data);
|
||||||
|
|
||||||
|
console.log(allSame)
|
||||||
|
|
||||||
|
if(holidays.includes(allSame)) {
|
||||||
|
this.holiday = allSame;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const hasContent = /[\da-zA-Z]/.test(JSON.stringify(hour));
|
const hasContent = /[\da-zA-Z]/.test(JSON.stringify(hour));
|
||||||
|
|
||||||
@ -28,6 +36,44 @@ class TimetableDay {
|
|||||||
this.hours[i] = hasContent ? new TimetableHour(hour) : null;
|
this.hours[i] = hasContent ? new TimetableHour(hour) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isHoliday() {
|
||||||
|
return this.holiday !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get holidayName() {
|
||||||
|
return this.isHoliday ? this.holiday : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the day only has the same hours (e.g. "-", "Himmelfahrt")
|
||||||
|
*
|
||||||
|
* @param {Array} day (Nested) Day as an array.
|
||||||
|
* @returns {false|string} False if they differ. When not it returns the only existing value.
|
||||||
|
*/
|
||||||
|
const sameHours = day => {
|
||||||
|
// Only include column teacher, subject and room.
|
||||||
|
// Exam always "-", except for when there's exams.
|
||||||
|
day = [day[0], day[1], day[2]];
|
||||||
|
|
||||||
|
const flat = day.flat(); // from [["x","x"]] to ["x","x"]
|
||||||
|
const first = flat[0];
|
||||||
|
return flat.every(val => val === first) ? first : false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultHolidays = [
|
||||||
|
"Sommerferien",
|
||||||
|
"Tag der Deutschen Einheit",
|
||||||
|
"Herbstferien",
|
||||||
|
"Reformationstag",
|
||||||
|
"Weihnachtsferien",
|
||||||
|
"Winterferien",
|
||||||
|
"Osterferien",
|
||||||
|
"Tag der Arbeit",
|
||||||
|
"Himmelfahrt",
|
||||||
|
"Pfingsten",
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
module.exports = TimetableDay;
|
module.exports = TimetableDay;
|
Loading…
x
Reference in New Issue
Block a user