def run
path = ARGV[0]
puts "入力ファイル:#{path}" if $DEBUG
unless path
return
end
File.open(path) {|io|
sep = ' '
sum_hash = Hash.new
count_hash = Hash.new
io.each_line() {|line|
arr = line.split(sep)
key_arr = arr[0, arr.size-1]
val = arr.last
puts arr.join(sep) if $DEBUG
puts key_arr.join(sep) if $DEBUG
puts val if $DEBUG
key = key_arr.join(sep)
unless sum_hash[key]
sum_hash[key] = 0
count_hash[key] = 0
end
sum_hash[key] += val.to_i
count_hash[key] += 1
}
puts "Key,Count,Sum,Average"
sum_hash.each {|key,val|
avg = val.to_f / count_hash[key]
puts "#{key},#{count_hash[key]},#{val},#{avg}"
}
}
end