Class: RubyMaat::Analysis::Effort::MainDeveloperByRevisions

Inherits:
BaseAnalysis
  • Object
show all
Defined in:
lib/ruby_maat/analysis/effort.rb

Overview

Main developer by revisions - primary contributor per entity (by commit count)

Instance Method Summary collapse

Instance Method Details

#analyze(dataset, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ruby_maat/analysis/effort.rb', line 59

def analyze(dataset, options = {})
  min_revs = options[:min_revs] || 5

  # Group by entity and author, count revisions
  entity_authors = {}

  dataset.to_df.each_row do |row|
    entity = row["entity"]
    author = row["author"]
    revision = row["revision"]

    entity_authors[entity] ||= {}
    entity_authors[entity][author] ||= Set.new
    entity_authors[entity][author] << revision
  end

  # Find main developer for each entity
  results = []

  entity_authors.each do |entity, authors|
    total_revisions = authors.values.sum(&:size)
    next if total_revisions < min_revs

    # Find author with most revisions
    main_author, revisions = authors.max_by { |_author, revs| revs.size }

    total_revisions = authors.values.sum(&:size)

    results << {
      entity: entity,
      "main-dev": main_author,
      added: revisions.size, # Number of revisions by main dev
      "total-added": total_revisions,
      ownership: total_revisions.positive? ? (revisions.size.to_f / total_revisions).round(2) : 0.0
    }
  end

  # Sort by number of revisions descending
  results.sort_by! { |r| -r[:added] }

  to_csv_data(results, %i[entity main-dev added total-added ownership])
end