Re: Re: t_onlineplot (Added weekday)

From nat, 4 Years ago, written in Bash, viewed 298 times. This paste is a reply to Re: t_onlineplot (BUGFIX) from nat - view diff
URL https://code.nat.moe/view/bbf9e100 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2.  
  3. filter_log () {
  4.     next=0
  5.     while read line; do {
  6.         date="$(cut -d',' -f1 <<< "$line")"
  7.         [ $date -gt $next ] && {
  8.             echo "$date"
  9.             read m s <<< $(date -d @$date +"%M %S")
  10.             next=$(( $date + 3600 - 10#$m*60 - 10#$s ))
  11.         }
  12.     }; done | xargs -I. date +"%Y-%m-%d (%a),%-H" -d @.
  13. }
  14.  
  15. plot () {
  16.     i_="\033[7m"
  17.     n_="\033[0m"
  18.     tot=0
  19.     onl=0
  20.     echo -n '                 '
  21.     for i in {0..23}; do [ $(($i%2)) -eq 0 ] && printf "%-4d" "$i"; done; echo
  22.     echo -n '                   '
  23.     for i in {0..23}; do [ $((($i+1)%2)) -eq 0 ] && printf "%-4d" "$i"; done; echo
  24.     while read line; do {
  25.         IFS=, read -ra days <<< "$line" #"$(date -d @$line +%Y-%m-%d,%-H)"
  26.         day=${days[0]}
  27.         [[ "$day_last" != "$day" ]] && {
  28.             [ ! -z "$day_last" ] && echo
  29.             day_last=$day
  30.             echo -n "$day "
  31.             [ -z "$day_last" ] && day_last=$day
  32.             ptr=0
  33.         }
  34.         hr=${days[1]}
  35.         let diff=$hr-$ptr
  36.         for ((i=0; i<$diff; i++)); do echo -n '  '; done
  37.         let tot+=$diff
  38.         let onl+=1
  39.         let ptr=$hr+1
  40.         echo -ne "$i_  $n_"
  41.     }; done
  42.     echo
  43.     let tot+=$onl
  44.     echo "Online $(bc <<< "scale=3; ($onl/$tot)*100" | sed -e 's/0*$//;s/\.$//')% of the times ($onl out of $tot hours)."
  45. }
  46.  
  47. filter_log | plot
  48.  

Reply to "Re: Re: t_onlineplot (Added weekday)"

Here you can reply to the paste above

captcha