git_analysis 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20d2cf9257f65553a99f093ed87ab95b54f6cc50
4
- data.tar.gz: f97582d793741002e2766ca967281e3aa4136672
3
+ metadata.gz: 08645a52eaadeb1867565675437d912c6f2e9902
4
+ data.tar.gz: 8e05322c0bbbbb96e0938b3d57251056fabc677d
5
5
  SHA512:
6
- metadata.gz: 20f0882da6026806f1932a0bb4436ab0cfae7d4b95a0e082e7a62753392cc5592743262f8c2c376f0e3cde453551e117716b6dd87dc9c8f807193deeb7af2a82
7
- data.tar.gz: e64295b927764850a513af55c1317f4394fc7cd88420cbe5391054d65c22c13e1daf642b9ac4a4d1bf81a796d5dffdf862beac383e63ded7417b1eda28d7c292
6
+ metadata.gz: ca59b4804e69e9e5d01fef1b7841af885d1dd6046d5d445689a011eb25fed9c5d4343a5700a884ba337e92f225784afd9146719694a10d9a4604672c5faa5554
7
+ data.tar.gz: 0f279e1d0a2e0683de45453e46939ae822c22af472dcfa7be94e0967f641d8984e0cefecb6fdd1f3c4bcfe4e3ca3a4147581bd75b8ad52c2871b63b8552c3bc0
data/README.md CHANGED
@@ -34,30 +34,98 @@ $ cd git_analysis
34
34
 
35
35
  $ git-analysis count -d |jq '.'
36
36
  {
37
- "total": 5,
38
- "gmail.com": 5
37
+ "count": {
38
+ "gmail.com": 14
39
+ },
40
+ "infomation": {
41
+ "last_commit_oid": "7bf2839121b1940c4999b187cd5717f9e94a4a85",
42
+ "last_commit_date": "2014-08-04 23:55:25 +0900",
43
+ "total_commit": 14
44
+ }
39
45
  }
40
- ```
41
46
 
42
47
  total = `git log --pretty=oneline |wc -l`
48
+ ```
49
+ ### Count E-mail Domain (topN add v0.0.3)
50
+ if N = 1, display most domain. and others is `total_commit - top1_commit`
51
+
52
+ ```
53
+ $ git clone https://github.com/libgit2/rugged.git
54
+ $ cd rugged
55
+
56
+ $ git-analysis count -d -n 2 |jq '.'
57
+ {
58
+ "count": {
59
+ "gmail.com": 882,
60
+ "googlemail.com": 453,
61
+ "others": 437
62
+ },
63
+ "infomation": {
64
+ "last_commit_oid": "e96d26174b2bf763e9dd5dd2370e79f5e29077c9",
65
+ "last_commit_date": "2014-07-23 20:16:10 +0900",
66
+ "total_commit": 1772
67
+ }
68
+ }
69
+ ```
70
+
43
71
 
44
72
  ### Count Addition & Deletion by Domain (add v0.0.2)
45
73
  ```
46
74
  $ git-analysis count -l |jq '.'
47
75
  {
48
- "gmail.com": {
49
- "addition": 290,
50
- "deletion": 50
76
+ "count": {
77
+ "gmail.com": {
78
+ "addition": 364,
79
+ "deletion": 74
80
+ }
51
81
  },
52
- "total": {
53
- "addition": 290,
54
- "deletion": 50
82
+ "infomation": {
83
+ "last_commit_oid": "022403ad80ee7b22231e40f9a3679a019d5439f6",
84
+ "last_commit_date": "2014-08-06 00:02:01 +0900",
85
+ "total_commit": {
86
+ "addition": 364,
87
+ "deletion": 74
88
+ }
55
89
  }
56
90
  }
57
91
 
58
92
  note: sort by addition
59
93
  ```
60
94
 
95
+ ### Count Addition & Deletion by Domain (topN add v0.0.3)
96
+ if N = 1, display most domain. and others is `total_commit(add/del) - top1_commit(add/del)`
97
+
98
+ ```
99
+ $ git clone https://github.com/libgit2/rugged.git
100
+ $ cd rugged
101
+
102
+ $ git-analysis count -l -n 2 |jq '.'
103
+ {
104
+ "count": {
105
+ "gmail.com": {
106
+ "addition": 32308,
107
+ "deletion": 15641
108
+ },
109
+ "googlemail.com": {
110
+ "addition": 17668,
111
+ "deletion": 7277
112
+ },
113
+ "others": {
114
+ "addition": 21768,
115
+ "deletion": 7098
116
+ }
117
+ },
118
+ "infomation": {
119
+ "last_commit_oid": "e96d26174b2bf763e9dd5dd2370e79f5e29077c9",
120
+ "last_commit_date": "2014-07-23 20:16:10 +0900",
121
+ "total_commit": {
122
+ "addition": 71744,
123
+ "deletion": 30016
124
+ }
125
+ }
126
+ }
127
+ ```
128
+
61
129
 
62
130
  ## Contributing
63
131
 
data/bin/git-analysis CHANGED
@@ -7,14 +7,15 @@ require 'thor'
7
7
 
8
8
  class Cli < Thor
9
9
 
10
- desc "count [-d][-l]", "count. email-domain or line. please run `git-analysis help count`)"
10
+ desc "count [-d][-l][-n]", "count. email-domain or line. please run `git-analysis help count`)"
11
11
  option :"domain", :type => :boolean, :aliases => '-d', :desc => "count e-mail domain. export json"
12
12
  option :"line", :type => :boolean, :aliases => '-l', :desc => "count insertion & deletion"
13
+ option :"number", :type => :numeric, :aliases => '-n', :desc => "topN."
13
14
  def count
14
15
  if options[:domain]
15
- GitAnalysis.count_domain
16
+ GitAnalysis.count_domain(options[:number])
16
17
  elsif options[:line]
17
- GitAnalysis.count_diff
18
+ GitAnalysis.count_diff(options[:number])
18
19
  end
19
20
  end
20
21
 
data/lib/git_analysis.rb CHANGED
@@ -7,22 +7,35 @@ require "oj"
7
7
  module GitAnalysis
8
8
 
9
9
  # count domain
10
- def self.count_domain()
10
+ def self.count_domain(number=0)
11
11
  repo = load_repo()
12
12
  count = Hash.new(0)
13
+ total = 0
13
14
  repo.walk(repo.last_commit).each do |commit|
14
15
  # TODO more Faster
15
16
  domain = commit.author[:email].gsub(/\A[a-zA-Z0-9\_\-\.\+ ]+@/,"").rstrip
16
17
  count[:"#{domain}"] += 1
17
- count[:"total"] += 1
18
+ total += 1
18
19
  end
19
- sorted = count.sort_by{|a,b| -b }
20
- puts Oj.dump(Hash[sorted], :mode => :compat)
20
+ if number.nil?
21
+ sorted = count.sort_by{|a,b| -b }
22
+ else
23
+ sorted = count.sort_by{|a,b| -b }.first(number)
24
+ sum =0
25
+ sorted.each{|c| sum += c[1] }
26
+ sorted << [:others, total - sum]
27
+ end
28
+ result = Hash.new
29
+ result[:'count'] = Hash.new
30
+ result[:'count'] = Hash[sorted]
31
+ result[:'infomation'] = get_info(repo,total)
32
+ puts Oj.dump(result, :mode => :compat)
21
33
  end
22
34
 
23
- def self.count_diff()
35
+ def self.count_diff(number=0)
24
36
  repo = load_repo()
25
37
  count = Hash.new{|h,k| h[k] = Hash.new(0) }
38
+ total = Hash.new(0)
26
39
  repo.walk(repo.last_commit).each do |commit|
27
40
  domain = commit.author[:email].gsub(/\A[a-zA-Z0-9\_\-\.\+ ]+@/,"").rstrip
28
41
  diff = commit_diff(repo, commit)
@@ -30,12 +43,29 @@ module GitAnalysis
30
43
  count[:"#{domain}"][:"addition"] += diff[1].to_i
31
44
  count[:"#{domain}"][:"deletion"] += diff[2].to_i
32
45
 
33
- count[:"total"][:"addition"] += diff[1].to_i
34
- count[:"total"][:"deletion"] += diff[2].to_i
46
+ total[:"addition"] += diff[1].to_i
47
+ total[:"deletion"] += diff[2].to_i
35
48
  end
36
- # TODO more Faster! it takes 50 sec(10k / sec).
37
- sorted = count.sort_by{|a,b| -b[:"addition"] }
38
- puts Oj.dump(Hash[sorted], :mode => :compat)
49
+ if number.nil?
50
+ # TODO more Faster! it takes 50 sec(10k / sec).
51
+ sorted = count.sort_by{|a,b| -b[:"addition"] }
52
+ else
53
+ sorted = count.sort_by{|a,b| -b[:"addition"] }.first(number)
54
+ sum = Hash.new(0)
55
+ sorted.each{|c|
56
+ sum["addition"] += c[1][:"addition"]
57
+ sum["deletion"] += c[1][:"deletion"]
58
+ }
59
+ tmp = Hash.new(0)
60
+ tmp[:"addition"] = total[:"addition"] - sum["addition"]
61
+ tmp[:"deletion"] = total[:"deletion"] - sum["deletion"]
62
+ sorted << [:"others",tmp]
63
+ end
64
+ result = Hash.new
65
+ result[:'count'] = Hash.new
66
+ result[:'count'] = Hash[sorted]
67
+ result[:'infomation'] = get_info(repo,total)
68
+ puts Oj.dump(result, :mode => :compat)
39
69
  end
40
70
 
41
71
  # export
@@ -84,4 +114,11 @@ module GitAnalysis
84
114
  return diff_stat
85
115
  end
86
116
 
117
+ def self.get_info(repo,total)
118
+ info = Hash.new
119
+ info[:'last_commit_oid'] = repo.last_commit.oid
120
+ info[:'last_commit_date'] = repo.last_commit.time.to_s
121
+ info[:'total_commit'] = total
122
+ return info
123
+ end
87
124
  end
@@ -1,3 +1,3 @@
1
1
  module GitAnalysis
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_analysis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - volanja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-04 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler