From 9c8fc9f997a42926dedffedaaead5bdd6e9fc96f Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 22 Jan 2022 20:54:27 +0200 Subject: Fixed bug in day mechanics for the food search Making monday first (0) instead of sunday was done twice, resulting with tuesday becoming first. --- server.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'server.js') 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('
', '