@ -463,8 +463,8 @@ update
data = graph_author_commits_per_month ( @repository )
when " author_commits_six_month "
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 +624,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 << 1 2
@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,12 +650,13 @@ 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 ,
:title = > l ( :label_revision_ plural )
:title = > l ( :label_revision_ commit_count )
)
graph . burn
end
@ -667,7 +668,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 }
@ -691,7 +692,49 @@ update
)
graph . add_data (
:data = > commits_data ,
:title = > l ( :label_revision_plural )
:title = > l ( :label_revision_commit_count )
)
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