Class: MetricAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/base/metric_analyzer.rb

Constant Summary collapse

COMMON_COLUMNS =
%w{metric}
GRANULARITIES =
%w{file_path class_name method_name}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml) ⇒ MetricAnalyzer

Returns a new instance of MetricAnalyzer.



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
55
# File 'lib/base/metric_analyzer.rb', line 10

def initialize(yaml)
  if(yaml.is_a?(String))
     @yaml = YAML.load(yaml)
   else
     @yaml = yaml
   end
  @file_ranking = MetricFu::Ranking.new
  @class_ranking = MetricFu::Ranking.new
  @method_ranking = MetricFu::Ranking.new
  rankings = [@file_ranking, @class_ranking, @method_ranking]

  tool_analyzers = [ReekAnalyzer.new, RoodiAnalyzer.new,
  FlogAnalyzer.new, ChurnAnalyzer.new, SaikuroAnalyzer.new,
  FlayAnalyzer.new, StatsAnalyzer.new, RcovAnalyzer.new]
  # TODO There is likely a clash that will happen between
  # column names eventually. We should probably auto-prefix
  # them (e.g. "roodi_problem")
  columns = COMMON_COLUMNS + GRANULARITIES + tool_analyzers.map{|analyzer| analyzer.columns}.flatten

  @table = make_table(columns)

  # These tables are an optimization. They contain subsets of the master table.
  # TODO - these should be pushed into the Table class now
  @tool_tables   = make_table_hash(columns)
  @file_tables   = make_table_hash(columns)
  @class_tables  = make_table_hash(columns)
  @method_tables = make_table_hash(columns)

  tool_analyzers.each do |analyzer|
    analyzer.generate_records(@yaml[analyzer.name], @table)
  end

  build_lookups!(table)
  process_rows!(table)

  tool_analyzers.each do |analyzer|
    GRANULARITIES.each do |granularity|
      metric_ranking = calculate_metric_scores(granularity, analyzer)
      add_to_master_ranking(ranking(granularity), metric_ranking, analyzer)
    end
  end

  rankings.each do |ranking|
    ranking.delete(nil)
  end
end

Instance Attribute Details

#tableObject

Returns the value of attribute table.



8
9
10
# File 'lib/base/metric_analyzer.rb', line 8

def table
  @table
end

Instance Method Details

#location(item, value) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/base/metric_analyzer.rb', line 57

def location(item, value)
  sub_table = get_sub_table(item, value)
  if(sub_table.length==0)
    raise AnalysisError, "The #{item.to_s} '#{value.to_s}' does not have any rows in the analysis table"
  else
    first_row = sub_table[0]
    case item
    when :class
      MetricFu::Location.get(first_row.file_path, first_row.class_name, nil)
    when :method
      MetricFu::Location.get(first_row.file_path, first_row.class_name, first_row.method_name)
    when :file
      MetricFu::Location.get(first_row.file_path, nil, nil)
    else
      raise ArgumentError, "Item must be :class, :method, or :file"
    end
  end
end

#problems_with(item, value, details = :summary, exclude_details = []) ⇒ Object

todo redo as item,value, options = {} Note that the other option for ‘details’ is :detailed (this isn’t at all clear from this method itself



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/base/metric_analyzer.rb', line 79

def problems_with(item, value, details = :summary, exclude_details = [])
  sub_table = get_sub_table(item, value)
  #grouping = Ruport::Data::Grouping.new(sub_table, :by => 'metric')
  grouping = get_grouping(sub_table, :by => 'metric')
  problems = {}
  grouping.each do |metric, table|
    if details == :summary || exclude_details.include?(metric)
      problems[metric] = present_group(metric,table)
    else
      problems[metric] = present_group_details(metric,table)
    end
  end
  problems
end

#worst_classes(size = nil) ⇒ Object



98
99
100
# File 'lib/base/metric_analyzer.rb', line 98

def worst_classes(size = nil)
  @class_ranking.top(size)
end

#worst_files(size = nil) ⇒ Object



102
103
104
# File 'lib/base/metric_analyzer.rb', line 102

def worst_files(size = nil)
  @file_ranking.top(size)
end

#worst_methods(size = nil) ⇒ Object



94
95
96
# File 'lib/base/metric_analyzer.rb', line 94

def worst_methods(size = nil)
  @method_ranking.top(size)
end