Project

General

Profile

Feature #4455 » merge_users_stats.diff

Parent a52c9dd45ef4b42acd99d423844ac4c43bd712c5 - Ammler _, 2010-07-28 09:55

View differences:

app/controllers/repositories_controller.rb Mon Mar 22 16:30:33 2010 +0900 → app/controllers/repositories_controller.rb Sun Jul 25 05:59:15 2010 +0200
262 262

  
263 263
  def graph_commits_per_author(repository)
264 264
    commits_by_author = repository.changesets.count(:all, :group => :committer)
265
    commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
266 265

  
267 266
    changes_by_author = repository.changes.count(:all, :group => :committer)
268 267
    h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
269
    
270
    fields = commits_by_author.collect {|r| r.first}
271
    commits_data = commits_by_author.collect {|r| r.last}
272
    changes_data = commits_by_author.collect {|r| h[r.first] || 0}
268

  
269
    # Aggregate data
270
    commits_data_aggregate = Hash.new(0)
271
    changes_data_aggregate = Hash.new(0)
272

  
273
    for commit in commits_by_author
274
      name = repository.find_committer_user(commit.first).to_s
275
      commits_data_aggregate[name] += commit.last
276
      changes_data_aggregate[name] += h[commit.first] || 0
277
    end
278

  
279
    # Sort fields
280
    commits_data_array = commits_data_aggregate.sort {|x, y| x.last <=> y.last}
281

  
282
    fields = commits_data_array.collect {|r| r.first}
283
    commits_data = commits_data_array.collect {|r| r.last}
284
    changes_data = fields.collect {|f| changes_data_aggregate[f]}
273 285
    
274 286
    fields = fields + [""]*(10 - fields.length) if fields.length<10
275 287
    commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
276 288
    changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
277 289
    
278
    # Remove email adress in usernames
279
    fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
280
    
281 290
    graph = SVG::Graph::BarHorizontal.new(
282 291
      :height => 400,
283 292
      :width => 800,
(20-20/24)