Last active
December 14, 2015 04:29
-
-
Save relistan/5028647 to your computer and use it in GitHub Desktop.
Draw a histogram from a CSV on the command line
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
#!/usr/bin/env ruby | |
COLUMNS_TO_USE = 40.0 | |
histo = [] | |
0.upto(9) { |i| histo[i] = 0 } | |
field_to_parse = ARGV.shift.to_i | |
ARGF.each do |line| | |
fields = line.split(/,/) | |
score = fields[field_to_parse].to_i | |
histo[(score * 0.1).floor] += 1 | |
end | |
max = histo.sort.last | |
scale = COLUMNS_TO_USE / max | |
puts "\n\n\n" | |
puts " 0\n ||" | |
histo.each { |l| print " ||", '=' * (l.to_i * scale), "\n" } | |
puts 100 | |
puts "\n\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Draw a Histogram from a CSV on the Command Line
Sideways ASCII art FTW.
Usage:
2 being the column number to grab from the CSV
Looks like: