Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #$watch -n 1 -t sh ./wurm-skill-rate.sh
- #SKILL NAME
- skill="Shield smithing"
- #PLAYER NAME
- pnam="kaelygon"
- #How many skill updates is wanted to be averaged?
- suavg=10
- #Decimal places (flored)
- precis=4
- #---------
- #Wurm logs path
- logs=~/".wurm/players/${pnam}/logs"
- #Newest _Skills.*txt
- file=$( ls -t "${logs}/_Skills"*txt | head -n1 )
- #Find latest session
- lastlog=$(grep "Logging started" "${file}" | tail -n1)
- #sed print only after current session | grep only wanted skill | take last $suavg skill updates
- olog="$( sed -n "/$lastlog/,\$p" "${file}" | grep -i "] $skill i" | tail -n $((${suavg}+1)))"
- if [ -z "$olog" ]; then
- echo "No skill updates found for $skill"
- fi
- #Count new lines for valid found skill updates count
- sucnt=$(($(echo "${olog}" | wc -l)-1))
- #Get last word (level) of first and last skill updates
- stlvl="$(echo "${olog}" | head -n1 | grep -oE '[^ ]+$')"
- ndlvl="$(echo "${olog}" | tail -n1 | grep -oE '[^ ]+$')"
- #Skill gain delta
- gain=$(bc -l <<< "$ndlvl - $stlvl")
- #Get first word (time) of first and last time stamps
- sttime="$(echo "${olog}" | head -n1 | cut -d ' ' -f1)"
- #ndtime="$(echo "${olog}" | tail -n1 | cut -d ' ' -f1)"
- #Time stamps to seconds ; exclude [ and ]
- sttime="$(echo "${sttime}" | sed 's/\[//;s/\]//' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')"
- #ndtime="$(echo "${ndtime}" | sed 's/\[//;s/\]//' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')"
- ndtime=" $( date +%T | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }' ) "
- #if skill updates happened past midnight, add 24hr to ndtime for correct time delta
- ndtime=$( bc -l <<< "$ndtime + ($ndtime < $sttime)*24*60*60" )
- #Time delta
- tdelta=$( bc -l <<< "$ndtime - $sttime" )
- #Skill gain rate
- sgrate=$( printf "%.${precis}f" $(bc -l <<< "$gain*3600/$tdelta") )
- #DEBUGS
- #echo "file $file"
- #echo "$lastlog"
- #echo "gain $stlvl-$ndlvl=$gain"
- #echo "tdelta $ndtime-$sttime=$tdelta"
- #echo "sgrate $sgrate"
- echo "(${sucnt}SU ${tdelta}s) ${skill} avg ${sgrate} LvL/Hr"
- #sweet spot
- echo SS $(printf "%.${precis}f" $(bc -l <<< "$ndlvl*0.77+23") )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement