-
-
Save DanPatey/8242c5b971429a37cab2 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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'json' | |
require 'pp' | |
# Read in our JSON file and convert to Hash so we can play with it | |
json = File.read('scan-times.json') | |
json_hash = JSON.parse(json, :symbolize_names => true) | |
# Create variables for our conditionals | |
$i = 0 | |
shortest_time = 0 | |
latest_time = 0 | |
# Update this to run to the end of the file | |
begin | |
start_time = json_hash[$i][:start].split(' ').last | |
start_time = Time.parse(start_time) | |
end_time = json_hash[$i][:stop].split(' ').last | |
end_time = Time.parse(end_time) | |
current_time = end_time - start_time | |
# Keep a running total for our average time | |
total_time +=current_time | |
$i +=1 | |
# Find the shortest time | |
if current_time < shortest_time |do| | |
shortest_time = current_time | |
return shortest_time | |
# Find the longest time | |
elsif current_time > latest_time |do| | |
latest_time = current_time | |
return latest_time | |
end | |
return total_time, $i | |
end while $i > json_hash | |
average_time = total_time / $i | |
print 'The average scan time was ' + average_time | |
print 'The fastest scan was ' + shortest_time | |
print 'The longest scan was ' + latest_time | |
print 'the total time to calculate was ' + total_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cleaner