add contribution rate

This commit is contained in:
nigel007 2019-06-15 21:46:17 +08:00
parent 15fe9de248
commit 0308a31d50
2 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -6,18 +6,18 @@
<table width="90%" border="0" align='center'>
<tr>
<td>用户名</td>
<td>代码总量</td>
<td>增加代码</td>
<td>删除代码</td>
<td>变更代码</td>
<td>贡献占比</td>
</tr>
<% @static_total_per_user.each do |static| %>
<tr>
<td><%= static.uname %></td>
<td><%= static.commits_num %></td>
<td><%= static.add %></td>
<td><%= static.del %></td>
<td><%= static.changes %></td>
<td><%= @contribution_rate[static.uname] %></td>
</tr>
<% end %>
</table>