mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Saving all/new questions added to idstats
This commit is contained in:
parent
01a8e83b3b
commit
b77a6bc0ad
2 changed files with 26 additions and 18 deletions
|
@ -142,7 +142,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
|
|||
let subjRow = '\t' + data.subj
|
||||
if (data.id) {
|
||||
subjRow += ' ( CID: ' + logger.logHashed(data.id) + ')'
|
||||
idStats.LogId(user.id, data.subj)
|
||||
idStats.LogId(user.id, data.subj, allQuestions.length, allQLength)
|
||||
}
|
||||
logger.Log(subjRow)
|
||||
if (data.version !== undefined) {
|
||||
|
|
|
@ -38,29 +38,29 @@ function Load() {
|
|||
try {
|
||||
var prevData = utils.ReadFile(idStatFile)
|
||||
data = JSON.parse(prevData)
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
logger.Log(
|
||||
'Error at loading id logs! (@ first run its normal)',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.log(e)
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
try {
|
||||
var prevVData = utils.ReadFile(idVStatFile)
|
||||
vData = JSON.parse(prevVData)
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
logger.Log(
|
||||
'Error at loading id logs! (@ first run its normal)',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.log(e)
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
function LogId(id, subj) {
|
||||
Inc(id, subj)
|
||||
AddVisitStat(id, subj)
|
||||
function LogId(id, subj, newQuestions, allQuestions) {
|
||||
Inc(id, subj, newQuestions, allQuestions)
|
||||
AddVisitStat(id, subj, newQuestions, allQuestions)
|
||||
Save()
|
||||
}
|
||||
|
||||
|
@ -71,35 +71,43 @@ function AddSubjToList(list, subj) {
|
|||
list[subj]++
|
||||
}
|
||||
|
||||
function Inc(value, subj) {
|
||||
function Inc(value, subj, newQuestions, allQuestions) {
|
||||
if (data[value] === undefined) {
|
||||
data[value] = {
|
||||
count: 0,
|
||||
newQuestions: 0,
|
||||
allQLength: 0,
|
||||
subjs: {},
|
||||
}
|
||||
}
|
||||
data[value].count++
|
||||
data[value].newQuestions += newQuestions
|
||||
data[value].allQuestions += allQuestions
|
||||
AddSubjToList(data[value].subjs, subj)
|
||||
}
|
||||
|
||||
function AddVisitStat(name, subj) {
|
||||
var m = new Date()
|
||||
function AddVisitStat(name, subj, newQuestions, allQuestions) {
|
||||
var date = new Date()
|
||||
const now =
|
||||
m.getFullYear() +
|
||||
date.getFullYear() +
|
||||
'/' +
|
||||
('0' + (m.getMonth() + 1)).slice(-2) +
|
||||
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||
'/' +
|
||||
('0' + m.getDate()).slice(-2)
|
||||
('0' + date.getDate()).slice(-2)
|
||||
if (vData[now] === undefined) {
|
||||
vData[now] = {}
|
||||
}
|
||||
if (vData[now][name] === undefined) {
|
||||
vData[now][name] = {
|
||||
count: 0,
|
||||
newQuestions: 0,
|
||||
allQLength: 0,
|
||||
subjs: {},
|
||||
}
|
||||
}
|
||||
vData[now][name].count++
|
||||
vData[now][name].newQuestions += newQuestions
|
||||
vData[now][name].allQuestions += allQuestions
|
||||
AddSubjToList(vData[now][name].subjs, subj)
|
||||
}
|
||||
|
||||
|
@ -109,16 +117,16 @@ function Save() {
|
|||
try {
|
||||
utils.WriteFile(JSON.stringify(data), idStatFile)
|
||||
// Log("Stats wrote.");
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
logger.Log('Error at writing logs!', logger.GetColor('redbg'))
|
||||
console.log(e)
|
||||
console.error(err)
|
||||
}
|
||||
try {
|
||||
utils.WriteFile(JSON.stringify(vData), idVStatFile)
|
||||
// Log("Stats wrote.");
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
logger.Log('Error at writing visit logs!', logger.GetColor('redbg'))
|
||||
console.log(e)
|
||||
console.error(err)
|
||||
}
|
||||
writes = 0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue