Skip to content

Instantly share code, notes, and snippets.

Created November 15, 2011 12:09
Show Gist options
  • Save anonymous/1366926 to your computer and use it in GitHub Desktop.
Save anonymous/1366926 to your computer and use it in GitHub Desktop.
spark
#!/bin/bash -e
if [ "$1" ]
then
data="$@"
else
while read x
do
data="$data $x"
done
fi
ticks=(▁ ▂ ▃ ▅ ▆ ▇)
sorted=$(echo "$data" |tr ' ' '\n' | sort -n)
sorted=($sorted)
data=($data)
incr=${sorted[0]}
i=${#sorted[@]}
mx=${sorted[$i - 1]}
i=${#ticks[@]}
width=$(( $mx / $i ))
for (( i = 0 ; i < ${#ticks[@]} ; ++i ))
do
thres=$(( $i * $width + $incr ))
bins="$bins $thres"
done
bins=($bins)
for n in ${data[@]}
do
for (( i = ${#bins[@]} ; i > 0 ; --i ))
do
thres=${bins[$i - 1]}
hi=$(( $thres + $width ))
if [ $n -gt $hi -o $n -ge $thres ]
then
echo -ne "${ticks[$i - 1]}"
break
fi
done
done
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment