From 4c4f007130ff20691b9ac2f5fbf05ed5be3c9931 Mon Sep 17 00:00:00 2001 From: JoelHMikael Date: Thu, 30 Dec 2021 12:48:42 +0200 Subject: Example input --- index.html | 2 +- parse.js | 28 ++++++++++++++++++++++++++++ server.js | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 4b6a503..b66abad 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@

- + Siis häh?

Syötä tähän kenttään yhdeltätoista alkavan tuntisi opettaja, kurssikoodi tai luokka. Älä syötä useampaa edellä mainituista, yksi on tarpeeksi.


diff --git a/parse.js b/parse.js index 7c47423..c3b7684 100644 --- a/parse.js +++ b/parse.js @@ -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; diff --git a/server.js b/server.js index 2f45e95..d3c8838 100644 --- a/server.js +++ b/server.js @@ -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]; -- cgit v1.2.3