Skip to content

Instantly share code, notes, and snippets.

@jumbosushi
Created June 26, 2018 17:28
Show Gist options
  • Save jumbosushi/f3c6159b9302d2bb02e31c7cae8a61f2 to your computer and use it in GitHub Desktop.
Save jumbosushi/f3c6159b9302d2bb02e31c7cae8a61f2 to your computer and use it in GitHub Desktop.
Get average from postman collection results json
require 'json'
def get_avg(num_array)
avg = num_array.instance_eval { reduce(:+) / size }
in_sec_f = avg / 1000
in_sec_f.round(3).to_s + " sec"
end
# 'vendor_index_api_responses' is dir that all responses are saved
all_results = Dir["#{Dir.home}/Documents/vendor_index_api_responses/*"]
all_results.each do |file_name|
file = File.read file_name
data = JSON.parse(file)
times = data["results"].first["times"].map(&:to_f)
file_basename = File.basename(file_name, ".*")
puts "#{file_basename}: " + get_avg(times)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment