Defect #13487 » repos-stats-map-users.patch
| app/controllers/repositories_controller.rb | ||
|---|---|---|
|
def graph_commits_per_author(repository)
|
||
|
commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id])
|
||
|
commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
|
||
|
changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
|
||
|
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
|
||
|
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}
|
||
|
# This is how we should do it ultimately:
|
||
|
# 1) Map committers to names
|
||
|
# 2) Identify all committers which map to the same user, leave others distinct
|
||
|
# But for now, we instead do
|
||
|
# 2') Identify all committers which map to the same name
|
||
|
author_names = commits_by_author.inject({}) {|o, r|
|
||
|
x = repository.find_committer_user(r.first)
|
||
|
o[r.first] = x && x.name || r.first.gsub(%r{\s+<.*>}, '')
|
||
|
o}
|
||
|
# Label y-axis by author names, sorted alphabetically, case insensitive
|
||
|
names = author_names.collect {|r| r.last}
|
||
|
names.uniq!.sort! {|x, y| y.casecmp(x)}
|
||
|
fields = fields + [""]*(10 - fields.length) if fields.length<10
|
||
|
commits_data = commits_by_author.inject({}) {|o, r| n = author_names[r.first] ; o[n] ||= 0 ; o[n] += r.last ; o}
|
||
|
commits_data = names.collect {|r| commits_data[r]}
|
||
|
changes_data = changes_by_author.inject({}) {|o, r| n = author_names[r.first] ; o[n] ||= 0 ; o[n] += r.last ; o}
|
||
|
changes_data = names.collect {|r| changes_data[r]}
|
||
|
# Pad data if necessary
|
||
|
names = names + [""]*(10 - names.length) if names.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,
|
||
|
:fields => fields,
|
||
|
:fields => names,
|
||
|
:stack => :side,
|
||
|
:scale_integers => true,
|
||
|
:show_data_values => false,
|
||