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.



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
56
57
58
59
60
# File 'lib/base/metric_analyzer.rb', line 15

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.



13
14
15
# File 'lib/base/metric_analyzer.rb', line 13

def table
  @table
end

Instance Method Details

#location(item, value) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/base/metric_analyzer.rb', line 62

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/base/metric_analyzer.rb', line 84

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



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

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

#worst_files(size = nil) ⇒ Object



107
108
109
# File 'lib/base/metric_analyzer.rb', line 107

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

#worst_methods(size = nil) ⇒ Object



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

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