mirror of
https://github.com/ssyyhhrr/stewardle.git
synced 2025-11-08 10:33:46 -05:00
Metrics Tracking
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
driver.txt
|
driver.txt
|
||||||
drivers.json
|
drivers.json
|
||||||
|
.idea
|
||||||
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
7
.idea/discord.xml
generated
Normal file
7
.idea/discord.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="PROJECT_FILES" />
|
||||||
|
<option name="description" value="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/stewardle.iml" filepath="$PROJECT_DIR$/.idea/stewardle.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
.idea/stewardle.iml
generated
Normal file
12
.idea/stewardle.iml
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
40
app.js
40
app.js
@@ -5,8 +5,10 @@ const schedule = require("node-schedule")
|
|||||||
const express = require("express")
|
const express = require("express")
|
||||||
const favicon = require("serve-favicon")
|
const favicon = require("serve-favicon")
|
||||||
const morgan = require("morgan")
|
const morgan = require("morgan")
|
||||||
|
const dayjs = require("dayjs")
|
||||||
|
|
||||||
const path = "./assets/drivers.json"
|
const driversPath = "./assets/drivers.json"
|
||||||
|
const statsPath = "./assets/stats.json"
|
||||||
|
|
||||||
const flag = {
|
const flag = {
|
||||||
"British": "gb",
|
"British": "gb",
|
||||||
@@ -55,6 +57,11 @@ const team = {
|
|||||||
"Ferrari": "ferrari"
|
"Ferrari": "ferrari"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let stats = {
|
||||||
|
"visits": 0,
|
||||||
|
"guesses": 0
|
||||||
|
}
|
||||||
|
|
||||||
let drivers = {}
|
let drivers = {}
|
||||||
let driver
|
let driver
|
||||||
|
|
||||||
@@ -68,14 +75,24 @@ schedule.scheduleJob("0 0 * * *", async () => {
|
|||||||
dotd()
|
dotd()
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
console.log("API is unreachable! Not updating drivers...")
|
console.log("API is unreachable! Not updating drivers...")
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(driversPath)) {
|
||||||
let data = fs.readFileSync(path)
|
let data = fs.readFileSync(driversPath)
|
||||||
drivers = JSON.parse(data)
|
drivers = JSON.parse(data)
|
||||||
dotd()
|
dotd()
|
||||||
} else {
|
} else {
|
||||||
throw "Ergast API is unreachable and the drivers.json cache has not been built. Please try again when the Ergast API is online."
|
throw "Ergast API is unreachable and the drivers.json cache has not been built. Please try again when the Ergast API is online."
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
let rawStatsFile = fs.readFileSync(statsPath)
|
||||||
|
let statsFile = JSON.parse(rawStatsFile)
|
||||||
|
let date = dayjs.format("YYYY-MM-DD")
|
||||||
|
statsFile[date] = stats
|
||||||
|
let newStatsFile = JSON.stringify(statsFile)
|
||||||
|
fs.writeFileSync(statsPath, newStatsFile)
|
||||||
|
stats = {
|
||||||
|
"visits": 0,
|
||||||
|
"guesses": 0
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
@@ -84,9 +101,13 @@ async function main() {
|
|||||||
dotd()
|
dotd()
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
console.log("API is unreachable! Not updating drivers...")
|
console.log("API is unreachable! Not updating drivers...")
|
||||||
let data = fs.readFileSync(path)
|
if (fs.existsSync(driversPath)) {
|
||||||
drivers = JSON.parse(data)
|
let data = fs.readFileSync(driversPath)
|
||||||
dotd()
|
drivers = JSON.parse(data)
|
||||||
|
dotd()
|
||||||
|
} else {
|
||||||
|
throw "Ergast API is unreachable and the drivers.json cache has not been built. Please try again when the Ergast API is online."
|
||||||
|
}
|
||||||
})
|
})
|
||||||
server()
|
server()
|
||||||
}
|
}
|
||||||
@@ -164,6 +185,12 @@ function server() {
|
|||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.render("index")
|
res.render("index")
|
||||||
|
stats.visits++
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get("/stats", (req, res) => {
|
||||||
|
let rawStatsFile = fs.readFileSync(statsPath)
|
||||||
|
res.json(JSON.parse(rawStatsFile))
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get("/winner", (req, res) => {
|
app.get("/winner", (req, res) => {
|
||||||
@@ -222,6 +249,7 @@ function server() {
|
|||||||
"firstYear": response[4],
|
"firstYear": response[4],
|
||||||
"wins": response[5]
|
"wins": response[5]
|
||||||
})
|
})
|
||||||
|
stats.guesses++
|
||||||
})
|
})
|
||||||
|
|
||||||
let port = 3000
|
let port = 3000
|
||||||
|
|||||||
11
package-lock.json
generated
11
package-lock.json
generated
@@ -10,6 +10,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
|
"dayjs": "^1.11.7",
|
||||||
"ejs": "^3.1.8",
|
"ejs": "^3.1.8",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
@@ -233,6 +234,11 @@
|
|||||||
"node": ">=0.8"
|
"node": ">=0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/dayjs": {
|
||||||
|
"version": "1.11.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz",
|
||||||
|
"integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ=="
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
@@ -1177,6 +1183,11 @@
|
|||||||
"luxon": "^1.26.0"
|
"luxon": "^1.26.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dayjs": {
|
||||||
|
"version": "1.11.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz",
|
||||||
|
"integrity": "sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ=="
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
|
"dayjs": "^1.11.7",
|
||||||
"ejs": "^3.1.8",
|
"ejs": "^3.1.8",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
|||||||
Reference in New Issue
Block a user