Big Update
This commit is contained in:
36
classes/parsers/AbsentDay.js
Normal file
36
classes/parsers/AbsentDay.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const ParseTools = require("./ParseTools");
|
||||
|
||||
class AbsentDay {
|
||||
constructor(data) {
|
||||
this.date = ParseTools.parseDateTime(data.Datum);
|
||||
this.hour = data.Stunde;
|
||||
this.status = data.Status;
|
||||
this.comment = ParseTools.isFilled(data.Bemerkung);
|
||||
}
|
||||
|
||||
get present() {
|
||||
switch (this.status) {
|
||||
case "o":
|
||||
case "G5":
|
||||
case "L5":
|
||||
case "V5":
|
||||
return true;
|
||||
case "--":
|
||||
case "K":
|
||||
case "E":
|
||||
case "A":
|
||||
case "( )":
|
||||
case "U":
|
||||
return false;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
get absent() {
|
||||
if(this.present === null) return null;
|
||||
return !this.present;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AbsentDay
|
||||
20
classes/parsers/AbsentSummary.js
Normal file
20
classes/parsers/AbsentSummary.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const ParseTools = require("./ParseTools");
|
||||
const AbsentDay = require("./AbsentDay");
|
||||
|
||||
class AbsentSummary {
|
||||
days = [];
|
||||
|
||||
constructor(data) {
|
||||
this.presentDays = ParseTools.daysToArray(data.Summary['Anwesend am']);
|
||||
this.absentDays = ParseTools.daysToArray(data.Summary['Fehlte am']);
|
||||
this.partlyAbsentDays = ParseTools.daysToArray(data.Summary['Fehlte teilweise am']);
|
||||
this.unexcusedDays = ParseTools.daysToArray(data.Summary['unentschuldigte Tage']);
|
||||
this.excusedDays = ParseTools.daysToArray(data.Summary['unentschuldigte Tage']);
|
||||
|
||||
data.Details.forEach((day, i) => {
|
||||
this.days[i] = new AbsentDay(day);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AbsentSummary
|
||||
16
classes/parsers/Functions.js
Normal file
16
classes/parsers/Functions.js
Normal file
@@ -0,0 +1,16 @@
|
||||
class Functions {
|
||||
#data;
|
||||
|
||||
constructor(data) {
|
||||
this.#data = data;
|
||||
|
||||
this.enabled = data.Enabled;
|
||||
this.disabled = data.Disabled;
|
||||
}
|
||||
|
||||
getAll() {
|
||||
return [...this.enabled, ...this.disabled];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Functions
|
||||
37
classes/parsers/Head.js
Normal file
37
classes/parsers/Head.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const ParseTools = require("./ParseTools");
|
||||
|
||||
class Head {
|
||||
#data;
|
||||
|
||||
constructor(data) {
|
||||
this.#data = data;
|
||||
|
||||
this.httpStatus = data.Status ? Number(data.Status) : null;
|
||||
|
||||
this.from = data.KlaBuDateVon ? ParseTools.parseDateTime(data.KlaBuDateVon) : undefined;
|
||||
this.to = data.KlaBuDateBis ? ParseTools.parseDateTime(data.KlaBuDateBis) : undefined;
|
||||
|
||||
if(data['Von h']) this.fromHour = data['Von h'];
|
||||
if(data['Bis h']) this.toHour = data['Bis h'];
|
||||
|
||||
if(data['Von Wochentag']) this.fromWeekDay = data['Von Wochentag'];
|
||||
if(data['Bis Wochentag']) this.toWeekDay = data['Bis Wochentag'];
|
||||
|
||||
if(data.AktuelleID) this.currentID = Number(data.AktuelleID);
|
||||
|
||||
if(data.Schuljahr) this.schoolYear = data.Schuljahr;
|
||||
|
||||
if(data.AnzahlLeistungen) this.totalPerformances = data.AnzahlLeistungen;
|
||||
|
||||
// Timetable:
|
||||
if(ParseTools.isFilled(data.Name)) this.name = data.Name;
|
||||
if(ParseTools.isFilled(data.Klasse)) this.class = data.Klasse;
|
||||
if(data.Schulnummer) this.schoolNumber = data.Schulnummer;
|
||||
if(ParseTools.isFilled(data.InKlasse)) this.inClass = data.InKlasse;
|
||||
if(ParseTools.isFilled(data.InKursen)) this.inCourses = data.InKursen;
|
||||
if(typeof data.EffPlan !== "undefined") this.effectiveTimetable = !!data.EffPlan;
|
||||
if(typeof data.CompactPlan !== "undefined") this.compactTimetable = !!data.CompactPlan;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Head
|
||||
33
classes/parsers/Homework.js
Normal file
33
classes/parsers/Homework.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const PT = require("./ParseTools");
|
||||
const Teacher = require("./Teacher");
|
||||
|
||||
class Homework {
|
||||
#data;
|
||||
|
||||
constructor(data) {
|
||||
this.#data = data;
|
||||
|
||||
this.id = data.ID;
|
||||
this.date = PT.parseDateTime(this.rawDate, "dd.MM.yyyy");
|
||||
this.hour = PT.isFilled(data.Stunde) ? Number(data.Stunde): null;
|
||||
this.class = PT.isFilled(data.Klasse, true);
|
||||
this.course = PT.isFilled(data.Kurs, true);
|
||||
this.course = PT.isFilled(data.Kursschiene, true);
|
||||
this.teacher = PT.isFilled(data.LK, true);
|
||||
//data.Vertretung - value in testing always "" or "0"
|
||||
this.subject = PT.isFilled(data.Fach, true);
|
||||
this.room = PT.isFilled(data.Raum, true);
|
||||
this.note = PT.isFilled(data.Bemerkung, true);
|
||||
this.homework = PT.isFilled(data.Hausaufgaben, true);
|
||||
}
|
||||
|
||||
get rawDate() {
|
||||
return this.#data.Datum;
|
||||
}
|
||||
|
||||
get raw() {
|
||||
return this.#data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Homework
|
||||
22
classes/parsers/Message.js
Normal file
22
classes/parsers/Message.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const ParseTools = require("./ParseTools");
|
||||
|
||||
class Message {
|
||||
#data;
|
||||
|
||||
constructor(data) {
|
||||
this.#data = data;
|
||||
|
||||
this.content = data.Message;
|
||||
this.timestamp = ParseTools.parseDateTime(data.rawTimestamp, "yyyy-MM-dd HH:mm:ss");
|
||||
this.target = data.Target;
|
||||
this.type = data.Typ;
|
||||
this.course = data.Kurs;
|
||||
this.class = data.Klasse;
|
||||
}
|
||||
|
||||
get rawTimestamp() {
|
||||
return this.#data.Datum;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Message
|
||||
23
classes/parsers/ParseTools.js
Normal file
23
classes/parsers/ParseTools.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const { DateTime } = require("luxon");
|
||||
|
||||
class ParseTools {
|
||||
static parseDateTime(date, format="yyyy-MM-dd") {
|
||||
return DateTime.fromFormat(date, format, { zone: "Europe/Berlin" });
|
||||
}
|
||||
|
||||
static isFilled(value, returnValOrNull=false) {
|
||||
const res = value !== "" && value !== "-";
|
||||
return returnValOrNull ? (res ? value : null) : res;
|
||||
}
|
||||
|
||||
static daysToArray(days, seperator=", ", format="dd.MM.yyyy") {
|
||||
let res = [];
|
||||
days.split(seperator).forEach(day => {
|
||||
if(day === "") return;
|
||||
res.push(this.parseDateTime(day, format));
|
||||
});
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ParseTools
|
||||
24
classes/parsers/SchoolYear.js
Normal file
24
classes/parsers/SchoolYear.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const ParseTools = require("./ParseTools");
|
||||
|
||||
class SchoolYear {
|
||||
#data;
|
||||
|
||||
constructor(data) {
|
||||
this.#data = data;
|
||||
|
||||
this.id = data.ID;
|
||||
this.title = data.SJ;
|
||||
this.from = ParseTools.parseDateTime(this.rawFrom);
|
||||
this.to = ParseTools.parseDateTime(this.rawTo);
|
||||
}
|
||||
|
||||
get rawFrom() {
|
||||
return this.#data.von;
|
||||
}
|
||||
|
||||
get rawTo() {
|
||||
return this.#data.bis;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SchoolYear
|
||||
28
classes/parsers/Teacher.js
Normal file
28
classes/parsers/Teacher.js
Normal file
@@ -0,0 +1,28 @@
|
||||
class Teacher {
|
||||
/**
|
||||
* Creates a Instance of Teacher
|
||||
*
|
||||
* @param {String} teacher - Code for the teacher.
|
||||
* @param {Object} teacherList - Object of teachers.
|
||||
*/
|
||||
constructor(teacher, teacherList) {
|
||||
/** @returns {String} Teacher's code */
|
||||
this.code = teacher;
|
||||
|
||||
teacher = teacherList && teacherList[this.code] ? teacherList[this.code] : {};
|
||||
|
||||
/** @returns {String} First name(s) of the teacher. If unset the teacher's code. */
|
||||
this.firstName = teacher.firstName ?? this.code;
|
||||
/** @returns {String} Last name of the teacher. If unset the teacher's code. */
|
||||
this.lastName = teacher.lastName ?? this.code;
|
||||
|
||||
let name = [];
|
||||
if(teacher.firstName) name.push(teacher.firstName);
|
||||
if(teacher.lastName) name.push(teacher.lastName);
|
||||
|
||||
/** @returns {String} Full name of the teacher. If unset the teacher's code. */
|
||||
this.fullName = name.join(" ") || this.code;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Teacher
|
||||
33
classes/parsers/TimetableDay.js
Normal file
33
classes/parsers/TimetableDay.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const TimetableHour = require("./TimetableHour");
|
||||
|
||||
class TimetableDay {
|
||||
first = null;
|
||||
last = null;
|
||||
|
||||
constructor(data) {
|
||||
this.hours = [];
|
||||
|
||||
//console.log(data)
|
||||
|
||||
for (let i = 0; i < data[0].length; i++) {
|
||||
const hour = [
|
||||
data[0][i],
|
||||
data[1][i],
|
||||
data[2][i],
|
||||
data[3][i],
|
||||
data[4][i],
|
||||
]
|
||||
|
||||
const hasContent = /[\da-zA-Z]/.test(JSON.stringify(hour));
|
||||
|
||||
if(hasContent) {
|
||||
if(this.first === null) this.first = i;
|
||||
this.last = i;
|
||||
}
|
||||
|
||||
this.hours[i] = hasContent ? new TimetableHour(hour) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TimetableDay;
|
||||
60
classes/parsers/TimetableHour.js
Normal file
60
classes/parsers/TimetableHour.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const ParseTools = require("./ParseTools");
|
||||
|
||||
const parser = (text) => {
|
||||
if(!ParseTools.isFilled(text)) return null;
|
||||
|
||||
const data = {
|
||||
original: text,
|
||||
changes: false,
|
||||
note: null,
|
||||
planned: text,
|
||||
actual: text,
|
||||
};
|
||||
|
||||
const hasBold = text.includes("<b> ");
|
||||
const hasDel = text.includes("<del>");
|
||||
|
||||
if(hasBold) {
|
||||
data.actual = text.split("<b> ")[1].split("</b>")[0];
|
||||
if(hasDel) data.actual = data.actual.substring(1);
|
||||
}
|
||||
|
||||
if(hasDel) {
|
||||
data.planned = text.split("<del>")[1].split("</del>")[0];
|
||||
data.changes = true;
|
||||
if(text.substring(text.search("</del>") + 6) !== "") { // If it has reasoning/note
|
||||
|
||||
if(!hasBold) {
|
||||
data.actual = null;
|
||||
data.note = text.substring(text.search("</del>") + 6);
|
||||
} else data.note = text.substring(text.search("</b>") + 5);
|
||||
|
||||
data.note = data.note.trim();
|
||||
|
||||
if(data.note === "") data.note = null;
|
||||
|
||||
} else data.actual = null;
|
||||
} else data.planned = data.actual;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
class TimetableDay {
|
||||
#data = [];
|
||||
|
||||
anyChanges = false;
|
||||
|
||||
constructor(data) {
|
||||
data.forEach((part, i) => {
|
||||
this.#data[i] = parser(part);
|
||||
if(this.#data[i]?.changes) this.anyChanges = true;
|
||||
});
|
||||
|
||||
this.teacher = this.#data[0];
|
||||
this.subject = this.#data[1];
|
||||
this.room = this.#data[2];
|
||||
this.exam = this.#data[3];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TimetableDay;
|
||||
9
classes/parsers/index.js
Normal file
9
classes/parsers/index.js
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
Head: require("./Head"),
|
||||
Functions: require("./Functions"),
|
||||
Message: require("./Message"),
|
||||
Homework: require("./Homework"),
|
||||
SchoolYear: require("./SchoolYear"),
|
||||
TimetableDay: require("./TimetableDay"),
|
||||
AbsentSummary: require("./AbsentSummary"),
|
||||
}
|
||||
Reference in New Issue
Block a user