Class: RubyMaat::Analysis::SumOfCoupling
- Inherits:
-
BaseAnalysis
- Object
- BaseAnalysis
- RubyMaat::Analysis::SumOfCoupling
- Defined in:
- lib/ruby_maat/analysis/sum_of_coupling.rb
Overview
Sum of coupling analysis - aggregated coupling metrics per entity
Instance Method Summary collapse
Instance Method Details
#analyze(dataset, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_maat/analysis/sum_of_coupling.rb', line 7 def analyze(dataset, = {}) # First run the logical coupling analysis to get coupling data coupling_analysis = LogicalCoupling.new coupling_results = coupling_analysis.analyze(dataset, ) # If no coupling results, return empty return to_csv_data([], i[entity soc]) if coupling_results.empty? # Aggregate coupling degrees per entity entity_coupling_sums = Hash.new(0) coupling_results.each_row do |row| entity = row["entity"] coupled = row["coupled"] degree = row["degree"] # Add coupling for both directions entity_coupling_sums[entity] += degree entity_coupling_sums[coupled] += degree end # Calculate sum of coupling for each entity results = entity_coupling_sums.map do |entity, total_coupling| { entity: entity, soc: total_coupling } end # Sort by sum of coupling descending results.sort_by! { |r| -r[:soc] } to_csv_data(results, i[entity soc]) end |