From e10addbe36bc248b297cc19a943356fa9fd0f955 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Thu, 11 Apr 2024 19:18:22 +0200 Subject: structure --- src/main.js | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/stunden.js | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 456 insertions(+) create mode 100644 src/main.js create mode 100644 src/stunden.js (limited to 'src') diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..53323f3 --- /dev/null +++ b/src/main.js @@ -0,0 +1,229 @@ +import * as fs from "fs" +import * as html_to_pdf from "html-pdf-node" +import * as stu from './stunden.js' + +var student = "David Penkowoj"; +var semester = "Sommersemester 2024"; +var date = new Date(); +date = date.toLocaleDateString("de-DE", { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric', +}); + +let options = { + format: 'A4', + landscape: true, + margin: { + top: "0.5cm", + right: "1cm", + bottom: "1cm", + left: "2cm", + }, +}; + +var table = ` + + 08:00 + + + + + + + + +
TGI 1 / VAM 1
+ + + + + +
GET 2 / VH 1
+
GET 2 / VZ 1/2
+
Pho / VT 1
+ + + + + + + 09:00 + + + + + + + + + + + + + + + 10:00 + + + + +
FuQ / VAM 4
+ + + + + + + + + + + + + + + + + + + 11:00 + +
FuQ / ÜSI 4 (Minsky)
+ + + + + + + + + +
GET / ÜAM S4
+ + + + + + + + 12:00 +
GET 2 / ÜAM S4
+ +
Pho / ÜAM 1
+ + + + + +
Ana 2 / VAM 1
+ + + + + + 13:00 + + + + + + + + + + + + +`; + +table = stu.main(); + +var html = ` + +

Persönlicher Stundenplan von ${student} für das ${semester}. Letzter Stand: ${date}.

+ + + + + + + + + + ${table} +
Uhrzeit Montag Dienstag Mittwoch Donnerstag Freitag
+
+ Hinweise: + +`; + +fs.writeFileSync("test.html", html) + +html_to_pdf.generatePdf({content: html}, options).then(pdfBuffer => { + fs.writeFileSync('test.pdf', pdfBuffer); +}); diff --git a/src/stunden.js b/src/stunden.js new file mode 100644 index 0000000..0bf3024 --- /dev/null +++ b/src/stunden.js @@ -0,0 +1,227 @@ +// returns time difference in 15-minute intervalls +function timediff(a, b) { + const time = "1970-01-01 "; + return (new Date(time + a) - new Date(time + b)) / 1000 / 60 / 15; +} + +function gettimefromintervalls(x) { + let y = 15 * x / 60 + 8 + let z = y.toString().padStart(2, '0'); + + if (Math.round(y) == y) return `${z}:00`; + + return "" +} + +function sortTage(tage) { + for (let tag in tage) { + tage[tag].sort((a, b) => { + return timediff(a.von, b.von) + }); + } + + return tage; +} + +function runtimes(tage, tage_runtimes) { + for (let tag in tage) { + for (let eintrag in tage[tag]) { + // could be redundant + if (eintrag == tage[tag].length) break; + + let a = tage[tag][eintrag]; + let runtime = timediff(a.bis, a.von) + + tage_runtimes[tag].push({ + "name": a.name, + "raum": a.raum, + "runtime": runtime, + }); + } + } + + return tage_runtimes; +} + +function bufferUp(tage) { + tage = sortTage(tage); + + for (let tag in tage) { + if (tage[tag][0].von != "08:00") { + tage[tag].splice(0, 0, { + "name": "BUFFER", + "raum": "BUFFER", + "von": "08:00", + "bis": tage[tag][0].von, + }) + } + + if (tage[tag][tage[tag].length - 1].bis != "19:00") { + tage[tag].push({ + "name": "BUFFER", + "raum": "BUFFER", + "von": tage[tag][tage[tag].length - 1].bis, + "bis": "19:00", + }) + } + } + + for (let tag in tage) { + for (let eintrag in tage[tag]) { + if (eintrag == tage[tag].length - 1) break; + + let a = tage[tag][eintrag]; + let b = tage[tag][eintrag - -1]; + + let runtime = timediff(b.von, a.bis) + + if (runtime > 0) { + tage[tag].push({ + "name": "BUFFER", + "raum": "BUFFER", + "von": a.bis, + "bis": b.von, + }); + } + } + } + + return tage; +} + +class Eintrag { + constructor(name, termine) { + this.name = name; + this.termine = termine; + } +} + +class Termin { + constructor(wochentag, raum, von, bis) { + this.wochentag = wochentag; + this.raum = raum; + this.von = von; + this.bis = bis; + } +} + +const eintraege = [ + new Eintrag("GET 2 / Ü", [ + new Termin("Mo", "AM S4", "12:00", "13:00"), + new Termin("Fr", "AM S4", "11:30", "13:00") + ]), + new Eintrag("GET 2 / V", [ + new Termin("Di", "H1", "08:30", "10:00"), + new Termin("Do", "Z 1/2", "08:30", "10:00") + ]), + new Eintrag("TGI 1 / V", [ + new Termin("Mi", "AM 1", "08:15", "09:45"), + ]), + new Eintrag("TGI 1 / Ü", [ + new Termin("Do", "AM 1", "15:00", "16:00"), + ]), + new Eintrag("TGI 1 / Prak. Gr. 2", [ + new Termin("Di", "ITI 131", "14:30", "17:30"), + ]), + new Eintrag("Pho / V", [ + new Termin("Fr", "T 1", "08:30", "10:00"), + ]), + new Eintrag("Pho / Ü", [ + new Termin("Mi", "AM 1", "12:00", "13:00"), + ]), + new Eintrag("Ana 2 / V", [ + new Termin("Di", "AM 1", "12:30", "14:00"), + ]), + new Eintrag("Ana 2 / Ü", [ + new Termin("Do", "H 1", "16:15", "17:15"), + ]), + new Eintrag("Ana 2 / Helpdesk", [ + new Termin("Di", "O-Sync", "18:00", "19:00"), + new Termin("Mi", "O-Sync", "18:00", "19:00") + ]), + new Eintrag("EiBMO / V", [ + new Termin("Mi", "H 1", "14:00", "16:00"), + ]), + new Eintrag("EiBMO / Ü", [ + new Termin("Mi", "H 1", "16:00", "17:00"), + ]), + new Eintrag("FuQ / V", [ + new Termin("Fr", "AM 4", "10:00", "11:30"), + ]), + new Eintrag("FuQ / Ü", [ + new Termin("Di", "SI 4 (Minsky)", "11:00", "12:00"), + ]), + new Eintrag("BLOCKED", [ + new Termin("Mo", "BLOCKED", "13:00", "19:00"), + new Termin("Do", "BLOCKED", "10:00", "15:00") + ]) +]; + +const ctage = { + "Mo": [], + "Di": [], + "Mi": [], + "Do": [], + "Fr": [] +} + +export function main() { + let res = ""; + + let tage = structuredClone(ctage); + let tage_runtimes = structuredClone(ctage); + + for (let eintrag of eintraege) { + for (let termin of eintrag.termine) { + tage[termin.wochentag].push({ + "name": eintrag.name, + "raum": termin.raum, + "von": termin.von, + "bis": termin.bis, + }) + } + } + + tage = bufferUp(tage, ctage); + tage = sortTage(tage); + tage_runtimes = runtimes(tage, tage_runtimes) + + let timeout = {} + + // 1h has 4 15 minute intervalls: 08 to 19 means 44 intervalls + for (let i = 0; i < 44; i++) { + let mensa = ""; + + if (11 < i && i < 25) mensa = "mensa1"; + if (25 < i && i < 27) mensa = "mensa2"; + + res += `` + gettimefromintervalls(i) + + for (let day in tage_runtimes) { + if (timeout[day] > 0) { + timeout[day]--; + continue; + } + + let el = tage_runtimes[day][0]; + + if (el.name == "BLOCKED" && el.raum == "BLOCKED") { + res += ``; + } else { + let name = el.name == "BUFFER" ? "" : `
${el.name}`; + let raum = el.raum == "BUFFER" ? "" : `${el.raum}`; + + res += `${name}${raum}`; + } + + timeout[day] = el.runtime - 1; + tage_runtimes[day].splice(0, 1); + } + + res += "" + } + + // console.log(res) + + return res +} -- cgit v1.2.3