Class: RubyMaat::Analysis::Churn::MainDeveloper

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

Overview

Main developer analysis - primary contributor per entity (by lines)

Instance Method Summary collapse

Instance Method Details

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



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/ruby_maat/analysis/churn.rb', line 162

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

  # Group contributions by entity and author
  entity_contributions = {}
  entity_totals = {}

  dataset.to_df.each_row do |row|
    entity = row["entity"]
    author = row["author"]
    added = row["loc_added"] || 0
    row["loc_deleted"] || 0

    entity_contributions[entity] ||= {}
    entity_contributions[entity][author] ||= {added: 0, revisions: Set.new}
    entity_contributions[entity][author][:added] += added
    entity_contributions[entity][author][:revisions] << row["revision"]

    entity_totals[entity] ||= 0
    entity_totals[entity] += added
  end

  # Find main developer for each entity
  results = []

  entity_contributions.each do |entity, authors|
    total_revisions = authors.values.map { |data| data[:revisions] }.reduce(Set.new, &:|).size
    next if total_revisions < min_revs

    # Find author with most added lines (tie-break by author name alphabetically)
    main_author = authors.max_by { |author, data| [data[:added], author] }
    next unless main_author

    author_name, author_data = main_author
    total_added = entity_totals[entity]
    ownership = total_added.positive? ? (author_data[:added].to_f / total_added).round(2) : 0.0

    results << {
      entity: entity,
      "main-dev": author_name,
      added: author_data[:added],
      "total-added": total_added,
      ownership: ownership
    }
  end

  # Sort by entity name
  results.sort_by! { |r| r[:entity] }

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