jam-stats.sh (2032B) [raw]
1 #!/bin/sh 2 # stats.sh -- get frequencies of jam-tuesday songs/artists 3 # run with -f to show a plaintext table of the "full archive" 4 set -e 5 6 N=10 7 REPO=$(dirname "$(dirname "$0")") 8 DIR="$REPO/www/jam-tuesday" 9 TMP=$(mktemp) 10 num_sessions=0 11 for set in "$DIR"/[0-9][0-9][0-9][0-9]-*; do 12 # Remove leading notes, blank lines, and instrument/reprise 13 # comments (and blank lines before or after the comments) 14 sed '1,/---/d' "$set" | grep -v '^ *$' | sed 's/ *([^)]*) *//g' 15 num_sessions=$((num_sessions + 1)) 16 done > "$TMP" 17 18 artists() { 19 sed 's/.*, *//' "$TMP" | sort -f | uniq -i -c 20 } 21 22 songs() { 23 sed 's/ *//' "$TMP" | sort -f | uniq -i -c 24 } 25 26 topN() { 27 sort -n -r | head -n "$N" 28 } 29 30 echo "Play Stats:" 31 echo "-----------" 32 printf "%4d Jam Sessions\\n" "$num_sessions" 33 printf "%4d Songs Total\\n" "$(wc -l < "$TMP")" 34 printf "%4d Unique Songs\\n" "$(songs | wc -l)" 35 printf "%4d Unique Artists\\n\\n" "$(artists | wc -l)" 36 37 echo "Top $N Artists (Frequency, Name):" 38 echo "---------------------------------" 39 artists | topN 40 41 echo "" 42 echo "Top $N Songs (Frequency, Name):" 43 echo "-------------------------------" 44 songs | topN 45 46 # TODO: Don't hardcode the width to be perfect (if we ever have more setlists...) 47 if [ "$1" = "-f" ]; then 48 printf "\n\n\nFull Archive:\n" 49 SEP="----------------------------+---------------------------------------+--\n" 50 sed 's/.*, *//' "$TMP" | sort -u -f | while read artist; do 51 first="" 52 grep ", *$artist\$" "$TMP" | sort -f | sed "s#, *$artist *##" | uniq -c -i | \ 53 while read plays song; do 54 if [ -z "$first" ]; then 55 first=1 56 printf "$SEP" 57 printf "%-27s | %-37s |%2d\n" "$artist" "$song" "$plays" 58 else 59 printf "%-27s | %-37s |%2d\n" "" "$song" "$plays" 60 fi 61 done 62 done 63 printf "$SEP" 64 fi 65 66 rm "$TMP"