Created
October 16, 2012 05:06
-
-
Save kunishi/641f49e111fb80baa804 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
line_num = 0 | |
month = nil | |
max1 = max2 = min1 = min2 = nil | |
sum1 = sum2 = 0.0 | |
while line = gets | |
array = line.chomp.split(/,/) | |
month = array[0].to_i if !month | |
if month != array[0].to_i | |
print "month: ", month, ", point1: max = ", max1, ", min = ", min1, ", ave = ", sum1 / line_num, "\n" | |
print "month: ", month, ", point2: max = ", max2, ", min = ", min2, ", ave = ", sum2 / line_num, "\n" | |
line_num = 0 | |
month = array[0].to_i | |
max1 = max2 = min1 = min2 = nil | |
sum1 = sum2 = 0.0 | |
end | |
att1 = array[3].to_f | |
att2 = array[4].to_f | |
max1 = att1 if !max1 || max1 < att1 | |
max2 = att2 if !max2 || max2 < att2 | |
min1 = att1 if !min1 || min1 > att1 | |
min2 = att2 if !min2 || min2 > att2 | |
sum1 += att1 | |
sum2 += att2 | |
line_num += 1 | |
end | |
# for the last month | |
print "month: ", month, ", point1: max = ", max1, ", min = ", min1, ", ave = ", sum1 / line_num, "\n" | |
print "month: ", month, ", point2: max = ", max2, ", min = ", min2, ", ave = ", sum2 / line_num, "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment