Created
August 3, 2016 02:03
-
-
Save zekesonxx/1a73236e7dff3b5bb847a7d1908bd252 to your computer and use it in GitHub Desktop.
Earlier versions of my Warframe log parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WARFRAME_DIR="/home/zekesonxx/.PlayOnLinux/wineprefix/warframe/drive_c/users/zekesonxx/Local Settings/Application Data/Warframe" | |
LAUNCHER_LOG="${WARFRAME_DIR}/Preprocess.log" | |
# progress bar taken from http://stackoverflow.com/a/21959006/1904754 | |
progress(){ | |
# example usage: | |
# progress 30G 9G 30 | |
# 30G [================>.................................] 30% (9G) | |
# params: | |
# $1 = total value (e.g.: source size) | |
# $2 = current value (e.g.: destination size) | |
# $3 = percent completed | |
[[ -z $1 || -z $2 || -z $3 ]] && exit # on empty param... | |
percent=$3 | |
completed=$(( percent / 2 )) | |
remaining=$(( 50 - completed )) | |
echo -ne "\r$1 [" | |
printf "%0.s=" $(seq $completed) | |
echo -n ">" | |
[[ $remaining != 0 ]] && printf "%0.s." $(seq $remaining) | |
echo -n "] $percent% ($2)" | |
} | |
while true; do | |
if [[ -e "$LAUNCHER_LOG" ]]; then | |
TOUPDATE=$(grep -c "hash mismatch" "$LAUNCHER_LOG") | |
DONE=$(grep -c "Used shared" "$LAUNCHER_LOG") | |
if [[ $TOUPDATE == 0 ]]; then | |
# no divide by 0 errors | |
percent=0 | |
else | |
percent=$(( DONE * 100 / TOUPDATE )) | |
fi | |
progress "$TOUPDATE" "$DONE" $percent | |
else | |
echo -en "\r Launcher.log not yet created" | |
fi | |
sleep 0.1 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint node: true, quotmark: single, undef: true, indent: 2, esversion: 6 */ | |
'use strict'; | |
const wfpath = '/home/zekesonxx/.PlayOnLinux/wineprefix/warframe/drive_c/users/zekesonxx/Local Settings/Application Data/Warframe'; | |
const regex = { | |
hashMismatch: /[0-9\.]+\sSys\s\[Info\]: ([^\s]+) is out of date \(hash mismatch\)/, | |
bytesToDownload: /[0-9\.]+\sSys\s\[Info\]: ([0-9,]+) bytes to download/, | |
usedShared: /[0-9\.]+\sSys\s\[Info\]: Used shared ([^\s]+) \(([0-9,]+)[^)]+\)/ | |
}; | |
var fs = require('fs'); | |
var path = require('path'); | |
var lines = []; | |
var mismatches = 0; | |
var usedShared = 0; | |
var totalBytes = 0; | |
var downloadedBytes = 0; | |
function humanFileSize(bytes, si) { | |
var thresh = si ? 1000 : 1024; | |
if(Math.abs(bytes) < thresh) { | |
return bytes + ' B'; | |
} | |
var units = si ? ['kB','MB','GB','TB','PB','EB','ZB','YB'] | |
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']; | |
var u = -1; | |
do { | |
bytes /= thresh; | |
++u; | |
} while(Math.abs(bytes) >= thresh && u < units.length - 1); | |
return bytes.toFixed(3)+' '+units[u]; | |
} | |
function loadFile() { | |
lines = []; | |
var rawInput = fs.readFileSync(path.join(wfpath, 'Preprocess.log'), 'utf8'); | |
lines = rawInput.split('\n'); | |
} | |
function processFile() { | |
mismatches = 0; | |
usedShared = 0; | |
totalBytes = 0; | |
downloadedBytes = 0; | |
lines.forEach(function(line, i) { | |
var result = null; | |
//(hash mismatch) | |
result = regex.hashMismatch.exec(line); | |
if (result !== null) { | |
mismatches++; | |
return; | |
} | |
//bytes to download | |
result = regex.bytesToDownload.exec(line); | |
if (result !== null) { | |
totalBytes = parseInt(result[1].replace(/\,/g, ''), 10); | |
return; | |
} | |
//used shared | |
result = regex.usedShared.exec(line); | |
if (result !== null) { | |
usedShared++; | |
downloadedBytes += parseInt(result[2].replace(/\,/g, ''), 10); | |
return; | |
} | |
}); | |
} | |
loadFile(); | |
processFile(); | |
var percentage = Math.floor((downloadedBytes/totalBytes)*10000)/100; | |
console.log(`lines: ${lines.length};` + | |
` bytes: ${humanFileSize(downloadedBytes)}/${humanFileSize(totalBytes)} (${percentage}%);` + | |
` files: ${usedShared}/${mismatches}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment