aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-01-22 20:54:27 +0200
committerJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-01-22 20:54:27 +0200
commit9c8fc9f997a42926dedffedaaead5bdd6e9fc96f (patch)
tree2cd013c676cae7fae00762081451729591e33603
parent708996ed58f031fd31d7696a98adfc287db9905a (diff)
downloadLYLLRuoka-9c8fc9f997a42926dedffedaaead5bdd6e9fc96f.tar.gz
LYLLRuoka-9c8fc9f997a42926dedffedaaead5bdd6e9fc96f.zip
Fixed bug in day mechanics for the food search
Making monday first (0) instead of sunday was done twice, resulting with tuesday becoming first.
-rw-r--r--.gitignore3
-rw-r--r--README.md13
-rw-r--r--package.json3
-rw-r--r--server.js20
4 files changed, 33 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 1ca582b..6507360 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
Classes
node_modules
package-lock.json
-shifts.txt \ No newline at end of file
+shifts.txt
+funcs \ No newline at end of file
diff --git a/README.md b/README.md
index c593e02..4195255 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,7 @@ You will need a SSL certificate if you want to use https.
You need to install node.js and MySQL (+ npm install mysql2).
You will need to update the server with the help of the food shift message and a tab separated list of classes (just copypaste from excel from the Kurssitarjotin)
You probably want to set up cron to run some cronjobs from crontab_add.txt.
+Also, some of the code depends on the github repo JoelHMikael/funcs, so go ahead and clone them.
You need to provide the login info to the MySQL DB in ../dblogin.txt. Logging in as root was found problematic on Mint, but feel free to try if you want to.
You should create the following tables, because the server code wont do it for you.
@@ -33,3 +34,15 @@ CREATE TABLE devs (
description VARCHAR(128),
contact VARCHAR(40)
);
+CREATE TABLE stats (
+ start DATE PRIMARY KEY,
+ uptime INT,
+ requests INT,
+ requests_per_day INT
+);
+CREATE TABLE exams (
+ start DATE,
+ end DATE,
+ message VARCHAR(256),
+ PRIMARY KEY (start, end)
+); \ No newline at end of file
diff --git a/package.json b/package.json
index cad9a81..ff58a92 100644
--- a/package.json
+++ b/package.json
@@ -25,5 +25,8 @@
"homepage": "https://github.com/JoelHMikael/FoodJS#readme",
"dependencies": {
"mysql2": "^2.3.3"
+ },
+ "devDependencies": {
+ "jest": "^27.4.7"
}
}
diff --git a/server.js b/server.js
index b01b6de..046563f 100644
--- a/server.js
+++ b/server.js
@@ -97,8 +97,19 @@ async function init()
// stop server
async function closeServer() {
- const uptime = ((new Date()).getTime() - startDate.getTime()) / 1000;
- console.log(`Stats:\nServer uptime: ${uptime} s\nVisitor count: ${visitorCount}\nVisitors per day: ${visitorCount / (uptime / (24 * 60 * 60))}\n\nShutting down...`);
+
+ console.log("Updating stats to DB...")
+ const uptime = Math.ceil((((new Date()).getTime() - startDate.getTime()) / 1000) / (24 * 60 * 60));
+ const monthOfStart = `${startDate.getMonth() + 1}`.padStart(2, "0");
+ const monthDayOfStart = `${startDate.getDate()}`.padStart(2, "0");
+ await SQLDB.query("INSERT INTO stats VALUES (?, ?, ?, ?)", [
+ `${startDate.getFullYear()}-${monthOfStart}-${monthDayOfStart}`,
+ uptime,
+ visitorCount,
+ Math.round(visitorCount / uptime)
+ ]);
+ console.log("Done. Shutting down...");
+
await SQLDB.close();
console.log("MySQL closed");
runningServer.close();
@@ -159,8 +170,8 @@ async function buildMain(args)
// get valid day
const d = new Date();
let day = d.getDay();
- day = (day + +(day === 0) * 7) - 1;
- const actualDay = day + (+(day === 0) * 7);
+ day = (day + +(day === 0) * 7) - 1; // converts from 0 = sunday to 0 = monday
+ const actualDay = day;
day = +(!(day === 5) && !(day === 6)) * day;
if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) >= 0) && (parseInt(query.day) < 5))
day = parseInt(query.day);
@@ -215,7 +226,6 @@ async function buildMain(args)
data_string = data_string.replace('<div id="shift-result" class="float-block">', '<div id="shift-result" class="float-block" style="display: none;">');
// get the food
- day += (day === 0) * 7;
let food;
food = foods[ +(day < actualDay) ][day];
if (food !== undefined)