Re: Re: t_onlineplot (Added weekday)

From nat, 4 Years ago, written in Bash, viewed 308 times. This paste is a reply to Re: t_onlineplot (BUGFIX) from nat - go back
URL https://code.nat.moe/view/bbf9e100/diff Embed
Viewing differences between Re: t_onlineplot (BUGFIX) and Re: Re: t_onlineplot (Added weekday)
#!/bin/bash

filter_log () {
    next=0
    while read line; do {
        date="$(cut -d',' -f1 <<< "$line")"
        [ $date -gt $next ] && {
            echo "$date"
            read m s <<< $(date -d @$date +"%M %S")
            next=$(( $date + 3600 - 10#$m*60 - 10#$s ))
        }
    }; done | xargs -I. date +%Y-%m-%d,%-H +"%Y-%m-%d (%a),%-H" -d @.
}

plot () {
    i_="\033[7m"
    n_="\033[0m"
    tot=0
    onl=0
    echo -n '           '                 '
    for i in {0..23}; do [ $(($i%2)) -eq 0 ] && printf "%-4d" "$i"; done; echo
    echo -n '             '                   '
    for i in {0..23}; do [ $((($i+1)%2)) -eq 0 ] && printf "%-4d" "$i"; done; echo
    while read line; do {
        IFS=, read -ra days <<< "$line" #"$(date -d @$line +%Y-%m-%d,%-H)"
        day=${days[0]}
        [[ "$day_last" != "$day" ]] && {
            [ ! -z "$day_last" ] && echo
            day_last=$day
            echo -n "$day "
            [ -z "$day_last" ] && day_last=$day
            ptr=0
        }
        hr=${days[1]}
        let diff=$hr-$ptr
        for ((i=0; i<$diff; i++)); do echo -n '  '; done
        let tot+=$diff
        let onl+=1
        let ptr=$hr+1
        echo -ne "$i_  $n_"
    }; done
    echo
    let tot+=$onl
    echo "Online $(bc <<< "scale=3; ($onl/$tot)*100" | sed -e 's/0*$//;s/\.$//')% of the times ($onl out of $tot hours)."
}

filter_log | plotplot

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

Here you can reply to the paste above

captcha