Project

General

Profile

Feature #2624 » merge_users_stats.diff

João Machado, 2010-03-14 01:25

View differences:

app/controllers/repositories_controller.rb (working copy)
255 255

  
256 256
  def graph_commits_per_author(repository)
257 257
    commits_by_author = repository.changesets.count(:all, :group => :committer)
258
    commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
259 258

  
260 259
    changes_by_author = repository.changes.count(:all, :group => :committer)
261 260
    h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
261

  
262
    # Aggregate data
263
    commits_data_aggregate = Hash.new(0)
264
    changes_data_aggregate = Hash.new(0)
265

  
266
    for commit in commits_by_author
267
      name = repository.find_committer_user(commit.first).to_s
268
      commits_data_aggregate[name] += commit.last
269
      changes_data_aggregate[name] += h[commit.first] || 0
270
    end
271

  
272
    # Sort fields
273
    commits_data_array = commits_data_aggregate.sort {|x, y| x.last <=> y.last}
274

  
275
    fields = commits_data_array.collect {|r| r.first}
276
    commits_data = commits_data_array.collect {|r| r.last}
277
    changes_data = fields.collect {|f| changes_data_aggregate[f]}
262 278
    
263
    fields = commits_by_author.collect {|r| r.first}
264
    commits_data = commits_by_author.collect {|r| r.last}
265
    changes_data = commits_by_author.collect {|r| h[r.first] || 0}
266
    
267 279
    fields = fields + [""]*(10 - fields.length) if fields.length<10
268 280
    commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
269 281
    changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
270 282
    
271
    # Remove email adress in usernames
272
    fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
273
    
274 283
    graph = SVG::Graph::BarHorizontal.new(
275 284
      :height => 400,
276 285
      :width => 800,
    (1-1/1)