mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added sum to ranklist, simplified ranklist code a bit
This commit is contained in:
parent
1aa2dc656c
commit
c9df0fdce5
1 changed files with 37 additions and 39 deletions
|
@ -197,31 +197,12 @@ function GetApp() {
|
|||
|
||||
app.get('/ranklist', (req, res) => {
|
||||
logger.LogReq(req)
|
||||
let result
|
||||
let since = req.query.since
|
||||
const user = req.session.user
|
||||
|
||||
if (!since) {
|
||||
const data = utils.ReadJSON(idStatFile)
|
||||
const list = []
|
||||
|
||||
Object.keys(data).forEach((key) => {
|
||||
list.push({
|
||||
userId: parseInt(key),
|
||||
...data[key],
|
||||
})
|
||||
})
|
||||
|
||||
if (list.length === 0) {
|
||||
res.json({
|
||||
msg: 'There are no users in the stats db :c',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
res.json({
|
||||
list: list,
|
||||
selfuserId: user.id,
|
||||
})
|
||||
result = utils.ReadJSON(idStatFile)
|
||||
} else {
|
||||
try {
|
||||
since = new Date(since)
|
||||
|
@ -229,14 +210,14 @@ function GetApp() {
|
|||
throw new Error('Not a date')
|
||||
}
|
||||
const data = utils.ReadJSON(idvStatFile)
|
||||
const result = {}
|
||||
result = {}
|
||||
|
||||
Object.keys(data).forEach((key) => {
|
||||
const dayliStat = data[key]
|
||||
const dailyStat = data[key]
|
||||
|
||||
if (new Date(key) > since) {
|
||||
Object.keys(dayliStat).forEach((userId) => {
|
||||
const userStat = dayliStat[userId]
|
||||
Object.keys(dailyStat).forEach((userId) => {
|
||||
const userStat = dailyStat[userId]
|
||||
const uidRes = result[userId]
|
||||
|
||||
if (!uidRes) {
|
||||
|
@ -252,26 +233,43 @@ function GetApp() {
|
|||
})
|
||||
}
|
||||
})
|
||||
|
||||
const list = []
|
||||
Object.keys(result).forEach((key) => {
|
||||
list.push({
|
||||
userId: parseInt(key),
|
||||
...result[key],
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
since: since,
|
||||
list: list,
|
||||
selfuserId: user.id,
|
||||
})
|
||||
} catch (err) {
|
||||
res.json({
|
||||
msg: 'invalid date format, or other error occured',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const list = []
|
||||
const sum = {
|
||||
count: 0,
|
||||
newQuestions: 0,
|
||||
allQuestions: 0,
|
||||
}
|
||||
Object.keys(result).forEach((key) => {
|
||||
list.push({
|
||||
userId: parseInt(key),
|
||||
...result[key],
|
||||
})
|
||||
|
||||
sum.count = sum.count + result[key].count
|
||||
sum.newQuestions = sum.newQuestions + result[key].newQuestions
|
||||
sum.allQuestions = sum.allQuestions + result[key].allQuestions
|
||||
})
|
||||
|
||||
if (list.length === 0) {
|
||||
res.json({
|
||||
msg: 'There are no users in the stats db :c',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
res.json({
|
||||
since: since,
|
||||
sum: sum,
|
||||
list: list,
|
||||
selfuserId: user.id,
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/quickvote', (req, res) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue