Docker and stat script changes

This commit is contained in:
mrfry 2021-09-22 14:41:09 +02:00
parent 25963566ca
commit e17760a8db
5 changed files with 165 additions and 148 deletions

View file

@ -74,7 +74,8 @@ const filterFromDailyStats = [
'.xml',
'.aspx',
'/questionDbs/',
'/chatFiles/'
'/chatFiles/',
'rss'
]
// -----------------------------------------------------------------
@ -291,165 +292,180 @@ function pCols(cols, rowTitles, colorNames, firstRowColor) {
// ------------------------------------------------------------------------------
printHeader('Daily stats')
const dailyStats = readJSON(`${dir}stats/vstats`)
function preProcessDailyStats(obj) {
const formatted = Object.keys(obj).reduce((acc, key) => {
const includes = filterFromDailyStats.some((keyword) => {
return key.toLowerCase().includes(keyword.toLowerCase())
})
if (!includes) {
acc.push({ name: key.replace(/\.html/g, ''), val: obj[key] })
}
return acc
}, [])
const merged = formatted.reduce((acc, x) => {
const index = acc.findIndex((y) => {
return x.name === y.name
})
if (index !== -1) {
acc = acc.map((z, i) => {
if (i === index) {
return {
...x,
val: z.val + x.val,
}
}
return z
try {
const dailyStats = readJSON(`${dir}stats/vstats`)
function preProcessDailyStats(obj) {
const formatted = Object.keys(obj).reduce((acc, key) => {
const includes = filterFromDailyStats.some((keyword) => {
return key.toLowerCase().includes(keyword.toLowerCase())
})
} else {
acc.push(x)
}
if (!includes) {
acc.push({ name: key.replace(/\.html/g, ''), val: obj[key] })
}
return acc
}, [])
return acc
}, [])
const merged = formatted.reduce((acc, x) => {
const index = acc.findIndex((y) => {
return x.name === y.name
})
return merged.sort((a, b) => {
if (a.name > b.name) {
return 1
} else if (a.name < b.name) {
return -1
} else {
return 0
}
})
if (index !== -1) {
acc = acc.map((z, i) => {
if (i === index) {
return {
...x,
val: z.val + x.val,
}
}
return z
})
} else {
acc.push(x)
}
return acc
}, [])
return merged.sort((a, b) => {
if (a.name > b.name) {
return 1
} else if (a.name < b.name) {
return -1
} else {
return 0
}
})
}
function getDailyStat(day) {
return preProcessDailyStats(dailyStats[getDayIndex(day)])
}
pCols(
[
...[...Array(colsToPrint).keys()].map((x) => {
return getDailyStat(-x)
}),
],
null,
true
)
} catch (e) {
console.error(e)
}
function getDailyStat(day) {
return preProcessDailyStats(dailyStats[getDayIndex(day)])
}
pCols(
[
...[...Array(colsToPrint).keys()].map((x) => {
return getDailyStat(-x)
}),
],
null,
true
)
// ------------------------------------------------------------------------------
printHeader('User id test solving')
const userIdTestSolving = readJSON(`${dir}stats/idvstats`)
function preProcessUIdTestSolving(obj, minLength) {
if (!obj) {
return '0'
try {
const userIdTestSolving = readJSON(`${dir}stats/idvstats`)
function preProcessUIdTestSolving(obj, minLength) {
if (!obj) {
return '0'
}
if (minLength) {
return Object.keys(obj)
.filter((key) => {
return obj[key] > minLength
})
.length.toString()
} else {
return Object.keys(obj).length.toString()
}
}
if (minLength) {
return Object.keys(obj)
.filter((key) => {
return obj[key] > minLength
})
.length.toString()
} else {
return Object.keys(obj).length.toString()
function getUserIdTestSolving(day) {
return [
getDayName(day),
preProcessUIdTestSolving(userIdTestSolving[getDayIndex(day)]),
]
}
}
function getUserIdTestSolving(day) {
return [
getDayName(day),
preProcessUIdTestSolving(userIdTestSolving[getDayIndex(day)]),
]
}
pCols(
[
...[...Array(colsToPrint).keys()].map((x) => {
return getUserIdTestSolving(-x)
}),
],
null,
false,
'green'
)
pCols(
[
...[...Array(colsToPrint).keys()].map((x) => {
return getUserIdTestSolving(-x)
}),
],
null,
false,
'green'
)
} catch(e) {
console.error(e)
}
// ------------------------------------------------------------------------------
printHeader('User id requests')
const clientIdTestSolving = readJSON(`${dir}stats/uvstats`)
function getUserIdRequests(day) {
return [
getDayName(day),
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)]),
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)], 5),
]
}
try {
const clientIdTestSolving = readJSON(`${dir}stats/uvstats`)
function getUserIdRequests(day) {
return [
getDayName(day),
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)]),
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)], 5),
]
}
pCols(
[
...[...Array(colsToPrint).keys()].map((x) => {
return getUserIdRequests(-x)
}),
],
['', 'All', 'More than 5'],
false,
'green'
)
pCols(
[
...[...Array(colsToPrint).keys()].map((x) => {
return getUserIdRequests(-x)
}),
],
['', 'All', 'More than 5'],
false,
'green'
)
// ------------------------------------------------------------------------------
printHeader('Daily data count')
const dailyDataCount = readFile(`${dir}stats/dailyDataCount`)
function getDailyDataCount(count) {
return [...Array(count).keys()].map((x) => {
return JSON.parse(head(tail(dailyDataCount, x + 1), 1))
})
}
// ------------------------------------------------------------------------------
printHeader('Daily data count')
const dailyDataCount = readFile(`${dir}stats/dailyDataCount`)
function getDailyDataCount(count) {
return [...Array(count).keys()].map((x) => {
return JSON.parse(head(tail(dailyDataCount, x + 1), 1))
})
}
printLastDataCount(getDailyDataCount(colsToPrint))
printLastDataCount(getDailyDataCount(colsToPrint))
function printLastDataCount(data) {
const res = [...Array(colsToPrint).keys()].map((x) => {
return [getDayName(-x)]
})
data.forEach((dataCount, i) => {
res[i].push(dataCount.userCount.toString())
res[i].push(dataCount.subjectCount.toString())
res[i].push(dataCount.questionCount.toString())
})
function printLastDataCount(data) {
const res = [...Array(colsToPrint).keys()].map((x) => {
return [getDayName(-x)]
})
data.forEach((dataCount, i) => {
res[i].push(dataCount.userCount.toString())
res[i].push(dataCount.subjectCount.toString())
res[i].push(dataCount.questionCount.toString())
})
pCols(res, ['', 'Users', 'Subjects', 'Questions'], false, 'green')
pCols(res, ['', 'Users', 'Subjects', 'Questions'], false, 'green')
}
} catch(e) {
console.error(e)
}
// ------------------------------------------------------------------------------
printHeader('Daily script install / update check count')
function getDailyScriptStat(day) {
const log =
!day || day === 0
? readFile(`${dir}stats/vlogs/log`)
: readFile(`${dir}stats/vlogs/${getDayIndex(day)}`)
try {
function getDailyScriptStat(day) {
const log =
!day || day === 0
? readFile(`${dir}stats/vlogs/log`)
: readFile(`${dir}stats/vlogs/${getDayIndex(day)}`)
if (!log) {
return [getDayName(day), 0, 0]
if (!log) {
return [getDayName(day), 0, 0]
}
return [
getDayName(day),
countLinesMatching(log, '?install').toString(),
countLinesMatching(log, '?up').toString(),
]
}
return [
getDayName(day),
countLinesMatching(log, '?install').toString(),
countLinesMatching(log, '?up').toString(),
]
const installs = [...Array(colsToPrint).keys()].map((x) => {
return getDailyScriptStat(-x)
})
pCols(installs, ['', 'Installs', 'Updates'], false, 'green')
} catch(e) {
console.error(e)
}
const installs = [...Array(colsToPrint).keys()].map((x) => {
return getDailyScriptStat(-x)
})
pCols(installs, ['', 'Installs', 'Updates'], false, 'green')