Created
April 10, 2012 11:45
-
-
Save masaakif/2350787 to your computer and use it in GitHub Desktop.
複数のカンマ区切りのファイルを読み込んで、6番目のフィールドの平均、最大値、標準偏差、件数を表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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