| 394 | 
  394 | 
  
    
   | 
  | 395 | 
  395 | 
  
      def graph_commits_per_author(repository) 
   | 
  | 396 | 
  396 | 
  
        commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id]) 
   | 
  | 397 | 
   | 
  
        commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
   | 
  | 398 | 
   | 
  
    
   | 
  | 399 | 
  397 | 
  
        changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
   | 
  | 400 | 
   | 
  
        h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
   | 
  | 401 | 
  398 | 
  
    
   | 
  | 402 | 
   | 
  
        fields = commits_by_author.collect {|r| r.first}
   | 
  | 403 | 
   | 
  
        commits_data = commits_by_author.collect {|r| r.last}
   | 
  | 404 | 
   | 
  
        changes_data = commits_by_author.collect {|r| h[r.first] || 0}
   | 
   | 
  399 | 
  
        # This is how we should do it ultimately: 
   | 
   | 
  400 | 
  
        # 1) Map committers to names 
   | 
   | 
  401 | 
  
        # 2) Identify all committers which map to the same user, leave others distinct 
   | 
   | 
  402 | 
  
        # But for now, we instead do 
   | 
   | 
  403 | 
  
        # 2') Identify all committers which map to the same name 
   | 
   | 
  404 | 
  
    
   | 
   | 
  405 | 
  
        author_names = commits_by_author.inject({}) {|o, r|
   | 
   | 
  406 | 
  
                x = repository.find_committer_user(r.first) 
   | 
   | 
  407 | 
  
                o[r.first] = x && x.name || r.first.gsub(%r{\s+<.*>}, '')
   | 
   | 
  408 | 
  
                o} 
   | 
   | 
  409 | 
  
    
   | 
   | 
  410 | 
  
        # Label y-axis by author names, sorted alphabetically, case insensitive 
   | 
   | 
  411 | 
  
        names = author_names.collect {|r| r.last}
   | 
   | 
  412 | 
  
        names.uniq!.sort! {|x, y| y.casecmp(x)}
   | 
  | 405 | 
  413 | 
  
    
   | 
  | 406 | 
   | 
  
        fields = fields + [""]*(10 - fields.length) if fields.length<10 
   | 
   | 
  414 | 
  
        commits_data = commits_by_author.inject({}) {|o, r| n = author_names[r.first] ; o[n] ||= 0 ; o[n] += r.last ; o}
   | 
   | 
  415 | 
  
        commits_data = names.collect {|r| commits_data[r]}
   | 
   | 
  416 | 
  
    
   | 
   | 
  417 | 
  
        changes_data = changes_by_author.inject({}) {|o, r| n = author_names[r.first] ; o[n] ||= 0 ; o[n] += r.last ; o}
   | 
   | 
  418 | 
  
        changes_data = names.collect {|r| changes_data[r]}
   | 
   | 
  419 | 
  
    
   | 
   | 
  420 | 
  
        # Pad data if necessary 
   | 
   | 
  421 | 
  
        names = names + [""]*(10 - names.length) if names.length<10 
   | 
  | 407 | 
  422 | 
  
        commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 
   | 
  | 408 | 
  423 | 
  
        changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 
   | 
  | 409 | 
  424 | 
  
    
   | 
  | 410 | 
   | 
  
        # Remove email adress in usernames 
   | 
  | 411 | 
   | 
  
        fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
   | 
  | 412 | 
   | 
  
    
   | 
  | 413 | 
  425 | 
  
        graph = SVG::Graph::BarHorizontal.new( 
   | 
  | 414 | 
  426 | 
  
          :height => 400, 
   | 
  | 415 | 
  427 | 
  
          :width => 800, 
   | 
  | 416 | 
   | 
  
          :fields => fields, 
   | 
   | 
  428 | 
  
          :fields => names, 
   | 
  | 417 | 
  429 | 
  
          :stack => :side, 
   | 
  | 418 | 
  430 | 
  
          :scale_integers => true, 
   | 
  | 419 | 
  431 | 
  
          :show_data_values => false, 
   |