Skip to content

Instantly share code, notes, and snippets.

@masaakif
Created April 10, 2012 11:45
Show Gist options
  • Select an option

  • Save masaakif/2350787 to your computer and use it in GitHub Desktop.

Select an option

Save masaakif/2350787 to your computer and use it in GitHub Desktop.
複数のカンマ区切りのファイルを読み込んで、6番目のフィールドの平均、最大値、標準偏差、件数を表示
include Math
Dir.glob("*/*OrderEvents.Delay.csv") do |file|
i = 1
max = 0
sum = 0
File.open(file).each do |line|
delay = 0
delay = line.split(",")[5].to_i unless i == 1
sum += delay
max = delay if max < delay
i = i + 1
end
cnt = i
avg = sum/i
sd2 = 0
File.open(file).each do |line|
sd2 += (avg - line.split(",")[5].to_i)**2 unless i == 1
end
sd = sqrt(sd2).to_i
puts "#{file} : avg=#{avg}, count=#{cnt}, max=#{max}, sd=#{sd}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment