Skip to content

Instantly share code, notes, and snippets.

@sllvn
Created April 14, 2012 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sllvn/2386369 to your computer and use it in GitHub Desktop.
Save sllvn/2386369 to your computer and use it in GitHub Desktop.
Verite Spotify contest vote tallier
#!/usr/bin/env ruby
# CSV file available at: http://dl.dropbox.com/u/24209319/Verite%20Spotify%20Playlist%20Voting-%20Foreign%20Languages.csv
require 'csv'
class Tally < Hash
def vote(key, x)
self[key] = 0 unless self[key]
self[key] += x
end
end
tally = Tally.new
CSV.foreach("Verite Spotify Playlist Voting- Foreign Languages.csv") do |row|
next if row[2] == "First song choice" # ignore first line of file
tally.vote(row[2], 3)
tally.vote(row[3], 2)
tally.vote(row[4], 1)
end
tally.sort_by { |key,value| value }.reverse.each do |t|
puts t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment