版本库:用户六个月代码量统计

This commit is contained in:
huang 2015-07-24 17:40:43 +08:00
parent 683456dc3a
commit ea93a68a84
1 changed files with 43 additions and 0 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"
@ -696,6 +698,47 @@ 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{<.+@.+>}, '') }
commits_by_author = repository.commits(all_author, @date_from, @date_to)
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_commits_six_month),
:show_graph_title => true
)
graph.add_data(
:data => commits_data,
:title => l(:label_revision_plural)
)
graph.burn
end
def check_hidden_repo
project = Project.find(params[:id])