Merge branch 'szzh' into develop

This commit is contained in:
huang 2015-07-26 14:25:28 +08:00
commit cdd201daae
7 changed files with 153 additions and 26 deletions

View File

@ -465,6 +465,8 @@ update
data = author_commits_six_month(@repository)
when "author_qoc_per_author"
data = graph_author_qoc_per_author(@repository)
when "author_code_six_months"
data = author_code_six_month(@repository)
end
if data
headers["Content-Type"] = "image/svg+xml"
@ -624,14 +626,14 @@ update
graph.burn
end
# 用户每月提交次数
# 用户最近一年的提交次数
def graph_author_commits_per_month(repository)
@date_to = Date.today
@date_from = @date_to << 1
@date_from = @date_to << 12
@date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day)
commits_by_author = Changeset.count(:all, :group => :committer,
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(40)
commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25)
fields = commits_by_author.collect {|r| r.first}
commits_data = commits_by_author.collect {|r| r.last}
@ -650,8 +652,9 @@ update
:scale_integers => true,
:show_data_values => true,
:rotate_y_labels => false,
:graph_title => l(:label_author_commits_per_month),
:show_graph_title => true
:graph_title => l(:label_author_commits_year),
:show_graph_title => true,
:no_css => true
)
graph.add_data(
:data => commits_data,
@ -667,7 +670,7 @@ update
@date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day)
commits_by_author = Changeset.count(:all, :group => :committer,
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(40)
commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25)
fields = commits_by_author.collect {|r| r.first}
commits_data = commits_by_author.collect {|r| r.last}
@ -696,6 +699,48 @@ update
graph.burn
end
# 最近六个月代码量统计
def author_code_six_month(repository)
@date_to = Date.today
@date_from = @date_to << 6
@date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day)
commits_by_author = Changeset.count(:group => :committer, :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(40)
all_author = []
commits_by_author.each do |cba|
all_author << cba.first
end
# all_author = all_author.collect {|c| c.gsub(%r{/ /<.+@.+>}, '') }
all_author = all_author.collect {|c| c.split.first }
commits_by_author = repository.commits(all_author, "#{@date_from}", "#{@date_to}", repository.id == 150 ? "szzh" : 'master')
fields = commits_by_author.collect {|r| r.first}
commits_data = commits_by_author.collect {|r| r.last}
fields = fields + [""]*(10 - fields.length) if fields.length<10
commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
# Remove email adress in usernames
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
graph = SVG::Graph::BarHorizontal.new(
:height => 400,
:width => 600,
:fields => fields,
:stack => :side,
:scale_integers => true,
:show_data_values => true,
:rotate_y_labels => false,
:graph_title => l(:label_author_code_six_month),
:show_graph_title => true
)
graph.add_data(
:data => commits_data,
:title => l(:lable_revision_code_count)
)
graph.burn
end
def check_hidden_repo
project = Project.find(params[:id])

View File

@ -38,6 +38,12 @@ class Repository::Git < Repository
'Git'
end
def commits(authors, start_date, end_date, branch='master')
scm.commits(authors, start_date, end_date,branch).map {|commit|
[commit[:author], commit[:num]]
}
end
def report_last_commit
extra_report_last_commit
end

View File

@ -149,29 +149,65 @@
<div class="leftbox mt10">
<ul class="leftbox_ul_left">
<% if !@user.user_extensions.nil? && @user.user_extensions.identity == 0 %>
<li>创建课程&nbsp;:</li>
<li>发布作业&nbsp;:</li>
<% if(get_create_course_count(@user)) == 0 %>
<li>创建课程&nbsp;:</li>
<% end %>
<% if(get_homework_commons_count(@user)) == 0 %>
<li>发布作业&nbsp;:</li>
<% end %>
<% end %>
<% if (get_join_course_count(@user) != 0) %>
<li>加入课程&nbsp;:</li>
<% end %>
<% if @user.user_extensions.identity == 0 %>
<li>参加匿评&nbsp;:</li>
<% end %>
<% if (get_projectandcourse_attachment_count(@user) != 0) %>
<li>发布资源&nbsp;:</li>
<% end %>
<% if (get_create_project_count(@user) != 0) %>
<li>创建项目&nbsp;:</li>
<% end %>
<% if (get_join_project_count(@user) != 0) %>
<li>加入项目&nbsp;:</li>
<% end %>
<% if (get_create_issue_count(@user) != 0) %>
<li>发布缺陷&nbsp;:</li>
<% end %>
<% if (get_resolve_issue_count(@user) != 0) %>
<li>解决缺陷&nbsp;:</li>
<% end %>
<li>加入课程&nbsp;:</li>
<li>参加匿评&nbsp;:</li>
<li>发布资源&nbsp;:</li>
<li>创建项目&nbsp;:</li>
<li>加入项目&nbsp;:</li>
<li>发布缺陷&nbsp;:</li>
<li>解决缺陷&nbsp;:</li>
</ul>
<ul class="leftbox_ul_right c_dgrey">
<% if !@user.user_extensions.nil? && @user.user_extensions.identity == 0 %>
<li><%= get_create_course_count(@user) %></li>
<li><%= get_homework_commons_count(@user) %></li>
<% if(get_create_course_count(@user)) == 0 %>
<li><%= get_create_course_count(@user) %></li>
<% end %>
<% if(get_homework_commons_count(@user)) == 0 %>
<li><%= get_homework_commons_count(@user) %></li>
<% end %>
<% end %>
<% if (get_join_course_count(@user) != 0) %>
<li><%= get_join_course_count(@user) %></li>
<% end %>
<% if @user.user_extensions.identity == 0 %>
<li><%= get_anonymous_evaluation_count(@user) %></li>
<% end %>
<% if (get_projectandcourse_attachment_count(@user) != 0) %>
<li><%= get_projectandcourse_attachment_count(@user) %></li>
<% end %>
<% if (get_create_project_count(@user) != 0) %>
<li><%= get_create_project_count(@user) %></li>
<% end %>
<% if (get_join_project_count(@user) != 0) %>
<li><%= get_join_project_count(@user) %></li>
<% end %>
<% if (get_create_issue_count(@user) != 0) %>
<li><%= get_create_issue_count(@user) %></li>
<% end %>
<% if (get_resolve_issue_count(@user) != 0) %>
<li><%= get_resolve_issue_count(@user) %></li>
<% end %>
<li><%= get_join_course_count(@user) %></li>
<li><%= get_anonymous_evaluation_count(@user) %></li>
<li><%= get_projectandcourse_attachment_count(@user) %></li>
<li><%= get_create_project_count(@user) %></li>
<li><%= get_join_project_count(@user) %></li>
<li><%= get_create_issue_count(@user) %></li>
<li><%= get_resolve_issue_count(@user) %></li>
</ul>
<div class="cl"></div>
</div>

View File

@ -540,7 +540,6 @@
$('#my_account_form_btn').click();
});
$('#my_password_form_link').click(function(){
// alert("密码修改成功,请重新登录!");
$('#my_password_form_btn').click();
});
});

View File

@ -25,5 +25,13 @@
<%# 用户最近一年的提交次数 %>
<%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_qoc_per_author")) %>
</p>
<p style="padding-top: 50px;">
<%# 用户最近六个月的代码量 %>
<%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_code_six_months")) %>
</p>
<p style="padding-top: 50px;">
<%# 用户最近一年的代码量 %>
<%= tag("embed", :width => 670, :height => 400, :type => "image/svg+xml", :src => url_for(:controller => 'repositories', :action => 'graph', :id => @project, :repository_id => @repository.identifier_param, :graph => "author_code_year")) %>
</p>
<p><%= link_to l(:button_back), :action => 'show', :id => @project %></p>
<% html_title(l(:label_repository), l(:label_statistics)) -%>

View File

@ -669,6 +669,7 @@ zh:
label_tag: 标签
label_revision: 修订
label_revision_plural: 修订
lable_revision_code_count: 代码量
label_revision_id: 修订 %{value}
label_associated_revisions: 相关修订版本
label_added: 已添加
@ -716,8 +717,10 @@ zh:
label_commits_per_month: 每月提交次数
label_commits_per_author: 每用户提交次数
label_author_commits_per_month: 用户最近一月的提交次数
label_author_commits_six_month: 用户最近六个月提交次数
label_author_commits_six_month: 用户最近六个月提交次数
label_author_commits_year: 最近一年的提交次数
label_author_code_six_month: 用户最近六个月代码量
label_author_code_year: 用户最近一年代码量
label_view_diff: 查看差别
label_diff_inline: 直列
label_diff_side_by_side: 并排

View File

@ -380,6 +380,36 @@ module Redmine
nil
end
def parse_commit(commits)
sum = {file: 0, insertion: 0, deletion: 0}
commits.split("\n").each do |commit|
if /(\d+)\s+?file/ =~ commit
sum[:file] += $1 .to_i
end
if /(\d+)\s+?insertion/ =~ commit
sum[:insertion] += $1.to_i
end
if /(\d+)\s+?deletion/ =~ commit
sum[:deletion] += $1.to_i
end
end
sum[:insertion] + sum[:deletion]
end
def commits(authors, start_date, end_date, branch='master')
rs = []
authors.each do |author|
cmd_args = %W|log #{branch} --pretty=tformat: --shortstat --author=#{author} --since=#{start_date} --until=#{end_date}|
commits = ''
git_cmd(cmd_args) do |io|
commits = io.read
end
logger.info "git log output for #{author} #{commits}"
rs << {author: author, num: parse_commit(commits)}
end
rs
end
class Revision < Redmine::Scm::Adapters::Revision
# Returns the readable identifier
def format_identifier