mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Server stats now fills console width
This commit is contained in:
parent
e0a58f514b
commit
5192acfd90
1 changed files with 112 additions and 107 deletions
|
@ -8,12 +8,10 @@ const colWidth = 40
|
||||||
const maxStatLength = colWidth // Math.floor(cols / 4)
|
const maxStatLength = colWidth // Math.floor(cols / 4)
|
||||||
const statNameSpacing = 4
|
const statNameSpacing = 4
|
||||||
const beforeRowSpace = 13
|
const beforeRowSpace = 13
|
||||||
const rowsToPrint = Math.floor(cols / (colWidth + statNameSpacing + beforeRowSpace / 3 + 5)) || 1
|
const colsToPrint =
|
||||||
|
Math.floor(cols / (colWidth + statNameSpacing + beforeRowSpace / 3 + 5)) || 1
|
||||||
const coloredWords = {
|
const coloredWords = {
|
||||||
red: [
|
red: ['lred', 'thanks'],
|
||||||
'lred',
|
|
||||||
'thanks'
|
|
||||||
],
|
|
||||||
cyan: [
|
cyan: [
|
||||||
'getveteranpw',
|
'getveteranpw',
|
||||||
'pwrequest',
|
'pwrequest',
|
||||||
|
@ -39,7 +37,7 @@ const coloredWords = {
|
||||||
'contacts.json',
|
'contacts.json',
|
||||||
'patreon',
|
'patreon',
|
||||||
'donate',
|
'donate',
|
||||||
'userfiles'
|
'userfiles',
|
||||||
],
|
],
|
||||||
blue: [
|
blue: [
|
||||||
'isadding',
|
'isadding',
|
||||||
|
@ -52,12 +50,7 @@ const coloredWords = {
|
||||||
'registerscript',
|
'registerscript',
|
||||||
'install',
|
'install',
|
||||||
],
|
],
|
||||||
magenta: [
|
magenta: ['addPost', 'comment', 'postfeedback', 'quickvote'],
|
||||||
'addPost',
|
|
||||||
'comment',
|
|
||||||
'postfeedback',
|
|
||||||
'quickvote',
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
const filterFromDailyStats = [
|
const filterFromDailyStats = [
|
||||||
'savedQuestions',
|
'savedQuestions',
|
||||||
|
@ -162,10 +155,7 @@ function tail(text, number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function head(text, number) {
|
function head(text, number) {
|
||||||
return text
|
return text.split('\n').slice(0, number).join('\n')
|
||||||
.split('\n')
|
|
||||||
.slice(0, number)
|
|
||||||
.join('\n')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function countLinesMatching(text, toMatch) {
|
function countLinesMatching(text, toMatch) {
|
||||||
|
@ -178,6 +168,20 @@ function countLinesMatching(text, toMatch) {
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDayName(day) {
|
||||||
|
switch (day) {
|
||||||
|
case 0:
|
||||||
|
case undefined:
|
||||||
|
return 'Today'
|
||||||
|
case -1:
|
||||||
|
return 'Yesterday'
|
||||||
|
case -2:
|
||||||
|
return 'Before yesterday'
|
||||||
|
default:
|
||||||
|
return `Day ${day.toString()}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function readFile(name) {
|
function readFile(name) {
|
||||||
if (fs.existsSync(name)) {
|
if (fs.existsSync(name)) {
|
||||||
return fs.readFileSync(name, 'utf8')
|
return fs.readFileSync(name, 'utf8')
|
||||||
|
@ -196,7 +200,7 @@ function pCols(cols, rowTitles, colorNames, firstRowColor) {
|
||||||
// console.log(cols)
|
// console.log(cols)
|
||||||
let maxLength = 0
|
let maxLength = 0
|
||||||
cols.reverse().forEach((col, i) => {
|
cols.reverse().forEach((col, i) => {
|
||||||
if (i >= rowsToPrint) {
|
if (i >= colsToPrint) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (col.length > maxLength) {
|
if (col.length > maxLength) {
|
||||||
|
@ -209,54 +213,53 @@ function pCols(cols, rowTitles, colorNames, firstRowColor) {
|
||||||
for (let i = 0; i < maxLength; i++) {
|
for (let i = 0; i < maxLength; i++) {
|
||||||
const row = []
|
const row = []
|
||||||
|
|
||||||
cols
|
cols.forEach((val, colIndex) => {
|
||||||
.forEach((val, colIndex) => {
|
if (colIndex >= colsToPrint) {
|
||||||
if (colIndex >= rowsToPrint) {
|
return
|
||||||
return
|
}
|
||||||
}
|
if (!val[i]) {
|
||||||
if (!val[i]) {
|
row.push(getLetterNTimes(' ', maxStatLength + statNameSpacing + 2))
|
||||||
row.push(getLetterNTimes(' ', maxStatLength + statNameSpacing + 2))
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const keyName = val[i].name || val[i]
|
const keyName = val[i].name || val[i]
|
||||||
|
|
||||||
let slicedName = keyName.slice(0, maxStatLength)
|
let slicedName = keyName.slice(0, maxStatLength)
|
||||||
const toColor = colorNames
|
const toColor = colorNames
|
||||||
? Object.keys(coloredWords).reduce((acc, key) => {
|
? Object.keys(coloredWords).reduce((acc, key) => {
|
||||||
const colorArray = coloredWords[key]
|
const colorArray = coloredWords[key]
|
||||||
|
|
||||||
const includes = colorArray.some((colorableIdName) => {
|
const includes = colorArray.some((colorableIdName) => {
|
||||||
return keyName
|
return keyName
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.includes(colorableIdName.toLowerCase())
|
.includes(colorableIdName.toLowerCase())
|
||||||
})
|
})
|
||||||
|
|
||||||
if (includes) {
|
if (includes) {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
return acc
|
return acc
|
||||||
}, '')
|
}, '')
|
||||||
: false
|
: false
|
||||||
|
|
||||||
const sep = (i + 1) % 5 === 0 ? '.' : ' '
|
const sep = (i + 1) % 5 === 0 ? '.' : ' '
|
||||||
|
|
||||||
while (slicedName.length < maxStatLength) {
|
while (slicedName.length < maxStatLength) {
|
||||||
slicedName = slicedName + sep
|
slicedName = slicedName + sep
|
||||||
}
|
}
|
||||||
|
|
||||||
let ammount = val[i].val ? val[i].val.toString() : ''
|
let ammount = val[i].val ? val[i].val.toString() : ''
|
||||||
while (ammount.length < 5) {
|
while (ammount.length < 5) {
|
||||||
ammount = ammount + ' '
|
ammount = ammount + ' '
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toColor) {
|
if (toColor) {
|
||||||
row.push(C(toColor) + slicedName + ' ' + ammount + C())
|
row.push(C(toColor) + slicedName + ' ' + ammount + C())
|
||||||
} else {
|
} else {
|
||||||
row.push(slicedName + ' ' + ammount)
|
row.push(slicedName + ' ' + ammount)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// ROW TITLE ---------------------------------------------------
|
// ROW TITLE ---------------------------------------------------
|
||||||
let currRowTitle =
|
let currRowTitle =
|
||||||
|
@ -309,7 +312,7 @@ function preProcessDailyStats(obj) {
|
||||||
if (i === index) {
|
if (i === index) {
|
||||||
return {
|
return {
|
||||||
...x,
|
...x,
|
||||||
val: z.val + x.val
|
val: z.val + x.val,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return z
|
return z
|
||||||
|
@ -331,12 +334,15 @@ function preProcessDailyStats(obj) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function getDailyStat(day) {
|
||||||
|
return preProcessDailyStats(dailyStats[getDayIndex(day)])
|
||||||
|
}
|
||||||
|
|
||||||
pCols(
|
pCols(
|
||||||
[
|
[
|
||||||
preProcessDailyStats(dailyStats[getDayIndex()]),
|
...[...Array(colsToPrint).keys()].map((x) => {
|
||||||
preProcessDailyStats(dailyStats[getDayIndex(-1)]),
|
return getDailyStat(-x)
|
||||||
preProcessDailyStats(dailyStats[getDayIndex(-2)]),
|
}),
|
||||||
],
|
],
|
||||||
null,
|
null,
|
||||||
true
|
true
|
||||||
|
@ -359,15 +365,18 @@ function preProcessUIdTestSolving(obj, minLength) {
|
||||||
return Object.keys(obj).length.toString()
|
return Object.keys(obj).length.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function getUserIdTestSolving(day) {
|
||||||
|
return [
|
||||||
|
getDayName(day),
|
||||||
|
preProcessUIdTestSolving(userIdTestSolving[getDayIndex(day)]),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
pCols(
|
pCols(
|
||||||
[
|
[
|
||||||
['Today', preProcessUIdTestSolving(userIdTestSolving[getDayIndex()])],
|
...[...Array(colsToPrint).keys()].map((x) => {
|
||||||
['Yesterday', preProcessUIdTestSolving(userIdTestSolving[getDayIndex(-1)])],
|
return getUserIdTestSolving(-x)
|
||||||
[
|
}),
|
||||||
'Before yesterday',
|
|
||||||
preProcessUIdTestSolving(userIdTestSolving[getDayIndex(-2)]),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
|
@ -377,24 +386,19 @@ pCols(
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
printHeader('User id requests')
|
printHeader('User id requests')
|
||||||
const clientIdTestSolving = readJSON(`${dir}stats/uvstats`)
|
const clientIdTestSolving = readJSON(`${dir}stats/uvstats`)
|
||||||
|
function getUserIdRequests(day) {
|
||||||
|
return [
|
||||||
|
getDayName(day),
|
||||||
|
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)]),
|
||||||
|
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)], 5),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
pCols(
|
pCols(
|
||||||
[
|
[
|
||||||
[
|
...[...Array(colsToPrint).keys()].map((x) => {
|
||||||
'Today',
|
return getUserIdRequests(-x)
|
||||||
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex()]),
|
}),
|
||||||
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex()], 5),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'Yesterday',
|
|
||||||
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(-1)]),
|
|
||||||
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(-1)], 5),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'Before Yesterday',
|
|
||||||
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(-2)]),
|
|
||||||
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(-2)], 5),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
['', 'All', 'More than 5'],
|
['', 'All', 'More than 5'],
|
||||||
false,
|
false,
|
||||||
|
@ -404,15 +408,18 @@ pCols(
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
printHeader('Daily data count')
|
printHeader('Daily data count')
|
||||||
const dailyDataCount = readFile(`${dir}stats/dailyDataCount`)
|
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([
|
printLastDataCount(getDailyDataCount(colsToPrint))
|
||||||
JSON.parse(head(tail(dailyDataCount, 1), 1)),
|
|
||||||
JSON.parse(head(tail(dailyDataCount, 2), 1)),
|
|
||||||
JSON.parse(head(tail(dailyDataCount, 3), 1)),
|
|
||||||
])
|
|
||||||
|
|
||||||
function printLastDataCount(data) {
|
function printLastDataCount(data) {
|
||||||
const res = [['Today'], ['Yesterday'], ['Before yesterday']]
|
const res = [...Array(colsToPrint).keys()].map((x) => {
|
||||||
|
return [getDayName(-x)]
|
||||||
|
})
|
||||||
data.forEach((dataCount, i) => {
|
data.forEach((dataCount, i) => {
|
||||||
res[i].push(dataCount.userCount.toString())
|
res[i].push(dataCount.userCount.toString())
|
||||||
res[i].push(dataCount.subjectCount.toString())
|
res[i].push(dataCount.subjectCount.toString())
|
||||||
|
@ -423,26 +430,24 @@ function printLastDataCount(data) {
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
printHeader('Daily script install / update check count')
|
printHeader('Daily script install / update check count')
|
||||||
const todaysLogs = readFile(`${dir}stats/vlogs/log`)
|
function getDailyScriptStat(day) {
|
||||||
const yesterdaysLogs = readFile(`${dir}stats/vlogs/${getDayIndex(-1)}`) || ''
|
const log =
|
||||||
const beforeYesterdaysLogs = readFile(`${dir}stats/vlogs/${getDayIndex(-2)}`) || ''
|
!day || day === 0
|
||||||
|
? readFile(`${dir}stats/vlogs/log`)
|
||||||
|
: readFile(`${dir}stats/vlogs/${getDayIndex(day)}`)
|
||||||
|
|
||||||
const installs = [
|
if (!log) {
|
||||||
[
|
return [getDayName(day), 0, 0]
|
||||||
'Today',
|
}
|
||||||
countLinesMatching(todaysLogs, '?install').toString(),
|
return [
|
||||||
countLinesMatching(todaysLogs, '?up').toString(),
|
getDayName(day),
|
||||||
],
|
countLinesMatching(log, '?install').toString(),
|
||||||
[
|
countLinesMatching(log, '?up').toString(),
|
||||||
'Yesterday',
|
]
|
||||||
countLinesMatching(yesterdaysLogs, '?install').toString(),
|
}
|
||||||
countLinesMatching(yesterdaysLogs, '?up').toString(),
|
|
||||||
],
|
const installs = [...Array(colsToPrint).keys()].map((x) => {
|
||||||
[
|
return getDailyScriptStat(-x)
|
||||||
'Before yesterday',
|
})
|
||||||
countLinesMatching(beforeYesterdaysLogs, '?install').toString(),
|
|
||||||
countLinesMatching(beforeYesterdaysLogs, '?up').toString(),
|
|
||||||
],
|
|
||||||
]
|
|
||||||
|
|
||||||
pCols(installs, ['', 'Installs', 'Updates'], false, 'green')
|
pCols(installs, ['', 'Installs', 'Updates'], false, 'green')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue