Created
January 12, 2016 10:23
-
-
Save evalphobia/d956b34e9255dd775a70 to your computer and use it in GitHub Desktop.
This file contains 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
require 'ltsv' | |
require 'json' | |
result = {} | |
STDIN.each do |line| | |
record = LTSV.parse(line) | |
path = false | |
res = record[0] | |
next if res.nil? | |
path = res[:path] | |
next if res === false | |
if result[path].nil? then | |
result[path] = {} | |
result[path][:response_time] = 0 | |
result[path][:count] = 0 | |
end | |
result[path][:response_time] += Integer(res[:response_time]) | |
result[path][:count] += 1 | |
end | |
r = result.sort do |(k1, v1), (k2, v2)| | |
(v2[:response_time] / v2[:count]) <=> (v1[:response_time] / v1[:count]) | |
end | |
def output(r, max=10) | |
i = 0 | |
r.each do |k, v| | |
puts "path:#{k}\tavg:#{v[:response_time] / v[:count]}\tcount:#{v[:count]}\ttotal:#{v[:response_time]}" | |
i += 1 | |
return if i > max | |
end | |
end | |
output(r, 30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment