Advertisement
Kaelygon

wurm-skill-rate.sh

Sep 12th, 2022 (edited)
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.08 KB | Gaming | 0 0
  1. #!/bin/bash
  2. #$watch -n 1 -t sh ./wurm-skill-rate.sh
  3.  
  4. #SKILL NAME
  5. skill="Shield smithing"
  6. #PLAYER NAME
  7. pnam="kaelygon"
  8.  
  9. #How many skill updates is wanted to be averaged?
  10. suavg=10
  11. #Decimal places (flored)
  12. precis=4
  13.  
  14. #---------
  15.  
  16. #Wurm logs path
  17. logs=~/".wurm/players/${pnam}/logs"
  18. #Newest _Skills.*txt
  19. file=$( ls -t "${logs}/_Skills"*txt | head -n1 )
  20.  
  21. #Find latest session
  22. lastlog=$(grep "Logging started" "${file}" | tail -n1)
  23.  
  24. #sed print only after current session | grep only wanted skill | take last $suavg skill updates
  25. olog="$( sed -n "/$lastlog/,\$p" "${file}" | grep -i "] $skill i" | tail -n $((${suavg}+1)))"
  26.  
  27. if [ -z "$olog" ]; then
  28.     echo "No skill updates found for $skill"
  29. fi
  30.  
  31. #Count new lines for valid found skill updates count
  32. sucnt=$(($(echo "${olog}" | wc -l)-1))
  33.  
  34.  
  35. #Get last word (level) of first and last skill updates
  36. stlvl="$(echo "${olog}" | head -n1 | grep -oE '[^ ]+$')"
  37. ndlvl="$(echo "${olog}" | tail -n1 | grep -oE '[^ ]+$')"
  38.  
  39. #Skill gain delta
  40. gain=$(bc -l <<< "$ndlvl - $stlvl")
  41.  
  42.  
  43. #Get first word (time) of first and last time stamps
  44. sttime="$(echo "${olog}" | head -n1 | cut -d ' ' -f1)"
  45. #ndtime="$(echo "${olog}" | tail -n1 | cut -d ' ' -f1)"
  46.  
  47. #Time stamps to seconds ; exclude [ and ]
  48. sttime="$(echo "${sttime}" | sed 's/\[//;s/\]//' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')"
  49. #ndtime="$(echo "${ndtime}" | sed 's/\[//;s/\]//' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')"
  50. ndtime=" $( date +%T | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }' ) "
  51.  
  52. #if skill updates happened past midnight, add 24hr to ndtime for correct time delta
  53. ndtime=$( bc -l <<< "$ndtime + ($ndtime < $sttime)*24*60*60" )
  54.  
  55. #Time delta
  56. tdelta=$( bc -l <<< "$ndtime - $sttime" )
  57.  
  58. #Skill gain rate
  59. sgrate=$( printf "%.${precis}f" $(bc -l <<< "$gain*3600/$tdelta") )
  60.  
  61.  
  62. #DEBUGS
  63. #echo "file $file"
  64. #echo "$lastlog"
  65. #echo "gain $stlvl-$ndlvl=$gain"
  66. #echo "tdelta $ndtime-$sttime=$tdelta"
  67. #echo "sgrate $sgrate"
  68.  
  69. echo "(${sucnt}SU ${tdelta}s) ${skill} avg ${sgrate} LvL/Hr"
  70. #sweet spot
  71. echo SS $(printf "%.${precis}f" $(bc -l <<< "$ndlvl*0.77+23") )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement