diff options
author | JoelHMikael <joel.h.kronqvist@gmail.com> | 2021-12-30 12:48:42 +0200 |
---|---|---|
committer | JoelHMikael <joel.h.kronqvist@gmail.com> | 2021-12-30 12:48:42 +0200 |
commit | 4c4f007130ff20691b9ac2f5fbf05ed5be3c9931 (patch) | |
tree | 709a8c52eee059f334132b8ab8cdc063f4525161 | |
parent | da0fc08fe5a7ee72914197ff4eebd42b397957f6 (diff) | |
download | LYLLRuoka-4c4f007130ff20691b9ac2f5fbf05ed5be3c9931.tar.gz LYLLRuoka-4c4f007130ff20691b9ac2f5fbf05ed5be3c9931.zip |
Example input
-rw-r--r-- | index.html | 2 | ||||
-rw-r--r-- | parse.js | 28 | ||||
-rw-r--r-- | server.js | 3 |
3 files changed, 32 insertions, 1 deletions
@@ -18,7 +18,7 @@ <form method="GET" class="float-block"> <label for="index" class="shadow">Opettaja, kurssi tai luokka:</label> <br> - <input type="text" name="index" placeholder="sahe // ÄI1.2 // B203"> + <input type="text" name="index" placeholder="\(example-input\)"> <img src="/help.png" class="info" alt="Siis häh?"> <span><p class="infoblock highlight">Syötä tähän kenttään yhdeltätoista alkavan tuntisi opettaja, kurssikoodi tai luokka. Älä syötä useampaa edellä mainituista, yksi on tarpeeksi.</p></span> <br> @@ -277,9 +277,37 @@ function getShift(day, index, db) // day: int, 1 = monday; index: string of cour return res; } +function randInt(start, stop) +{ + return start + Math.floor(Math.random() * (stop - start)); +} + +function getIndexes(db, day, shift, type) +{ + let d = db[day]; + let sh = Object.values(d)[shift][type]; + return Object.values(db[day])[shift][type]; +} + +function getRandomIndex(db, day = randInt(0, 5), shift = randInt(0, 3), type = randInt(0, 3)) +{ + let el; + let i = 0; + let indexes = getIndexes(db, day, shift, type); + while ((el === undefined) && (i < indexes.length)) + { + el = indexes[i]; + i++; + } + if (el == undefined) + return getRandomIndex(db); + return el; +} + exports.build = parseShift; exports.indexType = getIndexType; exports.classes = parseClasses; exports.get = getShift; exports.cluttered = parseCluttered; exports.find = findExpression; +exports.randomIndex = getRandomIndex; @@ -132,6 +132,9 @@ async function buildMain(args) if (res["shift"] === -1) res["shift"] = "Kurssilla/opettajalla/luokalla ei ole ruokailua päivällä tai kurssia ei ole olemassa!"; + // get the example input + res["example-input"] = parse.randomIndex(DB, day - 1); + // get the day let weekdays = ["su", "ma", "ti", "ke", "to", "pe", "la"]; res["day"] = weekdays[day]; |