diff --git a/app/controllers/contributions_controller.rb b/app/controllers/contributions_controller.rb index b24740303..f36b8162f 100644 --- a/app/controllers/contributions_controller.rb +++ b/app/controllers/contributions_controller.rb @@ -10,9 +10,26 @@ class ContributionsController < ApplicationController # 计算每个分支每个人的贡献占比 project_id = @project.gpid rev = "master" + # rev = params[:rev] g = Gitlab.client begin - @static_total_per_user = g.rep_stats(project_id) + count_all = 0 + @contribution_rate = Hash.new + @static_total_per_user = g.rep_stats(project_id, :rev => rev) + @static_total_per_user.each do |static| + uname = static.uname + change_num = static.changes + if @contribution_rate.include?(uname) + @contribution_rate[uname] += change_num + else + @contribution_rate[uname] = change_num + end + count_all += change_num + end + + @contribution_rate.each do |uname, change_num| + @contribution_rate[uname] = change_num * 1.0 / count_all + end rescue render_404 return diff --git a/app/views/contributions/show.html.erb b/app/views/contributions/show.html.erb index 1476f7165..67fb360a3 100644 --- a/app/views/contributions/show.html.erb +++ b/app/views/contributions/show.html.erb @@ -6,18 +6,18 @@ - + <% @static_total_per_user.each do |static| %> - + <% end %>
用户名代码总量 增加代码 删除代码 变更代码贡献占比
<%= static.uname %><%= static.commits_num %> <%= static.add %> <%= static.del %> <%= static.changes %><%= @contribution_rate[static.uname] %>