mirror of
https://github.com/ssyyhhrr/stewardle.git
synced 2025-11-17 14:23:40 -05:00
Debug Removal
This commit is contained in:
34
app.js
34
app.js
@@ -149,67 +149,48 @@ async function updateDrivers() {
|
|||||||
|
|
||||||
function processStats(dotd = false) {
|
function processStats(dotd = false) {
|
||||||
const date = dayjs().format("YYYY-MM-DD");
|
const date = dayjs().format("YYYY-MM-DD");
|
||||||
console.log(`[DEBUG] processStats Date is ${date}`)
|
|
||||||
|
|
||||||
let statsFile = {};
|
let statsFile = {};
|
||||||
if (fs.existsSync(statsPath)) {
|
if (fs.existsSync(statsPath)) {
|
||||||
statsFile = JSON.parse(fs.readFileSync(statsPath));
|
statsFile = JSON.parse(fs.readFileSync(statsPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[DEBUG] statsFile ${statsFile}`)
|
if (statsFile.hasOwnProperty(date)) {
|
||||||
|
|
||||||
if (dotd) {
|
|
||||||
console.log(`[DEBUG] dotd TRUE`)
|
|
||||||
statsFile[date] = {
|
|
||||||
visits: stats.visits,
|
|
||||||
guesses: stats.guesses,
|
|
||||||
driver: stats.driver,
|
|
||||||
};
|
|
||||||
console.log(`[DEBUG] statsFile[date] ${statsFile[date]}`)
|
|
||||||
|
|
||||||
} else if (statsFile.hasOwnProperty(date)) {
|
|
||||||
console.log(`[DEBUG] statsFile.hasOwnProperty(date) TRUE`)
|
|
||||||
if (statsFile[date].visits > stats.visits) {
|
if (statsFile[date].visits > stats.visits) {
|
||||||
console.log(`[DEBUG] statsFile[date].visits > stats.visits`)
|
|
||||||
statsFile[date].visits += stats.visits
|
statsFile[date].visits += stats.visits
|
||||||
stats.visits = statsFile[date].visits
|
stats.visits = statsFile[date].visits
|
||||||
}
|
}
|
||||||
else statsFile[date].visits = stats.visits
|
else statsFile[date].visits = stats.visits
|
||||||
if (statsFile[date].guesses > stats.guesses) {
|
if (statsFile[date].guesses > stats.guesses) {
|
||||||
console.log(`[DEBUG] statsFile[date].guesses > stats.guesses`)
|
|
||||||
statsFile[date].guesses += stats.guesses
|
statsFile[date].guesses += stats.guesses
|
||||||
stats.guesses = statsFile[date].guesses
|
stats.guesses = statsFile[date].guesses
|
||||||
}
|
}
|
||||||
else statsFile[date].guesses = stats.guesses
|
else statsFile[date].guesses = stats.guesses
|
||||||
|
} else if (dotd) {
|
||||||
|
statsFile[date] = {
|
||||||
|
"driver": stats.driver
|
||||||
|
}
|
||||||
} else return
|
} else return
|
||||||
|
|
||||||
console.log(`[DEBUG] Writing ${statsFile} to ${statsPath}`)
|
|
||||||
fs.writeFileSync(statsPath, JSON.stringify(statsFile));
|
fs.writeFileSync(statsPath, JSON.stringify(statsFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
function dotd() {
|
function dotd() {
|
||||||
console.log("Selecting Driver of the Day...")
|
console.log("Selecting Driver of the Day...")
|
||||||
let date = dayjs().format("YYYY-MM-DD")
|
let date = dayjs().format("YYYY-MM-DD")
|
||||||
console.log(`dotd Date is ${date}`)
|
|
||||||
let pastDrivers = []
|
let pastDrivers = []
|
||||||
let pastDates = []
|
let pastDates = []
|
||||||
if (fs.existsSync(statsPath)) {
|
if (fs.existsSync(statsPath)) {
|
||||||
let statsFile = JSON.parse(fs.readFileSync(statsPath))
|
let statsFile = JSON.parse(fs.readFileSync(statsPath))
|
||||||
pastDates = Object.keys(statsFile)
|
pastDates = Object.keys(statsFile)
|
||||||
pastDrivers = Object.values(statsFile).map(x => x.driver).filter((x) => { return typeof x === "string"})
|
pastDrivers = Object.values(statsFile).map(x => x.driver).filter((x) => { return typeof x === "string"})
|
||||||
console.log(`[DEBUG] pastDates ${pastDates}`)
|
|
||||||
console.log(`[DEBUG] pastDrivers ${pastDrivers}`)
|
|
||||||
}
|
}
|
||||||
if (pastDrivers.length > 0 && pastDates.length > 0 && pastDates[pastDates.length - 1] === date) {
|
if (pastDrivers.length > 0 && pastDates.length > 0 && pastDates[pastDates.length - 1] === date) {
|
||||||
console.log(`[DEBUG] Date is TODAY`)
|
|
||||||
driver = pastDrivers[pastDrivers.length - 1]
|
driver = pastDrivers[pastDrivers.length - 1]
|
||||||
console.log(`[DEBUG] driver ${driver}`)
|
|
||||||
} else {
|
} else {
|
||||||
let newDriver = getRandomProperty(drivers)
|
let newDriver = getRandomProperty(drivers)
|
||||||
console.log(`[DEBUG] newDriver ${newDriver}`)
|
while (pastDrivers.slice(-7).includes(newDriver)) {
|
||||||
if (pastDrivers.slice(-7).includes(newDriver)) {
|
newDriver = getRandomProperty(drivers)
|
||||||
console.log("Driver was picked recently, re-selecting...")
|
|
||||||
return dotd()
|
|
||||||
}
|
}
|
||||||
driver = newDriver
|
driver = newDriver
|
||||||
}
|
}
|
||||||
@@ -218,7 +199,6 @@ function dotd() {
|
|||||||
"guesses": 0,
|
"guesses": 0,
|
||||||
"driver": driver
|
"driver": driver
|
||||||
}
|
}
|
||||||
console.log(`[DEBUG] stats ${stats}`)
|
|
||||||
processStats(true)
|
processStats(true)
|
||||||
console.log(`Driver of the Day is ${driver}!`)
|
console.log(`Driver of the Day is ${driver}!`)
|
||||||
console.log(drivers[driver])
|
console.log(drivers[driver])
|
||||||
|
|||||||
Reference in New Issue
Block a user