mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2026-04-28 11:17:38 +02:00
prettier 4 tabwidth
This commit is contained in:
+89
-89
@@ -19,8 +19,8 @@
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
export default {
|
||||
LogId: LogId,
|
||||
Load: Load,
|
||||
LogId: LogId,
|
||||
Load: Load,
|
||||
}
|
||||
|
||||
import utils from '../utils/utils'
|
||||
@@ -35,113 +35,113 @@ let idvStatsData = {}
|
||||
let writes = 0
|
||||
|
||||
function Load(): void {
|
||||
try {
|
||||
idStatsData = utils.ReadJSON(idStatFile)
|
||||
} catch (err) {
|
||||
logger.Log(
|
||||
'Error at loading id logs! (@ first run its normal)',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.error(err)
|
||||
}
|
||||
try {
|
||||
idStatsData = utils.ReadJSON(idStatFile)
|
||||
} catch (err) {
|
||||
logger.Log(
|
||||
'Error at loading id logs! (@ first run its normal)',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
try {
|
||||
const prevVData = utils.ReadFile(idVStatFile)
|
||||
idvStatsData = JSON.parse(prevVData)
|
||||
} catch (err) {
|
||||
logger.Log(
|
||||
'Error at loading id logs! (@ first run its normal)',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.error(err)
|
||||
}
|
||||
try {
|
||||
const prevVData = utils.ReadFile(idVStatFile)
|
||||
idvStatsData = JSON.parse(prevVData)
|
||||
} catch (err) {
|
||||
logger.Log(
|
||||
'Error at loading id logs! (@ first run its normal)',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
function LogId(
|
||||
id: number,
|
||||
subj: string,
|
||||
newQuestions: number,
|
||||
allQuestions: number
|
||||
id: number,
|
||||
subj: string,
|
||||
newQuestions: number,
|
||||
allQuestions: number
|
||||
): void {
|
||||
Inc(id, subj, newQuestions, allQuestions)
|
||||
AddVisitStat(id, subj, newQuestions, allQuestions)
|
||||
Save()
|
||||
Inc(id, subj, newQuestions, allQuestions)
|
||||
AddVisitStat(id, subj, newQuestions, allQuestions)
|
||||
Save()
|
||||
}
|
||||
|
||||
function AddSubjToList(list: { [key: string]: any }, subj: string) {
|
||||
if (!list[subj]) {
|
||||
list[subj] = 0
|
||||
}
|
||||
list[subj]++
|
||||
if (!list[subj]) {
|
||||
list[subj] = 0
|
||||
}
|
||||
list[subj]++
|
||||
}
|
||||
|
||||
function Inc(
|
||||
value: number,
|
||||
subj: string,
|
||||
newQuestions: number,
|
||||
allQuestions: number
|
||||
value: number,
|
||||
subj: string,
|
||||
newQuestions: number,
|
||||
allQuestions: number
|
||||
) {
|
||||
if (idStatsData[value] === undefined) {
|
||||
idStatsData[value] = {
|
||||
count: 0,
|
||||
newQuestions: 0,
|
||||
allQuestions: 0,
|
||||
subjs: {},
|
||||
if (idStatsData[value] === undefined) {
|
||||
idStatsData[value] = {
|
||||
count: 0,
|
||||
newQuestions: 0,
|
||||
allQuestions: 0,
|
||||
subjs: {},
|
||||
}
|
||||
}
|
||||
}
|
||||
idStatsData[value].count++
|
||||
idStatsData[value].newQuestions += newQuestions
|
||||
idStatsData[value].allQuestions += allQuestions
|
||||
AddSubjToList(idStatsData[value].subjs, subj)
|
||||
idStatsData[value].count++
|
||||
idStatsData[value].newQuestions += newQuestions
|
||||
idStatsData[value].allQuestions += allQuestions
|
||||
AddSubjToList(idStatsData[value].subjs, subj)
|
||||
}
|
||||
|
||||
function AddVisitStat(
|
||||
name: number,
|
||||
subj: string,
|
||||
newQuestions: number,
|
||||
allQuestions: number
|
||||
name: number,
|
||||
subj: string,
|
||||
newQuestions: number,
|
||||
allQuestions: number
|
||||
) {
|
||||
const date = new Date()
|
||||
const now =
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||
'-' +
|
||||
('0' + date.getDate()).slice(-2)
|
||||
if (idvStatsData[now] === undefined) {
|
||||
idvStatsData[now] = {}
|
||||
}
|
||||
if (idvStatsData[now][name] === undefined) {
|
||||
idvStatsData[now][name] = {
|
||||
count: 0,
|
||||
newQuestions: 0,
|
||||
allQuestions: 0,
|
||||
subjs: {},
|
||||
const date = new Date()
|
||||
const now =
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||
'-' +
|
||||
('0' + date.getDate()).slice(-2)
|
||||
if (idvStatsData[now] === undefined) {
|
||||
idvStatsData[now] = {}
|
||||
}
|
||||
}
|
||||
idvStatsData[now][name].count++
|
||||
idvStatsData[now][name].newQuestions += newQuestions
|
||||
idvStatsData[now][name].allQuestions += allQuestions
|
||||
AddSubjToList(idvStatsData[now][name].subjs, subj)
|
||||
if (idvStatsData[now][name] === undefined) {
|
||||
idvStatsData[now][name] = {
|
||||
count: 0,
|
||||
newQuestions: 0,
|
||||
allQuestions: 0,
|
||||
subjs: {},
|
||||
}
|
||||
}
|
||||
idvStatsData[now][name].count++
|
||||
idvStatsData[now][name].newQuestions += newQuestions
|
||||
idvStatsData[now][name].allQuestions += allQuestions
|
||||
AddSubjToList(idvStatsData[now][name].subjs, subj)
|
||||
}
|
||||
|
||||
function Save() {
|
||||
writes++
|
||||
if (writes === writeInterval) {
|
||||
try {
|
||||
utils.WriteFile(JSON.stringify(idStatsData), idStatFile)
|
||||
// Log("Stats wrote.");
|
||||
} catch (err) {
|
||||
logger.Log('Error at writing logs!', logger.GetColor('redbg'))
|
||||
console.error(err)
|
||||
writes++
|
||||
if (writes === writeInterval) {
|
||||
try {
|
||||
utils.WriteFile(JSON.stringify(idStatsData), idStatFile)
|
||||
// Log("Stats wrote.");
|
||||
} catch (err) {
|
||||
logger.Log('Error at writing logs!', logger.GetColor('redbg'))
|
||||
console.error(err)
|
||||
}
|
||||
try {
|
||||
utils.WriteFile(JSON.stringify(idvStatsData), idVStatFile)
|
||||
// Log("Stats wrote.");
|
||||
} catch (err) {
|
||||
logger.Log('Error at writing visit logs!', logger.GetColor('redbg'))
|
||||
console.error(err)
|
||||
}
|
||||
writes = 0
|
||||
}
|
||||
try {
|
||||
utils.WriteFile(JSON.stringify(idvStatsData), idVStatFile)
|
||||
// Log("Stats wrote.");
|
||||
} catch (err) {
|
||||
logger.Log('Error at writing visit logs!', logger.GetColor('redbg'))
|
||||
console.error(err)
|
||||
}
|
||||
writes = 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user