Skip to content

Instantly share code, notes, and snippets.

@evalphobia
Created January 12, 2016 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evalphobia/d956b34e9255dd775a70 to your computer and use it in GitHub Desktop.
Save evalphobia/d956b34e9255dd775a70 to your computer and use it in GitHub Desktop.
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