Last active
June 8, 2016 14:37
-
-
Save ebot/e7252b28910711db555e323edb4f6f29 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/env ruby -wKU | |
# This script reads a list of completion times and | |
# figures out the latest end time for each day. It | |
# then averages those out by day of the week. | |
require 'csv' | |
require 'chronic' | |
latest = '00:00:00' | |
earliest = '24:00:00' | |
days = {} | |
dates = {} | |
# Determine the latest completion time for each date in the list | |
CSV.foreach( 'completion_times.csv') do |rec| | |
puts "Reading #{rec}" if $DEBUG | |
date = Chronic.parse rec[0].split(' ')[0] | |
time = rec[0].split(' ')[1] | |
unless date.nil? | |
puts " Processing #{date}" if $DEBUG | |
date = date.strftime '%Y-%m-%d' | |
dates[date] = '00:00:00' if dates[date].nil? | |
dates[date] = time if time > dates[date] | |
end | |
end | |
# Get the latest completion times for each day of the week | |
dates.each do |date, time| | |
date = Chronic.parse date | |
day = date.strftime '%^a' | |
days[day] = [] if days[day].nil? | |
latest = time if time > latest | |
earliest = time if time < earliest | |
days[day] << time | |
end | |
puts "The latest time is #{latest}" | |
puts "The earliest time is #{earliest}" | |
puts "\nAverage Daily Completion times:" | |
days.each do |d,t| | |
times = t.map { |time| Chronic.parse(time).to_i } | |
avg = (times.inject(0) {|sum,x| sum + x }) / times.count | |
puts " #{d}: #{Time.at(avg).to_datetime.strftime('%H:%M %p')}" | |
puts " Weekly Times: #{t.join(', ')}" | |
end | |
puts "\nDaily Completion Times:" | |
dates.each { |d,t| puts " #{d}: #{t}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment