From 2fa616570cd95391297f7d9651fb3bd455603469 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sat, 8 Jul 2017 13:14:59 +0200 Subject: [PATCH] Add log parser --- .gitignore | 5 +-- api/war-parser/clean.sh | 25 +++++++++++++ api/war-parser/run.sh | 77 +++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100755 api/war-parser/clean.sh create mode 100755 api/war-parser/run.sh diff --git a/.gitignore b/.gitignore index 54262ee..0c40f44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ # See http://help.github.com/ignore-files/ for more about ignoring files. # compiled output -/dist -/tmp +dist/ +tmp/ +etc/ # dependencies /node_modules diff --git a/api/war-parser/clean.sh b/api/war-parser/clean.sh new file mode 100755 index 0000000..547ff9b --- /dev/null +++ b/api/war-parser/clean.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +FILE="$1" +FILTER=("Budget" "Mission" "Abschuss" "Respawn" "Punkte") + +pat=$(echo ${FILTER[@]}|tr " " "|") + + +while IFS= read -r line; do + if [[ $line =~ [^[:space:]] ]]; then + RES="$(grep -Ew "$pat" <<< "$line")" + if [[ ${RES} =~ [^[:space:]] ]]; then + echo ${RES} + echo "" + fi + fi +done < <(cat ${FILE} ) + +# Add OPT Scoreboard +while IFS= read -r line; do + if [[ $line =~ [^[:space:]] ]]; then + echo "$line" + echo "" + fi +done < <(grep -A 200 Scoreboard ${FILE} ) diff --git a/api/war-parser/run.sh b/api/war-parser/run.sh new file mode 100755 index 0000000..3c6d69d --- /dev/null +++ b/api/war-parser/run.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +createScoreboardHeader() { + printf "%25s %8s %8s %8s %8s %8s\n" "Name" "Kill" "FF" "Death" "Respawn" + echo "---------------------------------------------------------------------------" +} + +createScoreboard() { + NAME="$1" + FILE="$2" + + KILL=0 + FF=0 + DEATH=0 + RESPAWN=0 + + #escape '[' -> somehow escapes all special chars, lol? + ESC_NAME=$(echo "$NAME" | sed -r 's/[\[]+/\\[/g') + + while IFS= read -r line; do + case "$line" in + *\(WEST\)[" "]von:[" "]${ESC_NAME}[" "]\(EAST\)* | *\(EAST\)[" "]von:[" "]${ESC_NAME}[" "]\(WEST\)*) + ((KILL++)) + ;; + *\(EAST\)[" "]von:[" "]${ESC_NAME}[" "]\(EAST\)* | *\(WEST\)[" "]von:[" "]${ESC_NAME}[" "]\(WEST\)*) + ((FF++)) + ;; + *${ESC_NAME}[" "]*von:*) + ((DEATH++)) + ;; + *Spieler:*${ESC_NAME}*) + ((RESPAWN++)) + ;; + esac + done < <(grep -- "${ESC_NAME}" ${FILE}) + + #echo {\"name\":\"$NAME\", \"kill\":${KILL}, \"ff\":${FF}, \"death\":${DEATH}, \"respawn\":${RESPAWN}}, + if [[ $NAME =~ [^[:space:]] ]]; then + printf "%25s %8s %8s %8s %8s %8s\n" "$NAME" $KILL $FF $DEATH $RESPAWN + fi +} + + +FILE="$1" +PLAYERS=() + +while IFS='' read -r line || [[ -n "$line" ]]; do + if [[ $line =~ [^[:space:]] ]]; then + case "$line" in + *"TFAR_RadioRequestEvent"*) + RES=$(echo "$(grep -oP ':[0-9]+\s\(\K.*?(?=\)\sREMOTE)' <<< "$line")") + ;; + *"Respawn"*) + RES=$(echo "$(grep -oP '\|\|\sSpieler:\s\K.*?(?=\s-\sKosten:)' <<< "$line")") + ;; + *"Abschuss"*) + RES=$(echo "$(grep -oP '\|\|\s\K.*?(?=\s\((EAST|WEST|CIV))' <<< "$line")") + RES1=$(echo "$(grep -oP 'von:\s\K.*?(?=\s\((EAST|WEST|CIV))' <<< "$line")") + ;; + esac + + if [[ $RES =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES "* ]]; then + PLAYERS+=("$RES") + fi + if [[ $RES1 =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES1 "* ]]; then + PLAYERS+=("$RES1") + fi + fi +done < ${FILE} + +createScoreboardHeader + +for i in "${PLAYERS[@]}" +do + : + createScoreboard "$i" ${FILE} +done diff --git a/package.json b/package.json index 735d989..beddf20 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "deploy-static": "cd ./static && ng build && ln -s ../api/resource/ ../public/resource", "deploy-static-prod": "cd ./static && ng build --env=prod && ln -s ../api/resource/ ../public/resource", "postinstall": "npm install --prefix ./static && npm install --prefix ./api", - "mongodb": "mongod --dbpath ./mongodb-data", + "mongodb": "mkdir -p mongodb-data && mongod --dbpath ./mongodb-data", "test": "npm test --prefix ./api", "e2e": "npm run deploy-static && concurrently \"npm run e2e --prefix ./api\" \"wait-on -t 60000 http://localhost:3001/ && npm run e2e --prefix ./static\" --success first --kill-others", "start-e2e": "npm run deploy-static && npm run e2e --prefix ./api",