From c90c879fc016b8afb42ab4af84b4e9a68b02eb81 Mon Sep 17 00:00:00 2001 From: mrfry Date: Fri, 23 Oct 2020 12:01:11 +0200 Subject: [PATCH] Ranklist logging --- .eslintrc.js | 2 +- scripts/serverStats.sh | 134 +++++++++++++++++++--------------------- src/modules/api/api.js | 1 + submodules/qmining-page | 2 +- 4 files changed, 68 insertions(+), 71 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ed5c981..5dda5f1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,6 +16,6 @@ module.exports = { eqeqeq: ['warn', 'smart'], 'no-unused-vars': 'warn', 'no-prototype-builtins': 'off', - 'id-length': ['warn', { exceptions: ['i', 'j', 't', 'Q', 'A', 'C', 'q'] }], + 'id-length': ['warn', { exceptions: ['i', 'j', 't', 'Q', 'A', 'C', 'q', 'a', 'b'] }], }, } diff --git a/scripts/serverStats.sh b/scripts/serverStats.sh index bba4798..0e040ab 100755 --- a/scripts/serverStats.sh +++ b/scripts/serverStats.sh @@ -18,80 +18,75 @@ P='' C='' sep="${P}----------------------------------------------------------------------------------------------------------------------------<=$NC" -pcolumns () { - mlength=35 - NUM=0; - l=$(echo $"$1" | wc -l) - sizeof2=$(echo $"$2" | wc -l) - sizeof3=$(echo $"$3" | wc -l) +pcolumns() { + mlength=35 + NUM=0 + l=$(echo $"$1" | wc -l) + sizeof2=$(echo $"$2" | wc -l) + sizeof3=$(echo $"$3" | wc -l) - if [ "$l" -lt "$sizeof2" ]; then - l=$(echo $"$2" | wc -l) - fi - if [ "$l" -lt "$sizeof3" ]; then - l=$(echo $"$3" | wc -l) - fi + if [ "$l" -lt "$sizeof2" ]; then + l=$(echo $"$2" | wc -l) + fi + if [ "$l" -lt "$sizeof3" ]; then + l=$(echo $"$3" | wc -l) + fi - for i in $( eval echo {0..$l} ) - do - line=$(echo -ne $"$1" | cut -d$'\n' -f $(($NUM+1))) - sliced="${line:0:$mlength}" - last="${line: -3}" - size=${#sliced} - diff=$(($mlength-$size)) + for i in $(eval echo {0..$l}); do + line=$(echo -ne $"$1" | cut -d$'\n' -f $(($NUM + 1))) + sliced="${line:0:$mlength}" + last="${line: -3}" + size=${#sliced} + diff=$(($mlength - $size)) - if [ "$sliced" == "null" ]; then - echo -en "\t" - else - echo -en "\t$sliced" - fi - if [ "$diff" -gt "0" ]; then - diff=$((diff+2)) - for j in $( eval echo {0..$diff} ) - do - echo -n " " - done - else - echo -en "$last" - fi + if [ "$sliced" == "null" ]; then + echo -en "\t" + else + echo -en "\t$sliced" + fi + if [ "$diff" -gt "0" ]; then + diff=$((diff + 2)) + for j in $(eval echo {0..$diff}); do + echo -n " " + done + else + echo -en "$last" + fi - sr=$(echo -ne $"$2" | cut -d$'\n' -f $(($NUM+1))) - r=$"${sr:0:$mlength}" - last="${r: -3}" - size=${#r} - diff=$(($mlength-$size)) - if [ "$r" == "null" ]; then - echo -ne '' - else - echo -ne "$r" - fi + sr=$(echo -ne $"$2" | cut -d$'\n' -f $(($NUM + 1))) + r=$"${sr:0:$mlength}" + last="${r: -3}" + size=${#r} + diff=$(($mlength - $size)) + if [ "$r" == "null" ]; then + echo -ne '' + else + echo -ne "$r" + fi + if [ "$diff" -gt "0" ]; then + diff=$((diff + 2)) + for j in $(eval echo {0..$diff}); do + echo -n " " + done + else + echo -en "$last" + fi - if [ "$diff" -gt "0" ]; then - diff=$((diff+2)) - for j in $( eval echo {0..$diff} ) - do - echo -n " " - done - else - echo -en "$last" - fi + tr=$(echo -ne $"$3" | cut -d$'\n' -f $(($NUM + 1))) + r=$"${tr:0:$mlength}" + if [ "$r" == "null" ]; then + echo '' + else + echo "$r" + fi - tr=$(echo -ne $"$3" | cut -d$'\n' -f $(($NUM+1))) - r=$"${tr:0:$mlength}" - - if [ "$r" == "null" ]; then - echo '' - else - echo "$r" - fi - - NUM=$((NUM+1)) - done + NUM=$((NUM + 1)) + done } -function jsonStats () { +function jsonStats() { dateind=$(date '+%Y/%m/%d') a=$(cat "$1" | jq ".[\"$dateind\"]" | grep -ve '^{' | grep -ve '}$' | grep -ve '^\s*}' | sort) ac=$(cat "$1" | jq ".[\"$dateind\"] | length") @@ -125,7 +120,7 @@ function jsonStats () { -e "s,/addQuestion,${G}&${NC},g" \ -e "s,/dataCount,${G}&${NC},g" \ -e "s,/menuClick,${G}&${NC},g" \ - -e "s,/allqr,${G}&${NC},g" \ + -e "s,/ranklist,${G}&${NC},g" \ -e "s,/uploaddata,${G}&${NC},g" \ -e "s,/legacy,${G}&${NC},g" \ -e "s,/donate,${P}&${NC},g" \ @@ -140,10 +135,11 @@ function jsonStats () { -e "s,/lred,${R}&${NC},g" \ -e "s,/thanks,${R}&${NC},g" \ -e "s,/isAdding,${B}&${NC},g" \ + -e "s,/allqr,${B}&${NC},g" \ -e "s,/ask,${B}&${NC},g" } -function jsonStatsLength () { +function jsonStatsLength() { dateind=$(date '+%Y/%m/%d') ac=$(cat "$1" | jq ".[\"$dateind\"] | length") a="\t${ac}\n" @@ -184,9 +180,9 @@ sy=$(cat "${1}/stats/dailyDataCount" | tail -n 3 | head -n 1 | jq '.subjectCount qy=$(cat "${1}/stats/dailyDataCount" | tail -n 3 | head -n 1 | jq '.questionCount') uy=$(cat "${1}/stats/dailyDataCount" | tail -n 3 | head -n 1 | jq '.userCount') -sd=$((s-st)) -qd=$((q-qt)) -ud=$((u-ut)) +sd=$((s - st)) +qd=$((q - qt)) +ud=$((u - ut)) echo -e "Users:\t\t${G}${uy}${NC}\t\t\t\t\t${G}${ut}${NC}\t\t\t\t\t${G}${u}${NC}\t+${B}${ud}${NC}" echo -e "Subjects:\t${G}${sy}${NC}\t\t\t\t\t${G}${st}${NC}\t\t\t\t\t${G}${s}${NC}\t+${B}${sd}${NC}" diff --git a/src/modules/api/api.js b/src/modules/api/api.js index 032e627..10f7f47 100644 --- a/src/modules/api/api.js +++ b/src/modules/api/api.js @@ -163,6 +163,7 @@ function GetApp() { // ------------------------------------------------------------- app.get('/ranklist', (req, res) => { + logger.LogReq(req) const user = req.session.user const data = utils.ReadJSON(idStatFile) diff --git a/submodules/qmining-page b/submodules/qmining-page index 5385ef6..ebad81a 160000 --- a/submodules/qmining-page +++ b/submodules/qmining-page @@ -1 +1 @@ -Subproject commit 5385ef67b6655ea87009761cc5c2b5daebdfa1e0 +Subproject commit ebad81a75ec4bb43d918136adf1724d25f3f91a9