Created
June 26, 2018 17:28
-
-
Save jumbosushi/f3c6159b9302d2bb02e31c7cae8a61f2 to your computer and use it in GitHub Desktop.
Get average from postman collection results json
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
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