Module: GitAnalysis

Defined in:
lib/git_analysis.rb,
lib/git_analysis/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.count_diff(number = 0) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/git_analysis.rb', line 35

def self.count_diff(number=0)
  repo = load_repo()
  count = Hash.new{|h,k| h[k] = Hash.new(0) }
  total = Hash.new(0)
  repo.walk(repo.last_commit).each do |commit|
    domain = commit.author[:email].gsub(/\A[a-zA-Z0-9\_\-\.\+ ]+@/,"").rstrip
    diff = commit_diff(repo, commit)

    count[:"#{domain}"][:"addition"] += diff[1].to_i
    count[:"#{domain}"][:"deletion"] += diff[2].to_i

    total[:"addition"] += diff[1].to_i
    total[:"deletion"] += diff[2].to_i
  end
  if number.nil?
    # TODO more Faster! it takes 50 sec(10k / sec).
    sorted = count.sort_by{|a,b| -b[:"addition"] }
  else
    sorted = count.sort_by{|a,b| -b[:"addition"] }.first(number)
    sum = Hash.new(0)
    sorted.each{|c|
      sum["addition"] += c[1][:"addition"]
      sum["deletion"] += c[1][:"deletion"]
    }
    tmp = Hash.new(0)
    tmp[:"addition"] = total[:"addition"] - sum["addition"]
    tmp[:"deletion"] = total[:"deletion"] - sum["deletion"]
    sorted << [:"others",tmp]
  end
  result = Hash.new
  result[:'count'] = Hash.new
  result[:'count'] = Hash[sorted]
  result[:'infomation'] = get_info(repo,total)
  puts Oj.dump(result, :mode => :compat)
end

.count_domain(number = 0) ⇒ Object

count domain



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/git_analysis.rb', line 10

def self.count_domain(number=0)
  repo = load_repo()
  count = Hash.new(0)
  total = 0
  repo.walk(repo.last_commit).each do |commit|
    # TODO more Faster
    domain = commit.author[:email].gsub(/\A[a-zA-Z0-9\_\-\.\+ ]+@/,"").rstrip
    count[:"#{domain}"] += 1
    total += 1
  end
  if number.nil?
    sorted = count.sort_by{|a,b| -b }
  else
    sorted = count.sort_by{|a,b| -b }.first(number)
    sum =0
    sorted.each{|c| sum += c[1] } 
    sorted << [:others, total - sum] 
  end
  result = Hash.new
  result[:'count'] = Hash.new
  result[:'count'] = Hash[sorted]
  result[:'infomation'] = get_info(repo,total)
  puts Oj.dump(result, :mode => :compat)
end

.exportObject

export



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/git_analysis.rb', line 72

def self.export()
  repo = load_repo()
  commits = repo.walk(repo.last_commit).to_a
  list = Hash.new
  domain = Array.new
  commits.each do |c|
    log = Hash.new
    log[:sha] = c.oid
    log[:message] = c.message
    log[:time] =  c.time
    log[:name] = c.author[:name]
    log[:email] = c.author[:email]
    log[:domain] = c.author[:email].match(/([a-zA-Z0-9\_\-\.]+$)/)[1]
    list["#{c.oid}"] = log
  end
  puts Oj.dump(list, :mode => :compat)
end