Class: RubyMaat::Analysis::Churn::MainDeveloper
- Inherits:
-
BaseAnalysis
- Object
- BaseAnalysis
- RubyMaat::Analysis::Churn::MainDeveloper
- 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, = {}) min_revs = [:min_revs] || 5 # Group contributions by entity and author entity_contributions = {} entity_totals = {} dataset.to_df.each_row do |row| entity = row["entity"] = row["author"] added = row["loc_added"] || 0 row["loc_deleted"] || 0 entity_contributions[entity] ||= {} entity_contributions[entity][] ||= {added: 0, revisions: Set.new} entity_contributions[entity][][:added] += added entity_contributions[entity][][:revisions] << row["revision"] entity_totals[entity] ||= 0 entity_totals[entity] += added end # Find main developer for each entity results = [] entity_contributions.each do |entity, | total_revisions = .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) = .max_by { |, data| [data[:added], ] } next unless , = total_added = entity_totals[entity] ownership = total_added.positive? ? ([:added].to_f / total_added).round(2) : 0.0 results << { entity: entity, "main-dev": , added: [: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 |