From 0d8b9c462ea24a4569fec30cde3366153ab4b378 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Thu, 11 Apr 2024 19:33:03 +0200 Subject: making things a little more friendly --- src/main.js | 327 ++++++++++++++++++++++++++----------------------------- src/stunden.js | 227 -------------------------------------- src/variables.js | 143 ++++++++++++++++++++++++ 3 files changed, 299 insertions(+), 398 deletions(-) delete mode 100644 src/stunden.js create mode 100644 src/variables.js (limited to 'src') diff --git a/src/main.js b/src/main.js index 53323f3..cedd21d 100644 --- a/src/main.js +++ b/src/main.js @@ -1,10 +1,15 @@ 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(); +import * as v from './variables.js' + +let hinweise = "`; + +let date = new Date(); date = date.toLocaleDateString("de-DE", { weekday: 'long', year: 'numeric', @@ -23,184 +28,169 @@ let options = { }, }; -var table = ` - - 08:00 - - - - - - - - -
TGI 1 / VAM 1
- - - - - -
GET 2 / VH 1
-
GET 2 / VZ 1/2
-
Pho / VT 1
- - - - +// 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, + }) + } - - 09:00 - - - - - - - - - - - - + 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", + }) + } + } - - 10:00 - - - - -
FuQ / VAM 4
- - - - - - - - - - - - - - - - + for (let tag in tage) { + for (let eintrag in tage[tag]) { + if (eintrag == tage[tag].length - 1) break; - - 11:00 - -
FuQ / ÜSI 4 (Minsky)
- - - - - - - - - -
GET / ÜAM S4
- - - - - + let a = tage[tag][eintrag]; + let b = tage[tag][eintrag - -1]; - - 12:00 -
GET 2 / ÜAM S4
- -
Pho / ÜAM 1
- - - - - -
Ana 2 / VAM 1
- - - + let runtime = timediff(b.von, a.bis) - - 13:00 - - - - - - - - - - - - -`; + if (runtime > 0) { + tage[tag].push({ + "name": "BUFFER", + "raum": "BUFFER", + "von": a.bis, + "bis": b.von, + }); + } + } + } + + return tage; +} + +const ctage = { + "Mo": [], + "Di": [], + "Mi": [], + "Do": [], + "Fr": [] +} + +function main() { + let res = ""; + + let tage = structuredClone(ctage); + let tage_runtimes = structuredClone(ctage); + + for (let eintrag of v.eintraege) { + for (let termin of eintrag.termine) { + tage[termin.wochentag].push({ + "name": eintrag.name, + "raum": termin.raum, + "von": termin.von, + "bis": termin.bis, + }) + } + } -table = stu.main(); + tage = bufferUp(tage, ctage); + tage = sortTage(tage); + tage_runtimes = runtimes(tage, tage_runtimes) -var html = ` - -

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

+ return res +} + +let html = ` +${v.style} +

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

@@ -210,20 +200,15 @@ var html = ` - ${table} + ${main()}
Uhrzeit Donnerstag Freitag

Hinweise: - +${hinweise} `; fs.writeFileSync("test.html", html) html_to_pdf.generatePdf({content: html}, options).then(pdfBuffer => { - fs.writeFileSync('test.pdf', pdfBuffer); + fs.writeFileSync(v.filename, pdfBuffer); }); diff --git a/src/stunden.js b/src/stunden.js deleted file mode 100644 index 0bf3024..0000000 --- a/src/stunden.js +++ /dev/null @@ -1,227 +0,0 @@ -// 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 -} diff --git a/src/variables.js b/src/variables.js new file mode 100644 index 0000000..bf98ca1 --- /dev/null +++ b/src/variables.js @@ -0,0 +1,143 @@ +// Dont touch this +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; + } +} + +// You may touch this +export const student = "David Penkowoj"; +export const semester = "Sommersemester 2024"; +export const filename = `Stundenplan-${semester.replace(" ", "-")}.pdf`; + +export const hinweise = [ + "Mensabetrieb: 11:15 - 14:15 Uhr + 00:15 min", + "GET 2 / V am 23.05. & 04.07. im V1", + "GET 2 / Ü am 24.05. im T S2", + "FuQ / V am 24.05. im T S1", +]; + +export 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") + ]) +]; + +// You may touch this, if you know what you are doing +export const style = ` + +`; -- cgit v1.2.3