Feature #2624 » merge_users_stats.diff
| app/controllers/repositories_controller.rb (working copy) | ||
|---|---|---|
|
def graph_commits_per_author(repository)
|
||
|
commits_by_author = repository.changesets.count(:all, :group => :committer)
|
||
|
commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
|
||
|
changes_by_author = repository.changes.count(:all, :group => :committer)
|
||
|
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
|
||
|
# Aggregate data
|
||
|
commits_data_aggregate = Hash.new(0)
|
||
|
changes_data_aggregate = Hash.new(0)
|
||
|
for commit in commits_by_author
|
||
|
name = repository.find_committer_user(commit.first).to_s
|
||
|
commits_data_aggregate[name] += commit.last
|
||
|
changes_data_aggregate[name] += h[commit.first] || 0
|
||
|
end
|
||
|
# Sort fields
|
||
|
commits_data_array = commits_data_aggregate.sort {|x, y| x.last <=> y.last}
|
||
|
fields = commits_data_array.collect {|r| r.first}
|
||
|
commits_data = commits_data_array.collect {|r| r.last}
|
||
|
changes_data = fields.collect {|f| changes_data_aggregate[f]}
|
||
|
|
||
|
fields = commits_by_author.collect {|r| r.first}
|
||
|
commits_data = commits_by_author.collect {|r| r.last}
|
||
|
changes_data = commits_by_author.collect {|r| h[r.first] || 0}
|
||
|
|
||
|
fields = fields + [""]*(10 - fields.length) if fields.length<10
|
||
|
commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
|
||
|
changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
|
||
|
|
||
|
# Remove email adress in usernames
|
||
|
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
|
||
|
|
||
|
graph = SVG::Graph::BarHorizontal.new(
|
||
|
:height => 400,
|
||
|
:width => 800,
|
||