Class: RubyMaat::Analysis::Effort::ByRevisions

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

Overview

Entity effort analysis - revisions per author per entity

Instance Method Summary collapse

Instance Method Details

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



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ruby_maat/analysis/effort.rb', line 8

def analyze(dataset, _options = {})
  # Group by entity and author, count revisions
  results = {}

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

    key = [entity, author]
    results[key] ||= {
      entity: entity,
      author: author,
      author_revs: Set.new,
      total_revs: Set.new
    }
    results[key][:author_revs] << revision
  end

  # Calculate total revisions per entity
  entity_totals = {}
  dataset.to_df.each_row do |row|
    entity = row["entity"]
    revision = row["revision"]

    entity_totals[entity] ||= Set.new
    entity_totals[entity] << revision
  end

  # Format results
  formatted_results = results.map do |(entity, author), data|
    {
      entity: entity,
      author: author,
      "author-revs": data[:author_revs].size,
      "total-revs": entity_totals[entity].size
    }
  end

  # Sort by entity, then by author revisions descending
  formatted_results.sort! do |a, b|
    entity_comparison = a[:entity] <=> b[:entity]
    entity_comparison.zero? ? b[:"author-revs"] <=> a[:"author-revs"] : entity_comparison
  end

  to_csv_data(formatted_results, i[entity author author-revs total-revs])
end