lib/base/metric_analyzer.rb in metric_fu-2.0.0 vs lib/base/metric_analyzer.rb in metric_fu-2.0.1
- old
+ new
@@ -11,13 +11,13 @@
if(yaml.is_a?(String))
@yaml = YAML.load(yaml)
else
@yaml = yaml
end
- @file_ranking = Ranking.new
- @class_ranking = Ranking.new
- @method_ranking = Ranking.new
+ @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]
@@ -25,18 +25,18 @@
# 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)
@@ -60,15 +60,15 @@
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
- Location.get(first_row.file_path, first_row.class_name, nil)
+ MetricFu::Location.get(first_row.file_path, first_row.class_name, nil)
when :method
- Location.get(first_row.file_path, first_row.class_name, first_row.method_name)
+ MetricFu::Location.get(first_row.file_path, first_row.class_name, first_row.method_name)
when :file
- Location.get(first_row.file_path, nil, nil)
+ MetricFu::Location.get(first_row.file_path, nil, nil)
else
raise ArgumentError, "Item must be :class, :method, or :file"
end
end
end
@@ -145,19 +145,19 @@
end
end
def fix_row_file_path!(row)
# We know that Saikuro rows are broken
- next unless row['metric'] == :saikuro
+ # next unless row['metric'] == :saikuro
key = [row['class_name'], row['method_name']]
current_file_path = row['file_path'].to_s
correct_file_path = @class_and_method_to_file[key]
if(correct_file_path!=nil && correct_file_path.include?(current_file_path))
row['file_path'] = correct_file_path
else
# There wasn't an exact match, so we can do a substring match
- matching_file_path = file_paths.detect {|file_path|
+ matching_file_path = file_paths.detect {|file_path|
file_path!=nil && file_path.include?(current_file_path)
}
if(matching_file_path)
row['file_path'] = matching_file_path
end
@@ -178,36 +178,36 @@
@method_ranking
else
raise ArgumentError, "Invalid column name #{column_name}"
end
end
-
+
def calculate_metric_scores(granularity, analyzer)
- metric_ranking = Ranking.new
+ metric_ranking = MetricFu::Ranking.new
metric_violations = @tool_tables[analyzer.name]
metric_violations.each do |row|
location = row[granularity]
metric_ranking[location] ||= []
metric_ranking[location] << analyzer.map(row)
end
-
+
metric_ranking.each do |item, scores|
metric_ranking[item] = analyzer.reduce(scores)
end
-
+
metric_ranking
end
def add_to_master_ranking(master_ranking, metric_ranking, analyzer)
metric_ranking.each do |item, _|
master_ranking[item] ||= 0
- master_ranking[item] += analyzer.score(metric_ranking, item)
+ master_ranking[item] += analyzer.score(metric_ranking, item) # scaling? Do we just add in the raw score?
end
end
def most_common_column(column_name, size)
- #grouping = Ruport::Data::Grouping.new(@table,
+ #grouping = Ruport::Data::Grouping.new(@table,
# :by => column_name,
# :order => lambda { |g| -g.size})
get_grouping(@table, :by => column_name, :order => lambda {|g| -g.size})
values = []
grouping.each do |value, _|
@@ -221,11 +221,11 @@
return values.first
else
return values
end
end
-
+
# TODO: As we get fancier, the presenter should
# be its own class, not just a method with a long
# case statement
def present_group(metric, group)
occurences = group.size
@@ -244,11 +244,11 @@
"#{"average " if occurences > 1}complexity is %.1f" % complexity
when :flay
"found #{occurences} code duplications"
when :rcov
average_code_uncoverage = get_mean(group.column("percentage_uncovered"))
- "#{"average " if occurences > 1}uncovered code is %.1f%" % average_code_uncoverage
+ "#{"average " if occurences > 1}uncovered code is %.1f%" % average_code_uncoverage
else
raise AnalysisError, "Unknown metric #{metric}"
end
end
@@ -318,17 +318,17 @@
collection_length = collection.length
sum = 0
sum = collection.inject( nil ) { |sum,x| sum ? sum+x : x }
(sum.to_f / collection_length.to_f)
end
-
+
end
class Record
attr_reader :data
-
+
def initialize(data, columns)
@data = data
@columns = columns
end
@@ -378,10 +378,10 @@
hash[row[column_name]] ||= Table.new(:column_names => row.attributes)
hash[row[column_name]] << row
end
end
if order
- @arr = hash.sort_by &order
+ @arr = hash.sort_by &order
else
@arr = hash.to_a
end
end