alexkarle.com

Source for alexkarle.com
git clone git://git.alexkarle.com/alexkarle.com.git
Log | Files | Refs | README | LICENSE

stats.sh (916B) [raw]


      1 #!/bin/sh
      2 # stats.sh -- get frequencies of jam-tuesday songs/artists
      3 set -e
      4 
      5 N=${1:-10}
      6 DIR=$(dirname "$0")
      7 TMP=$(mktemp)
      8 for set in "$DIR"/[01][0-9]-*; do
      9     # Remove leading notes, blank lines, and instrument/reprise
     10     # comments (and blank lines before or after the comments)
     11     sed '1,/---/d' "$set" | grep -v '^ *$' | sed 's/ *([^)]*) *//g'
     12 done > "$TMP"
     13 
     14 artists() {
     15     sed 's/.*, *//' "$TMP" | sort -f | uniq -i -c
     16 }
     17 
     18 songs() {
     19     sort -f "$TMP" | uniq -i -c
     20 }
     21 
     22 topN() {
     23     sort -n -r | head -n "$N"
     24 }
     25 
     26 echo "Play Stats:"
     27 echo "-----------"
     28 printf "%4d Songs Total\\n" "$(wc -l < "$TMP")"
     29 printf "%4d Unique Songs\\n" "$(songs | wc -l)"
     30 printf "%4d Unique Artists\\n\\n" "$(artists | wc -l)"
     31 
     32 echo "Top $N Artists (Frequency, Name):"
     33 echo "---------------------------------"
     34 artists | topN
     35 
     36 echo ""
     37 echo "Top $N Songs (Frequency, Name):"
     38 echo "-------------------------------"
     39 songs | topN
     40 
     41 
     42 rm "$TMP"