Last active
July 8, 2020 12:59
-
-
Save caiobegotti/d65aae18073e6248edbebaff725cd0cd to your computer and use it in GitHub Desktop.
Companion script to generate ratings stats from https://github.com/caiobegotti/Scripts/blob/master/rottentomatoes-ratings-exporter.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# public domain | |
# caio begotti | |
set -euo pipefail | |
CSVFILE=$(mktemp) | |
wget https://raw.githubusercontent.com/caiobegotti/Scripts/master/rottentomatoes-ratings-exporter.csv --quiet -O ${CSVFILE} | |
for decade in $(cat ${CSVFILE} | sed -e '/^[A-Z]\+/d' -e 's/^\(.*\)\, \([12][0-9]\{3\}\).*$/\2/g' -e 's/[0-9]$//g' | sort -u); do | |
movies=$(grep -c ", ${decade}[0-9]," ${CSVFILE}) | |
ratings=$(grep ", ${decade}[0-9]," ${CSVFILE} | sed -e 's/^.*\([1-5]\)$/\1/g' | paste -s -d+ - | bc) | |
# since ratings are between 1-5 only, to give them a better real life value we do this to match 0-10 grades | |
average=$(echo "scale=2; ${ratings} / ${movies} * 2 + 1" | bc) | |
# rounded up: echo ${decade}0:${movies}:$(LC_ALL=C printf "%.0f\n" "${average}") | |
echo ${decade}0:${movies}:${average} | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment