Ruby: Visualizing NCAA College Basketball

The data is from Here.

collegeballart

Weight Averages (lb) by School
weight averages NCAA Mens baseketball

Height Averages (inches) by School
height averages NCAA Mens baseketball

Ruby used to parse data.
rubytoparse


parseWeight.rb

require 'csv'
Hash schoolHash = Hash.new
Hash schoolHashAverages = Hash.new
CSV.foreach("C:\\CollegeBall\\all_ncaa_tourney_players_14_player_metadata.csv",
 :headers => true) do |row|
  school = row[8]
  weight = row[5].to_i
   if schoolHash.has_key?  ( school )
     count = schoolHash[ school ]
     count += 1
     schoolHash[ school ] = count
     countWeight = schoolHashAverages[ school ]
     countWeight += weight
     schoolHashAverages[ school ] = countWeight
   else
     schoolHash[ school ] = 1
     schoolHashAverages[school] = weight
   end
end
Hash averagesHash = Hash.new
schoolHashAverages.each do |key, value|
  averagesHash[key] = (value.to_f / schoolHash[key].to_f ).round(2) 
end
averagesHash = averagesHash.sort_by {|_key, value| value}
averagesHash.each do |key, value|
  puts ",[ '#{key.delete '\''}', #{value} ]"
end

Leave a Reply

Your email address will not be published. Required fields are marked *