Skip to content

Instantly share code, notes, and snippets.

@ignacy
Created May 15, 2011 10:19
Show Gist options
  • Select an option

  • Save ignacy/973028 to your computer and use it in GitHub Desktop.

Select an option

Save ignacy/973028 to your computer and use it in GitHub Desktop.
Get git commit timmings
require 'time'
data = `git log | grep "^Date"`.split($/).
map { |line| Time.parse(line.split(' ')[4]) }.
group_by { |x| x.hour }
data.each { |k, v| data[k] = data[k].size }
total_commits = data.values.inject(0) { |sum, x| sum += x }
data = data.sort { |a, b| a[0] <=> b[0] }
puts "|---------------------------------"
puts "| Total commits: #{total_commits.to_s.ljust(17)}"
puts "|---------------------------------"
puts "| Hour | #of Commits | %of Commits"
puts "|---------------------------------"
data.each do |k, v|
puts "| #{k.to_s.ljust(5)}|#{v.to_s.center(13)}| #{"%.3f"%((v*100.0)/total_commits)}"
end
@newacct
Copy link
Copy Markdown

newacct commented Aug 27, 2011

.sort.group_by { |x| x.hour } should just be written as .group_by { |x| x.hour }. sort is unnecessary

@ignacy
Copy link
Copy Markdown
Author

ignacy commented Sep 1, 2011

Good catch @newacct, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment