Class: RubyMaat::Analysis::Effort::Fragmentation
- Inherits:
-
BaseAnalysis
- Object
- BaseAnalysis
- RubyMaat::Analysis::Effort::Fragmentation
- Defined in:
- lib/ruby_maat/analysis/effort.rb
Overview
Fragmentation analysis - measures ownership distribution (fractal value)
Instance Method Summary collapse
Instance Method Details
#analyze(dataset, options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ruby_maat/analysis/effort.rb', line 105 def analyze(dataset, = {}) min_revs = [:min_revs] || 5 # Group by entity, count contributions per author entity_contributions = {} dataset.to_df.each_row do |row| entity = row["entity"] = row["author"] revision = row["revision"] entity_contributions[entity] ||= {} entity_contributions[entity][] ||= Set.new entity_contributions[entity][] << revision end # Calculate fragmentation (fractal value) for each entity results = [] entity_contributions.each do |entity, | total_revisions = .values.sum(&:size) next if total_revisions < min_revs # Calculate fractal value: 1 - sum(p_i^2) where p_i is proportion of each author sum_of_squares = .values.sum do |revisions| proportion = revisions.size.to_f / total_revisions proportion**2 end fractal_value = 1.0 - sum_of_squares results << { entity: entity, fractal_value: fractal_value.round(3) } end # Sort by fractal value descending (most fragmented first) results.sort_by! { |r| -r[:fractal_value] } to_csv_data(results, i[entity fractal_value]) end |