Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created June 23, 2009 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msonnabaum/134773 to your computer and use it in GitHub Desktop.
Save msonnabaum/134773 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require "csv"
class Array
def sum
inject(nil) { |sum,x| sum ? sum+x : x }
end
def average
sum.to_f / size
end
end
class VideoAnalysis
attr_reader :video_records
def initialize(filename)
puts "setting filename=",filename
@filename = filename
@results = CSV.read(@filename)
@video_records = {}
end
def printResults
@results = CSV.read(@filename)
#puts @results.inspect
puts @results[0][0]
puts @results[0][1]
puts @results[0][2]
puts @results[0][3]
puts @results[0][4]
end
def buildArray
@results.each do |record|
#height = Float(record[2])
#width = Float(record[3])
height = record[2]
width = record[3]
#total = height * width
#total_str = String(total)
total_str = height + "x" + width
begin
@video_records[total_str] << Float(record[4])
rescue
@video_records[total_str] = [Float(record[4])]
end
end
end
end
v = VideoAnalysis.new("video_analysis.csv")
v.buildArray
v.video_records.sort.each do |resolution, info|
puts "#{resolution} min #{info.min}, max #{info.max}, avg #{info.average}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment