goldstar-metric_fu 1.5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/HISTORY +208 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README +28 -0
  4. data/Rakefile +16 -0
  5. data/TODO +9 -0
  6. data/lib/base/base_template.rb +151 -0
  7. data/lib/base/configuration.rb +190 -0
  8. data/lib/base/generator.rb +162 -0
  9. data/lib/base/graph.rb +39 -0
  10. data/lib/base/md5_tracker.rb +52 -0
  11. data/lib/base/report.rb +100 -0
  12. data/lib/generators/churn.rb +28 -0
  13. data/lib/generators/flay.rb +31 -0
  14. data/lib/generators/flog.rb +98 -0
  15. data/lib/generators/rails_best_practices.rb +25 -0
  16. data/lib/generators/rcov.rb +85 -0
  17. data/lib/generators/reek.rb +60 -0
  18. data/lib/generators/roodi.rb +27 -0
  19. data/lib/generators/saikuro.rb +224 -0
  20. data/lib/generators/stats.rb +59 -0
  21. data/lib/graphs/engines/bluff.rb +113 -0
  22. data/lib/graphs/engines/gchart.rb +157 -0
  23. data/lib/graphs/flay_grapher.rb +18 -0
  24. data/lib/graphs/flog_grapher.rb +57 -0
  25. data/lib/graphs/grapher.rb +11 -0
  26. data/lib/graphs/rails_best_practices_grapher.rb +19 -0
  27. data/lib/graphs/rcov_grapher.rb +18 -0
  28. data/lib/graphs/reek_grapher.rb +30 -0
  29. data/lib/graphs/roodi_grapher.rb +18 -0
  30. data/lib/graphs/stats_grapher.rb +20 -0
  31. data/lib/metric_fu.rb +37 -0
  32. data/lib/templates/awesome/awesome_template.rb +37 -0
  33. data/lib/templates/awesome/churn.html.erb +58 -0
  34. data/lib/templates/awesome/css/buttons.css +82 -0
  35. data/lib/templates/awesome/css/default.css +91 -0
  36. data/lib/templates/awesome/css/integrity.css +335 -0
  37. data/lib/templates/awesome/css/reset.css +7 -0
  38. data/lib/templates/awesome/flay.html.erb +34 -0
  39. data/lib/templates/awesome/flog.html.erb +55 -0
  40. data/lib/templates/awesome/index.html.erb +31 -0
  41. data/lib/templates/awesome/layout.html.erb +30 -0
  42. data/lib/templates/awesome/rails_best_practices.html.erb +27 -0
  43. data/lib/templates/awesome/rcov.html.erb +42 -0
  44. data/lib/templates/awesome/reek.html.erb +40 -0
  45. data/lib/templates/awesome/roodi.html.erb +27 -0
  46. data/lib/templates/awesome/saikuro.html.erb +71 -0
  47. data/lib/templates/awesome/stats.html.erb +51 -0
  48. data/lib/templates/javascripts/bluff-min.js +1 -0
  49. data/lib/templates/javascripts/excanvas.js +35 -0
  50. data/lib/templates/javascripts/js-class.js +1 -0
  51. data/lib/templates/standard/churn.html.erb +31 -0
  52. data/lib/templates/standard/default.css +64 -0
  53. data/lib/templates/standard/flay.html.erb +34 -0
  54. data/lib/templates/standard/flog.html.erb +57 -0
  55. data/lib/templates/standard/index.html.erb +41 -0
  56. data/lib/templates/standard/rails_best_practices.html.erb +29 -0
  57. data/lib/templates/standard/rcov.html.erb +43 -0
  58. data/lib/templates/standard/reek.html.erb +42 -0
  59. data/lib/templates/standard/roodi.html.erb +29 -0
  60. data/lib/templates/standard/saikuro.html.erb +84 -0
  61. data/lib/templates/standard/standard_template.rb +26 -0
  62. data/lib/templates/standard/stats.html.erb +55 -0
  63. data/spec/base/base_template_spec.rb +161 -0
  64. data/spec/base/configuration_spec.rb +276 -0
  65. data/spec/base/generator_spec.rb +223 -0
  66. data/spec/base/graph_spec.rb +24 -0
  67. data/spec/base/md5_tracker_spec.rb +57 -0
  68. data/spec/base/report_spec.rb +139 -0
  69. data/spec/generators/churn_spec.rb +41 -0
  70. data/spec/generators/flay_spec.rb +105 -0
  71. data/spec/generators/flog_spec.rb +70 -0
  72. data/spec/generators/reek_spec.rb +134 -0
  73. data/spec/generators/saikuro_spec.rb +58 -0
  74. data/spec/generators/stats_spec.rb +74 -0
  75. data/spec/graphs/engines/bluff_spec.rb +19 -0
  76. data/spec/graphs/engines/gchart_spec.rb +156 -0
  77. data/spec/graphs/flay_grapher_spec.rb +56 -0
  78. data/spec/graphs/flog_grapher_spec.rb +108 -0
  79. data/spec/graphs/rcov_grapher_spec.rb +56 -0
  80. data/spec/graphs/reek_grapher_spec.rb +65 -0
  81. data/spec/graphs/roodi_grapher_spec.rb +56 -0
  82. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  83. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  84. data/spec/resources/saikuro/index_cyclo.html +155 -0
  85. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  86. data/spec/resources/yml/20090630.yml +7922 -0
  87. data/spec/spec.opts +6 -0
  88. data/spec/spec_helper.rb +7 -0
  89. data/tasks/metric_fu.rake +22 -0
  90. metadata +396 -0
@@ -0,0 +1,27 @@
1
+ module MetricFu
2
+ class Roodi < Generator
3
+
4
+ def emit
5
+ files_to_analyze = MetricFu.roodi[:dirs_to_roodi].map{|dir| Dir[File.join(dir, "**/*.rb")] }
6
+ files = remove_excluded_files(files_to_analyze.flatten)
7
+ config = MetricFu.roodi[:roodi_config] ? "-config=#{MetricFu.roodi[:roodi_config]}" : ""
8
+ @output = `roodi #{config} #{files.join(" ")}`
9
+ end
10
+
11
+ def analyze
12
+ @matches = @output.chomp.split("\n").map{|m| m.split(" - ") }
13
+ total = @matches.pop
14
+ @matches.reject! {|array| array.empty? }
15
+ @matches.map! do |match|
16
+ file, line = match[0].split(':')
17
+ problem = match[1]
18
+ {:file => file, :line => line, :problem => problem}
19
+ end
20
+ @roodi_results = {:total => total, :problems => @matches}
21
+ end
22
+
23
+ def to_h
24
+ {:roodi => @roodi_results}
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,224 @@
1
+ module MetricFu
2
+
3
+ class Saikuro < Generator
4
+
5
+ def emit
6
+ options_string = MetricFu.saikuro.inject("") do |options, option|
7
+ options + "--#{option.join(' ')} " unless option == :input_directory
8
+ end
9
+
10
+ MetricFu.saikuro[:input_directory].each do |input_dir|
11
+ options_string += "--input_directory #{input_dir} "
12
+ end
13
+ sh %{saikuro #{options_string}} do |ok, response|
14
+ unless ok
15
+ puts "Saikuro failed with exit status: #{response.exitstatus}"
16
+ exit 1
17
+ end
18
+ end
19
+ end
20
+
21
+ def format_directories
22
+ dirs = MetricFu.saikuro[:input_directory].join(" | ")
23
+ "\"#{dirs}\""
24
+ end
25
+
26
+ def analyze
27
+ @files = sort_files(assemble_files)
28
+ @classes = sort_classes(assemble_classes(@files))
29
+ @meths = sort_methods(assemble_methods(@files))
30
+ end
31
+
32
+ def to_h
33
+ files = @files.map do |file|
34
+ my_file = file.to_h
35
+ my_file[:filename] = file.filename
36
+ my_file
37
+ end
38
+ {:saikuro => {:files => files,
39
+ :classes => @classes.map {|c| c.to_h},
40
+ :methods => @meths.map {|m| m.to_h}
41
+ }
42
+ }
43
+ end
44
+
45
+ private
46
+ def sort_methods(methods)
47
+ methods.sort_by {|method| method.complexity.to_i}.reverse
48
+ end
49
+
50
+ def assemble_methods(files)
51
+ methods = []
52
+ files.each do |file|
53
+ file.elements.each do |element|
54
+ element.defs.each do |defn|
55
+ defn.name = "#{element.name}##{defn.name}"
56
+ methods << defn
57
+ end
58
+ end
59
+ end
60
+ methods
61
+ end
62
+
63
+ def sort_classes(classes)
64
+ classes.sort_by {|k| k.complexity.to_i}.reverse
65
+ end
66
+
67
+ def assemble_classes(files)
68
+ files.map {|f| f.elements}.flatten
69
+ end
70
+
71
+ def sort_files(files)
72
+ files.sort_by do |file|
73
+ file.elements.
74
+ max {|a,b| a.complexity.to_i <=> b.complexity.to_i}.
75
+ complexity.to_i
76
+ end.reverse
77
+ end
78
+
79
+ def assemble_files
80
+ files = []
81
+ Dir.glob("#{metric_directory}/**/*.html").each do |path|
82
+ if Saikuro::SFile.is_valid_text_file?(path)
83
+ file = Saikuro::SFile.new(path)
84
+ if file
85
+ files << file
86
+ end
87
+ end
88
+ end
89
+ files
90
+ end
91
+
92
+ end
93
+
94
+ class Saikuro::SFile
95
+
96
+ attr_reader :elements
97
+
98
+ def initialize(path)
99
+ @path = path
100
+ @file_handle = File.open(@path, "r")
101
+ @elements = []
102
+ get_elements
103
+ ensure
104
+ @file_handle.close if @file_handle
105
+ end
106
+
107
+ def self.is_valid_text_file?(path)
108
+ File.open(path, "r") do |f|
109
+ if f.eof? || !f.readline.match(/--/)
110
+ return false
111
+ else
112
+ return true
113
+ end
114
+ end
115
+ end
116
+
117
+ def filename
118
+ File.basename(@path, '_cyclo.html')
119
+ end
120
+
121
+ def to_h
122
+ merge_classes
123
+ {:classes => @elements}
124
+ end
125
+
126
+ def get_elements
127
+ begin
128
+ while (line = @file_handle.readline) do
129
+ return [] if line.nil? || line !~ /\S/
130
+ element ||= nil
131
+ if line.match /START/
132
+ unless element.nil?
133
+ @elements << element
134
+ element = nil
135
+ end
136
+ line = @file_handle.readline
137
+ element = Saikuro::ParsingElement.new(line)
138
+ elsif line.match /END/
139
+ @elements << element if element
140
+ element = nil
141
+ else
142
+ element << line if element
143
+ end
144
+ end
145
+ rescue EOFError
146
+ nil
147
+ end
148
+ end
149
+
150
+
151
+ def merge_classes
152
+ new_elements = []
153
+ get_class_names.each do |target_class|
154
+ elements = @elements.find_all {|el| el.name == target_class }
155
+ complexity = 0
156
+ lines = 0
157
+ defns = []
158
+ elements.each do |el|
159
+ complexity += el.complexity.to_i
160
+ lines += el.lines.to_i
161
+ defns << el.defs
162
+ end
163
+
164
+ new_element = {:class_name => target_class,
165
+ :complexity => complexity,
166
+ :lines => lines,
167
+ :methods => defns.flatten.map {|d| d.to_h}}
168
+ new_element[:methods] = new_element[:methods].
169
+ sort_by {|x| x[:complexity] }.
170
+ reverse
171
+
172
+ new_elements << new_element
173
+ end
174
+ @elements = new_elements if new_elements
175
+ end
176
+
177
+ def get_class_names
178
+ class_names = []
179
+ @elements.each do |element|
180
+ unless class_names.include?(element.name)
181
+ class_names << element.name
182
+ end
183
+ end
184
+ class_names
185
+ end
186
+
187
+ end
188
+
189
+ class Saikuro::ParsingElement
190
+ TYPE_REGEX=/Type:(.*) Name/
191
+ NAME_REGEX=/Name:(.*) Complexity/
192
+ COMPLEXITY_REGEX=/Complexity:(.*) Lines/
193
+ LINES_REGEX=/Lines:(.*)/
194
+
195
+ attr_reader :complexity, :lines, :defs, :element_type
196
+ attr_accessor :name
197
+
198
+ def initialize(line)
199
+ @line = line
200
+ @element_type = line.match(TYPE_REGEX)[1].strip
201
+ @name = line.match(NAME_REGEX)[1].strip
202
+ @complexity = line.match(COMPLEXITY_REGEX)[1].strip
203
+ @lines = line.match(LINES_REGEX)[1].strip
204
+ @defs = []
205
+ end
206
+
207
+ def <<(line)
208
+ @defs << Saikuro::ParsingElement.new(line)
209
+ end
210
+
211
+ def to_h
212
+ base = {:name => @name, :complexity => @complexity.to_i, :lines => @lines.to_i}
213
+ unless @defs.empty?
214
+ defs = @defs.map do |my_def|
215
+ my_def = my_def.to_h
216
+ my_def.delete(:defs)
217
+ my_def
218
+ end
219
+ base[:defs] = defs
220
+ end
221
+ return base
222
+ end
223
+ end
224
+ end
@@ -0,0 +1,59 @@
1
+ module MetricFu
2
+
3
+ class Stats < Generator
4
+
5
+ def emit
6
+ `rake stats > #{metric_directory + '/stats.txt'}`
7
+ end
8
+
9
+ def analyze
10
+ output = File.open(metric_directory + '/stats.txt').read
11
+ lines = remove_noise(output)
12
+
13
+ @stats = {}
14
+
15
+ set_global_stats(lines.pop)
16
+ set_granular_stats(lines)
17
+
18
+ @stats
19
+ end
20
+
21
+ def to_h
22
+ {:stats => @stats}
23
+ end
24
+
25
+ private
26
+
27
+ def remove_noise(output)
28
+ lines = output.split("\n")
29
+ lines = lines.find_all {|line| line[0].chr != "+" }
30
+ lines = lines.find_all {|line| line[0].chr != "(" }
31
+ lines.shift
32
+ lines
33
+ end
34
+
35
+ def set_global_stats(totals)
36
+ totals = totals.split(" ").find_all {|el| ! el.empty? }
37
+ @stats[:codeLOC] = totals[0].match(/\d.*/)[0].to_i
38
+ @stats[:testLOC] = totals[1].match(/\d.*/)[0].to_i
39
+ @stats[:code_to_test_ratio] = totals[2].match(/1\:(\d.*)/)[1].to_f
40
+ end
41
+
42
+ def set_granular_stats(lines)
43
+ @stats[:lines] = lines.map do |line|
44
+ elements = line.split("|")
45
+ elements.map! {|el| el.strip }
46
+ elements = elements.find_all {|el| ! el.empty? }
47
+ info_line = {}
48
+ info_line[:name] = elements.shift
49
+ elements.map! {|el| el.to_i }
50
+ [:lines, :loc, :classes, :methods,
51
+ :methods_per_class, :loc_per_method].each do |sym|
52
+ info_line[sym] = elements.shift
53
+ end
54
+ info_line
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,113 @@
1
+ require 'active_support'
2
+
3
+ module MetricFu
4
+ class Grapher
5
+ BLUFF_GRAPH_SIZE = "1000x600"
6
+ BLUFF_DEFAULT_OPTIONS = <<-EOS
7
+ var g = new Bluff.Line('graph', "#{BLUFF_GRAPH_SIZE}");
8
+ g.theme_37signals();
9
+ g.tooltips = true;
10
+ g.title_font_size = "24px"
11
+ g.legend_font_size = "12px"
12
+ g.marker_font_size = "10px"
13
+ EOS
14
+ end
15
+
16
+ class FlayBluffGrapher < FlayGrapher
17
+ def graph!
18
+ content = <<-EOS
19
+ #{BLUFF_DEFAULT_OPTIONS}
20
+ g.title = 'Flay: duplication';
21
+ g.data('flay', [#{@flay_score.join(',')}]);
22
+ g.labels = #{@labels.to_json};
23
+ g.draw();
24
+ EOS
25
+ File.open(File.join(MetricFu.output_directory, 'flay.js'), 'w') {|f| f << content }
26
+ end
27
+ end
28
+
29
+ class FlogBluffGrapher < FlogGrapher
30
+ def graph!
31
+ content = <<-EOS
32
+ #{BLUFF_DEFAULT_OPTIONS}
33
+ g.title = 'Flog: code complexity';
34
+ g.data('average', [#{@flog_average.join(',')}]);
35
+ g.data('top 5% average', [#{@top_five_percent_average.join(',')}])
36
+ g.labels = #{@labels.to_json};
37
+ g.draw();
38
+ EOS
39
+ File.open(File.join(MetricFu.output_directory, 'flog.js'), 'w') {|f| f << content }
40
+ end
41
+ end
42
+
43
+ class RcovBluffGrapher < RcovGrapher
44
+ def graph!
45
+ content = <<-EOS
46
+ #{BLUFF_DEFAULT_OPTIONS}
47
+ g.title = 'Rcov: code coverage';
48
+ g.data('rcov', [#{@rcov_percent.join(',')}]);
49
+ g.labels = #{@labels.to_json};
50
+ g.draw();
51
+ EOS
52
+ File.open(File.join(MetricFu.output_directory, 'rcov.js'), 'w') {|f| f << content }
53
+ end
54
+ end
55
+
56
+ class ReekBluffGrapher < ReekGrapher
57
+ def graph!
58
+ legend = @reek_count.keys.sort
59
+ data = ""
60
+ legend.each do |name|
61
+ data += "g.data('#{name}', [#{@reek_count[name].join(',')}])\n"
62
+ end
63
+ content = <<-EOS
64
+ #{BLUFF_DEFAULT_OPTIONS}
65
+ g.title = 'Reek: code smells';
66
+ #{data}
67
+ g.labels = #{@labels.to_json};
68
+ g.draw();
69
+ EOS
70
+ File.open(File.join(MetricFu.output_directory, 'reek.js'), 'w') {|f| f << content }
71
+ end
72
+ end
73
+
74
+ class RoodiBluffGrapher < RoodiGrapher
75
+ def graph!
76
+ content = <<-EOS
77
+ #{BLUFF_DEFAULT_OPTIONS}
78
+ g.title = 'Roodi: design problems';
79
+ g.data('roodi', [#{@roodi_count.join(',')}]);
80
+ g.labels = #{@labels.to_json};
81
+ g.draw();
82
+ EOS
83
+ File.open(File.join(MetricFu.output_directory, 'roodi.js'), 'w') {|f| f << content }
84
+ end
85
+ end
86
+
87
+ class StatsBluffGrapher < StatsGrapher
88
+ def graph!
89
+ content = <<-EOS
90
+ #{BLUFF_DEFAULT_OPTIONS}
91
+ g.title = 'Stats: LOC & LOT';
92
+ g.data('LOC', [#{@loc_counts.join(',')}]);
93
+ g.data('LOT', [#{@lot_counts.join(',')}])
94
+ g.labels = #{@labels.to_json};
95
+ g.draw();
96
+ EOS
97
+ File.open(File.join(MetricFu.output_directory, 'stats.js'), 'w') {|f| f << content }
98
+ end
99
+ end
100
+
101
+ class RailsBestPracticesBluffGrapher < RailsBestPracticesGrapher
102
+ def graph!
103
+ content = <<-EOS
104
+ #{BLUFF_DEFAULT_OPTIONS}
105
+ g.title = 'Rails Best Practices: design problems';
106
+ g.data('rails_best_practices', [#{@rails_best_practices_count.join(',')}]);
107
+ g.labels = #{@labels.to_json};
108
+ g.draw();
109
+ EOS
110
+ File.open(File.join(MetricFu.output_directory, 'rails_best_practices.js'), 'w') {|f| f << content }
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,157 @@
1
+ module MetricFu
2
+ module GchartGrapher
3
+ COLORS = %w{009999 FF7400 A60000 008500 E6399B 344AD7 00B860 D5CCB9}
4
+ GCHART_GRAPH_SIZE = "945x317" # maximum permitted image size is 300000 pixels
5
+
6
+ NUMBER_OF_TICKS = 6
7
+ def determine_y_axis_scale(values)
8
+ values.collect! {|val| val || 0.0 }
9
+ if values.empty?
10
+ @max_value = 10
11
+ @yaxis = [0, 2, 4, 6, 8, 10]
12
+ else
13
+ @max_value = values.max + Integer(0.1 * values.max)
14
+ portion_size = (@max_value / (NUMBER_OF_TICKS - 1).to_f).ceil
15
+ @yaxis = []
16
+ NUMBER_OF_TICKS.times {|n| @yaxis << Integer(portion_size * n) }
17
+ @max_value = @yaxis.last
18
+ end
19
+ end
20
+ end
21
+
22
+ class Grapher
23
+ include MetricFu::GchartGrapher
24
+
25
+ def self.require_graphing_gem
26
+ require 'gchart' if MetricFu.graph_engine == :gchart
27
+ rescue LoadError
28
+ puts "#"*99 + "\n" +
29
+ "If you want to use google charts for graphing, you'll need to install the googlecharts rubygem." +
30
+ "\n" + "#"*99
31
+ end
32
+ end
33
+
34
+ class FlayGchartGrapher < FlayGrapher
35
+ def graph!
36
+ determine_y_axis_scale(@flay_score)
37
+ url = Gchart.line(
38
+ :size => GCHART_GRAPH_SIZE,
39
+ :title => URI.escape("Flay: duplication"),
40
+ :data => @flay_score,
41
+ :max_value => @max_value,
42
+ :axis_with_labels => 'x,y',
43
+ :axis_labels => [@labels.values, @yaxis],
44
+ :format => 'file',
45
+ :filename => File.join(MetricFu.output_directory, 'flay.png'))
46
+ end
47
+ end
48
+
49
+ class FlogGchartGrapher < FlogGrapher
50
+ def graph!
51
+ determine_y_axis_scale(@top_five_percent_average + @flog_average)
52
+ url = Gchart.line(
53
+ :size => GCHART_GRAPH_SIZE,
54
+ :title => URI.escape("Flog: code complexity"),
55
+ :data => [@flog_average, @top_five_percent_average],
56
+ :stacked => false,
57
+ :bar_colors => COLORS[0..1],
58
+ :legend => ['average', 'top 5% average'],
59
+ :custom => "chdlp=t",
60
+ :max_value => @max_value,
61
+ :axis_with_labels => 'x,y',
62
+ :axis_labels => [@labels.values, @yaxis],
63
+ :format => 'file',
64
+ :filename => File.join(MetricFu.output_directory, 'flog.png'))
65
+ end
66
+ end
67
+
68
+ class RcovGchartGrapher < RcovGrapher
69
+ def graph!
70
+ url = Gchart.line(
71
+ :size => GCHART_GRAPH_SIZE,
72
+ :title => URI.escape("Rcov: code coverage"),
73
+ :data => self.rcov_percent,
74
+ :max_value => 101,
75
+ :axis_with_labels => 'x,y',
76
+ :axis_labels => [self.labels.values, [0,20,40,60,80,100]],
77
+ :format => 'file',
78
+ :filename => File.join(MetricFu.output_directory, 'rcov.png')
79
+ )
80
+ end
81
+ end
82
+
83
+ class ReekGchartGrapher < ReekGrapher
84
+ def graph!
85
+ determine_y_axis_scale(@reek_count.values.flatten.uniq)
86
+ values = []
87
+ legend = @reek_count.keys.sort
88
+ legend.collect {|k| values << @reek_count[k]}
89
+
90
+ url = Gchart.line(
91
+ :size => GCHART_GRAPH_SIZE,
92
+ :title => URI.escape("Reek: code smells"),
93
+ :data => values,
94
+ :stacked => false,
95
+ :bar_colors => COLORS,
96
+ :legend => legend,
97
+ :custom => "chdlp=t",
98
+ :max_value => @max_value,
99
+ :axis_with_labels => 'x,y',
100
+ :axis_labels => [@labels.values, @yaxis],
101
+ :format => 'file',
102
+ :filename => File.join(MetricFu.output_directory, 'reek.png'))
103
+ end
104
+ end
105
+
106
+ class RoodiGchartGrapher < RoodiGrapher
107
+ def graph!
108
+ determine_y_axis_scale(@roodi_count)
109
+ url = Gchart.line(
110
+ :size => GCHART_GRAPH_SIZE,
111
+ :title => URI.escape("Roodi: potential design problems"),
112
+ :data => @roodi_count,
113
+ :max_value => @max_value,
114
+ :axis_with_labels => 'x,y',
115
+ :axis_labels => [@labels.values, @yaxis],
116
+ :format => 'file',
117
+ :filename => File.join(MetricFu.output_directory, 'roodi.png'))
118
+ end
119
+ end
120
+
121
+ class StatsGchartGrapher < StatsGrapher
122
+ def graph!
123
+ determine_y_axis_scale(@loc_counts + @lot_counts)
124
+ url = Gchart.line(
125
+ :size => GCHART_GRAPH_SIZE,
126
+ :title => URI.escape("Stats: LOC & LOT"),
127
+ :data => [@loc_counts, @lot_counts],
128
+ :bar_colors => COLORS[0..1],
129
+ :legend => ['Lines of code', 'Lines of test'],
130
+ :custom => "chdlp=t",
131
+ :max_value => @max_value,
132
+ :axis_with_labels => 'x,y',
133
+ :axis_labels => [@labels.values, @yaxis],
134
+ :format => 'file',
135
+ :filename => File.join(MetricFu.output_directory, 'stats.png'))
136
+ end
137
+ end
138
+
139
+ class RailsBestPracticesGchartGrapher < RailsBestPracticesGrapher
140
+ def graph!
141
+ determine_y_axis_scale(@rails_best_practices_count)
142
+ url = Gchart.line(
143
+ :size => GCHART_GRAPH_SIZE,
144
+ :title => URI.escape("Rails Best Practices: design problems"),
145
+ :data => self.rails_best_practices_count,
146
+ :bar_colors => COLORS[0..1],
147
+ :legend => ['Problems'],
148
+ :custom => "chdlp=t",
149
+ :max_value => @max_value,
150
+ :axis_with_labels => 'x,y',
151
+ :axis_labels => [@labels.values, @yaxis],
152
+ :format => 'file',
153
+ :filename => File.join(MetricFu.output_directory, 'rails_best_practices.png')
154
+ )
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,18 @@
1
+ module MetricFu
2
+ class FlayGrapher < Grapher
3
+ attr_accessor :flay_score, :labels
4
+
5
+ def initialize
6
+ super
7
+ @flay_score = []
8
+ @labels = {}
9
+ end
10
+
11
+ def get_metrics(metrics, date)
12
+ if metrics && metrics[:flay]
13
+ @flay_score.push(metrics[:flay][:total_score].to_i)
14
+ @labels.update( { @labels.size => date })
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,57 @@
1
+ module MetricFu
2
+ class FlogGrapher < Grapher
3
+ attr_accessor :flog_average, :labels, :top_five_percent_average
4
+
5
+ def initialize
6
+ super
7
+ @flog_average = []
8
+ @labels = {}
9
+ @top_five_percent_average =[]
10
+ end
11
+
12
+ def get_metrics(metrics, date)
13
+ if metrics && metrics[:flog]
14
+ @top_five_percent_average.push(calc_top_five_percent_average(metrics))
15
+ @flog_average.push(metrics[:flog][:average])
16
+ @labels.update( { @labels.size => date })
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def calc_top_five_percent_average(metrics)
23
+ return calc_top_five_percent_average_legacy(metrics) if metrics[:flog][:pages]
24
+
25
+ method_scores = metrics[:flog][:method_containers].inject([]) do |method_scores, container|
26
+ method_scores += container[:methods].values.map {|v| v[:score]}
27
+ end
28
+ method_scores.sort!.reverse!
29
+
30
+ number_of_methods_that_is_five_percent = (method_scores.size * 0.05).ceil
31
+
32
+ total_for_five_percent =
33
+ method_scores[0...number_of_methods_that_is_five_percent].inject(0) { |total, score| total += score }
34
+ if number_of_methods_that_is_five_percent == 0
35
+ 0.0
36
+ else
37
+ total_for_five_percent / number_of_methods_that_is_five_percent.to_f
38
+ end
39
+ end
40
+
41
+ def calc_top_five_percent_average_legacy(metrics)
42
+ methods = metrics[:flog][:pages].inject([]) {|methods, page| methods << page[:scanned_methods]}
43
+ methods.flatten!
44
+ methods = methods.sort_by {|method| method[:score]}.reverse
45
+
46
+ number_of_methods_that_is_five_percent = (methods.size * 0.05).ceil
47
+
48
+ total_for_five_percent =
49
+ methods[0...number_of_methods_that_is_five_percent].inject(0) {|total, method| total += method[:score] }
50
+ if number_of_methods_that_is_five_percent == 0
51
+ 0.0
52
+ else
53
+ total_for_five_percent / number_of_methods_that_is_five_percent.to_f
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,11 @@
1
+ module MetricFu
2
+ class Grapher
3
+ def initialize
4
+ self.class.require_graphing_gem
5
+ end
6
+
7
+ def self.require_graphing_gem
8
+ # to be overridden by charting engines
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module MetricFu
2
+ class RailsBestPracticesGrapher < Grapher
3
+ attr_accessor :rails_best_practices_count, :labels
4
+
5
+ def initialize
6
+ super
7
+ @rails_best_practices_count = []
8
+ @labels = {}
9
+ end
10
+
11
+ def get_metrics(metrics, date)
12
+ if metrics && metrics[:rails_best_practices]
13
+ size = (metrics[:rails_best_practices][:problems] || []).size
14
+ @rails_best_practices_count.push(size)
15
+ @labels.update( { @labels.size => date })
16
+ end
17
+ end
18
+ end
19
+ end