aboutsummaryrefslogtreecommitdiff
path: root/stunden.js
diff options
context:
space:
mode:
Diffstat (limited to 'stunden.js')
-rw-r--r--stunden.js227
1 files changed, 227 insertions, 0 deletions
diff --git a/stunden.js b/stunden.js
new file mode 100644
index 0000000..0bf3024
--- /dev/null
+++ b/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 `<th rowspan="4">${z}:00</th>`;
+
+ 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 += `<tr class="${mensa}">` + 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 += `<td rowspan="${el.runtime}" class="block"></td>`;
+ } else {
+ let name = el.name == "BUFFER" ? "" : `<div><span>${el.name}</span>`;
+ let raum = el.raum == "BUFFER" ? "" : `<span>${el.raum}</span>`;
+
+ res += `<td rowspan="${el.runtime}">${name}${raum}</td>`;
+ }
+
+ timeout[day] = el.runtime - 1;
+ tage_runtimes[day].splice(0, 1);
+ }
+
+ res += "</tr>"
+ }
+
+ // console.log(res)
+
+ return res
+}