Skip to content

Instantly share code, notes, and snippets.

@NazarK
Forked from tobinharris/git-sniff.rb
Last active November 19, 2015 10:11
Show Gist options
  • Select an option

  • Save NazarK/f4430e6757571a92d4f7 to your computer and use it in GitHub Desktop.

Select an option

Save NazarK/f4430e6757571a92d4f7 to your computer and use it in GitHub Desktop.
# git time log
# by NK
# usage "ruby git-timelog.rb" in git repository
#
# based on
# Simple Git Analyzer
#
# WORK IN PROGRESS :)
#
# Tobin Harris (tobin@tobinharris.com)
# http://tobinharris.com
# http://engineroomapps.com
# Class to analyze git log
require "active_support/all"
require 'rubygems'
class Gitalyzer
# scrape the Git log for current directory and
# make into a hash we can fart about with using Ruby
def log_to_hash
docs = []
cmd = "git log --pretty='%cn|%cd|%s'"
res = `#{cmd}`
res.each_line do |line|
parts = line.split('|')
docs << {:username=>parts[0], :datetime=>DateTime.parse(parts[1]), :subject=>parts[2]}
end
return {
:users=> docs.map{|r| r[:username]}.uniq,
:dates=> docs.map{|r| r[:date]}.uniq,
:records => docs
}
end
end
# Sample Report that works with the record
def output_summary_report(res)
# Report how many commits over time
puts "User, Total hours, Avg interval"
res[:users].each do |user|
times_for_user = res[:records].select{|r| r[:username]==user}.map{|r| r[:datetime]}
prev_time = nil
total_hours = 0
total_intervals = 0
times_for_user.reverse.each do |time|
if prev_time
span_in_hours = ((time.to_i-prev_time.to_i).to_f/3600.0).round(2)
if span_in_hours<3
total_hours += span_in_hours
total_intervals += 1
end
end
prev_time = time.dup
end
avg_interval=0
avg_interval=(total_hours/total_intervals).round(2) if total_intervals>0
puts "#{user}, #{total_hours.round(2)}, #{avg_interval}"
end
end
Dir.chdir($1 || '.')
g = Gitalyzer.new
res = g.log_to_hash
output_summary_report(res)
@NazarK
Copy link
Author

NazarK commented May 21, 2014

shows work hours statistics by adding intervals between commits (all intervals lower than 3 hours)

very approximate, first interval can't be counted this way of cause

@NazarK
Copy link
Author

NazarK commented Nov 19, 2015

seems this stats break when you do rebase

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