edouard-metric_fu 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/HISTORY +41 -0
  2. data/TODO +0 -4
  3. data/lib/base/base_template.rb +1 -2
  4. data/lib/base/configuration.rb +5 -33
  5. data/lib/base/generator.rb +7 -0
  6. data/lib/base/graph.rb +5 -3
  7. data/lib/base/report.rb +3 -3
  8. data/lib/generators/churn.rb +0 -1
  9. data/lib/generators/flay.rb +2 -2
  10. data/lib/generators/flog.rb +34 -7
  11. data/lib/generators/rcov.rb +2 -2
  12. data/lib/generators/reek.rb +28 -1
  13. data/lib/generators/roodi.rb +2 -1
  14. data/lib/generators/saikuro.rb +3 -7
  15. data/lib/graphs/engines/bluff.rb +86 -0
  16. data/lib/graphs/engines/gchart.rb +119 -0
  17. data/lib/graphs/flay_grapher.rb +6 -20
  18. data/lib/graphs/flog_grapher.rb +25 -22
  19. data/lib/graphs/grapher.rb +11 -0
  20. data/lib/graphs/rcov_grapher.rb +2 -16
  21. data/lib/graphs/reek_grapher.rb +12 -24
  22. data/lib/graphs/roodi_grapher.rb +6 -20
  23. data/lib/metric_fu.rb +13 -6
  24. data/lib/templates/awesome/awesome_template.rb +7 -0
  25. data/lib/templates/awesome/css/buttons.css +82 -0
  26. data/lib/templates/awesome/{default.css → css/default.css} +16 -0
  27. data/lib/templates/awesome/css/integrity.css +335 -0
  28. data/lib/templates/awesome/css/reset.css +7 -0
  29. data/lib/templates/awesome/flay.html.erb +7 -1
  30. data/lib/templates/awesome/flog.html.erb +8 -1
  31. data/lib/templates/awesome/layout.html.erb +7 -4
  32. data/lib/templates/awesome/rcov.html.erb +7 -1
  33. data/lib/templates/awesome/reek.html.erb +7 -1
  34. data/lib/templates/awesome/roodi.html.erb +7 -1
  35. data/lib/templates/javascripts/bluff-min.js +1 -0
  36. data/lib/templates/javascripts/excanvas.js +35 -0
  37. data/lib/templates/javascripts/js-class.js +1 -0
  38. data/spec/base/configuration_spec.rb +18 -52
  39. data/spec/base/generator_spec.rb +61 -1
  40. data/spec/base/graph_spec.rb +24 -0
  41. data/spec/generators/flog_spec.rb +19 -0
  42. data/spec/generators/reek_spec.rb +66 -0
  43. data/spec/graphs/engines/bluff_spec.rb +15 -0
  44. data/spec/graphs/engines/gchart_spec.rb +14 -0
  45. data/spec/graphs/flay_grapher_spec.rb +37 -0
  46. data/spec/graphs/flog_grapher_spec.rb +40 -10
  47. data/spec/graphs/rcov_grapher_spec.rb +37 -0
  48. data/spec/graphs/reek_grapher_spec.rb +46 -0
  49. data/spec/graphs/roodi_grapher_spec.rb +37 -0
  50. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +1 -0
  51. data/spec/resources/yml/20090630.yml +7844 -0
  52. data/spec/spec_helper.rb +1 -23
  53. data/tasks/metric_fu.rake +1 -1
  54. metadata +34 -16
  55. data/vendor/_fonts/monaco.ttf +0 -0
  56. data/vendor/saikuro/saikuro.rb +0 -1214
@@ -0,0 +1,119 @@
1
+ module MetricFu
2
+ module GchartGrapher
3
+ COLORS = %w{009999 FF7400 A60000 008500 E6399B 344AD7 00B860 D5CCB9}
4
+ GCHART_GRAPH_SIZE = "1000x300" # 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'
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%25 average'],
59
+ :max_value => @max_value,
60
+ :axis_with_labels => 'x,y',
61
+ :axis_labels => [@labels.values, @yaxis],
62
+ :format => 'file',
63
+ :filename => File.join(MetricFu.output_directory, 'flog.png'))
64
+ end
65
+ end
66
+
67
+ class RcovGchartGrapher < RcovGrapher
68
+ def graph!
69
+ determine_y_axis_scale(self.rcov_percent)
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
+ :max_value => @max_value,
98
+ :axis_with_labels => 'x,y',
99
+ :axis_labels => [@labels.values, @yaxis],
100
+ :format => 'file',
101
+ :filename => File.join(MetricFu.output_directory, 'reek.png'))
102
+ end
103
+ end
104
+
105
+ class RoodiGchartGrapher < RoodiGrapher
106
+ def graph!
107
+ determine_y_axis_scale(@roodi_count)
108
+ url = Gchart.line(
109
+ :size => GCHART_GRAPH_SIZE,
110
+ :title => URI.escape("Roodi: potential design problems"),
111
+ :data => @roodi_count,
112
+ :max_value => @max_value,
113
+ :axis_with_labels => 'x,y',
114
+ :axis_labels => [@labels.values, @yaxis],
115
+ :format => 'file',
116
+ :filename => File.join(MetricFu.output_directory, 'roodi.png'))
117
+ end
118
+ end
119
+ end
@@ -1,32 +1,18 @@
1
- require 'gruff'
2
1
  module MetricFu
3
2
 
4
- class FlayGrapher
3
+ class FlayGrapher < Grapher
5
4
 
6
5
  attr_accessor :flay_score, :labels
7
6
 
8
7
  def initialize
9
- self.flay_score = []
10
- self.labels = {}
8
+ super
9
+ @flay_score = []
10
+ @labels = {}
11
11
  end
12
12
 
13
13
  def get_metrics(metrics, date)
14
- self.flay_score.push(metrics[:flay][:total_score].to_i)
15
- self.labels.update( { self.labels.size => date })
16
- end
17
-
18
- def graph!
19
- g = Gruff::Line.new(MetricFu.graph_size)
20
- g.title = "Flay: duplication"
21
- g.theme = MetricFu.graph_theme
22
- g.font = MetricFu.graph_font
23
- g.data('flay', self.flay_score)
24
- g.labels = self.labels
25
- g.title_font_size = MetricFu.graph_title_font_size
26
- g.legend_box_size = MetricFu.graph_legend_box_size
27
- g.legend_font_size = MetricFu.graph_legend_font_size
28
- g.marker_font_size = MetricFu.graph_marker_font_size
29
- g.write(File.join(MetricFu.output_directory, 'flay.png'))
14
+ @flay_score.push(metrics[:flay][:total_score].to_i)
15
+ @labels.update( { @labels.size => date })
30
16
  end
31
17
 
32
18
  end
@@ -1,35 +1,38 @@
1
- require 'gruff'
2
1
  module MetricFu
3
2
 
4
- class FlogGrapher
3
+ class FlogGrapher < Grapher
5
4
 
6
- attr_accessor :flog_total, :flog_average, :labels
5
+ attr_accessor :flog_average, :labels, :top_five_percent_average
7
6
 
8
7
  def initialize
9
- self.flog_total = []
10
- self.flog_average = []
11
- self.labels = {}
8
+ super
9
+ @flog_average = []
10
+ @labels = {}
11
+ @top_five_percent_average =[]
12
12
  end
13
13
 
14
14
  def get_metrics(metrics, date)
15
- self.flog_total.push(metrics[:flog][:total])
16
- self.flog_average.push(metrics[:flog][:average])
17
- self.labels.update( { self.labels.size => date })
15
+ @top_five_percent_average.push(calc_top_five_percent_average(metrics))
16
+ @flog_average.push(metrics[:flog][:average])
17
+ @labels.update( { @labels.size => date })
18
18
  end
19
19
 
20
- def graph!
21
- g = Gruff::Line.new(MetricFu.graph_size)
22
- g.title = "Flog: code complexity"
23
- g.theme = MetricFu.graph_theme
24
- g.font = MetricFu.graph_font
25
- g.data('flog total', self.flog_total)
26
- g.data('flog average', self.flog_average)
27
- g.labels = self.labels
28
- g.title_font_size = MetricFu.graph_title_font_size
29
- g.legend_box_size = MetricFu.graph_legend_box_size
30
- g.legend_font_size = MetricFu.graph_legend_font_size
31
- g.marker_font_size = MetricFu.graph_marker_font_size
32
- g.write(File.join(MetricFu.output_directory, 'flog.png'))
20
+ private
21
+
22
+ def calc_top_five_percent_average(metrics)
23
+ methods = metrics[:flog][:pages].inject([]) {|methods, page| methods << page[:scanned_methods]}
24
+ methods.flatten!
25
+ methods = methods.sort_by {|method| method[:score]}.reverse
26
+
27
+ number_of_methods_that_is_five_percent = (methods.size * 0.05).ceil
28
+
29
+ total_for_five_percent =
30
+ methods[0...number_of_methods_that_is_five_percent].inject(0) {|total, method| total += method[:score] }
31
+ if number_of_methods_that_is_five_percent == 0
32
+ 0.0
33
+ else
34
+ total_for_five_percent / number_of_methods_that_is_five_percent.to_f
35
+ end
33
36
  end
34
37
 
35
38
  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
@@ -1,11 +1,11 @@
1
- require 'gruff'
2
1
  module MetricFu
3
2
 
4
- class RcovGrapher
3
+ class RcovGrapher < Grapher
5
4
 
6
5
  attr_accessor :rcov_percent, :labels
7
6
 
8
7
  def initialize
8
+ super
9
9
  self.rcov_percent = []
10
10
  self.labels = {}
11
11
  end
@@ -15,20 +15,6 @@ module MetricFu
15
15
  self.labels.update( { self.labels.size => date })
16
16
  end
17
17
 
18
- def graph!
19
- g = Gruff::Line.new(MetricFu.graph_size)
20
- g.title = "Rcov: code coverage"
21
- g.theme = MetricFu.graph_theme
22
- g.font = MetricFu.graph_font
23
- g.data('rcov', self.rcov_percent)
24
- g.labels = self.labels
25
- g.title_font_size = MetricFu.graph_title_font_size
26
- g.legend_box_size = MetricFu.graph_legend_box_size
27
- g.legend_font_size = MetricFu.graph_legend_font_size
28
- g.marker_font_size = MetricFu.graph_marker_font_size
29
- g.write(File.join(MetricFu.output_directory, 'rcov.png'))
30
- end
31
-
32
18
  end
33
19
 
34
20
  end
@@ -1,44 +1,32 @@
1
- require 'gruff'
2
1
  module MetricFu
3
2
 
4
- class ReekGrapher
3
+ class ReekGrapher < Grapher
5
4
 
6
5
  attr_accessor :reek_count, :labels
7
6
 
8
7
  def initialize
9
- self.reek_count = {}
10
- self.labels= {}
8
+ super
9
+ @reek_count = {}
10
+ @labels = {}
11
11
  end
12
12
 
13
13
  def get_metrics(metrics, date)
14
- counter = self.labels.size
15
- self.labels.update( { counter => date })
14
+ counter = @labels.size
15
+ @labels.update( { @labels.size => date })
16
16
 
17
17
  metrics[:reek][:matches].each do |reek_chunk|
18
18
  reek_chunk[:code_smells].each do |code_smell|
19
19
  # speaking of code smell...
20
- self.reek_count[code_smell[:type]] = [] if self.reek_count[code_smell[:type]].nil?
21
- self.reek_count[code_smell[:type]][counter].nil? ? self.reek_count[code_smell[:type]][counter] = 1 : self.reek_count[code_smell[:type]][counter] += 1
20
+ @reek_count[code_smell[:type]] = [] if @reek_count[code_smell[:type]].nil?
21
+ if @reek_count[code_smell[:type]][counter].nil?
22
+ @reek_count[code_smell[:type]][counter] = 1
23
+ else
24
+ @reek_count[code_smell[:type]][counter] += 1
25
+ end
22
26
  end
23
27
  end
24
28
  end
25
29
 
26
- def graph!
27
- g = Gruff::Line.new(MetricFu.graph_size)
28
- g.title = "Reek: code smells"
29
- g.theme = MetricFu.graph_theme
30
- g.font = MetricFu.graph_font
31
- self.reek_count.each_pair do |type, count|
32
- g.data(type, count)
33
- end
34
- g.labels = self.labels
35
- g.title_font_size = MetricFu.graph_title_font_size
36
- g.legend_box_size = MetricFu.graph_legend_box_size
37
- g.legend_font_size = MetricFu.graph_legend_font_size
38
- g.marker_font_size = MetricFu.graph_marker_font_size
39
- g.write(File.join(MetricFu.output_directory, 'reek.png'))
40
- end
41
-
42
30
  end
43
31
 
44
32
  end
@@ -1,32 +1,18 @@
1
- require 'gruff'
2
1
  module MetricFu
3
2
 
4
- class RoodiGrapher
3
+ class RoodiGrapher < Grapher
5
4
 
6
5
  attr_accessor :roodi_count, :labels
7
6
 
8
7
  def initialize
9
- self.roodi_count = []
10
- self.labels = {}
8
+ super
9
+ @roodi_count = []
10
+ @labels = {}
11
11
  end
12
12
 
13
13
  def get_metrics(metrics, date)
14
- self.roodi_count.push(metrics[:roodi][:problems].size)
15
- self.labels.update( { self.labels.size => date })
16
- end
17
-
18
- def graph!
19
- g = Gruff::Line.new(MetricFu.graph_size)
20
- g.title = "Roodi: design problems"
21
- g.theme = MetricFu.graph_theme
22
- g.font = MetricFu.graph_font
23
- g.data('roodi', self.roodi_count)
24
- g.labels = self.labels
25
- g.title_font_size = MetricFu.graph_title_font_size
26
- g.legend_box_size = MetricFu.graph_legend_box_size
27
- g.legend_font_size = MetricFu.graph_legend_font_size
28
- g.marker_font_size = MetricFu.graph_marker_font_size
29
- g.write(File.join(MetricFu.output_directory, 'roodi.png'))
14
+ @roodi_count.push(metrics[:roodi][:problems].size)
15
+ @labels.update( { @labels.size => date })
30
16
  end
31
17
 
32
18
  end
data/lib/metric_fu.rb CHANGED
@@ -1,11 +1,13 @@
1
+ require 'rake'
2
+ require 'yaml'
1
3
  # Load a few things to make our lives easier elsewhere.
2
4
  module MetricFu
3
5
  LIB_ROOT = File.dirname(__FILE__)
4
6
  end
5
7
  base_dir = File.join(MetricFu::LIB_ROOT, 'base')
6
- generator_dir = File.join(MetricFu::LIB_ROOT, 'generators')
7
- template_dir = File.join(MetricFu::LIB_ROOT, 'templates')
8
- graph_dir = File.join(MetricFu::LIB_ROOT, 'graphs')
8
+ generator_dir = File.join(MetricFu::LIB_ROOT, 'generators')
9
+ template_dir = File.join(MetricFu::LIB_ROOT, 'templates')
10
+ graph_dir = File.join(MetricFu::LIB_ROOT, 'graphs')
9
11
 
10
12
  # We need to require these two things first because our other classes
11
13
  # depend on them.
@@ -13,12 +15,17 @@ require File.join(base_dir, 'report')
13
15
  require File.join(base_dir, 'generator')
14
16
  require File.join(base_dir, 'graph')
15
17
 
16
- # Load the rakefile so users of the gem get the default metric_fu task
17
- load File.join(MetricFu::LIB_ROOT, '..', 'tasks', 'metric_fu.rake')
18
+ # prevent the task from being run multiple times.
19
+ unless Rake::Task.task_defined? "metrics:all"
20
+ # Load the rakefile so users of the gem get the default metric_fu task
21
+ load File.join(MetricFu::LIB_ROOT, '..', 'tasks', 'metric_fu.rake')
22
+ end
18
23
 
19
24
  # Now load everything else that's in the directory
20
25
  Dir[File.join(base_dir, '*.rb')].each{|l| require l }
21
26
  Dir[File.join(generator_dir, '*.rb')].each {|l| require l }
22
27
  Dir[File.join(template_dir, 'standard/*.rb')].each {|l| require l}
23
28
  Dir[File.join(template_dir, 'awesome/*.rb')].each {|l| require l}
24
- Dir[File.join(graph_dir, '*.rb')].each {|l| require l}
29
+ require graph_dir + "/grapher"
30
+ Dir[File.join(graph_dir, '*.rb')].each {|l| require l}
31
+ Dir[File.join(graph_dir, 'engines', '*.rb')].each {|l| require l}
@@ -1,9 +1,16 @@
1
+ require 'fileutils'
2
+
1
3
  class AwesomeTemplate < MetricFu::Template
2
4
 
3
5
  def write
4
6
  # Getting rid of the crap before and after the project name from integrity
5
7
  @name = File.basename(Dir.pwd).gsub(/^\w+-|-\w+$/, "")
6
8
 
9
+ # Copy Bluff javascripts to output directory
10
+ Dir[File.join(this_directory, '..', 'javascripts', '*')].each do |f|
11
+ FileUtils.copy(f, File.join(MetricFu.output_directory, File.basename(f)))
12
+ end
13
+
7
14
  report.each_pair do |section, contents|
8
15
  if template_exists?(section)
9
16
  create_instance_var(section, contents)
@@ -0,0 +1,82 @@
1
+ /* --------------------------------------------------------------
2
+
3
+ buttons.css
4
+ * Gives you some great CSS-only buttons.
5
+
6
+ Created by Kevin Hale [particletree.com]
7
+ * particletree.com/features/rediscovering-the-button-element
8
+
9
+ See Readme.txt in this folder for instructions.
10
+
11
+ -------------------------------------------------------------- */
12
+
13
+ button {
14
+ display:block;
15
+ float:left;
16
+ margin:0 0.583em 0.667em 0;
17
+ padding:5px 10px 5px 7px; /* Links */
18
+
19
+ border:1px solid #dedede;
20
+ border-top:1px solid #eee;
21
+ border-left:1px solid #eee;
22
+
23
+ background-color:#f5f5f5;
24
+ font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif;
25
+ font-size:100%;
26
+ line-height:130%;
27
+ text-decoration:none;
28
+ font-weight:bold;
29
+ color:#565656;
30
+ cursor:pointer;
31
+ }
32
+ button {
33
+ width:auto;
34
+ overflow:visible;
35
+ padding:4px 10px 3px 7px; /* IE6 */
36
+ }
37
+ button[type] {
38
+ padding:4px 10px 4px 7px; /* Firefox */
39
+ line-height:17px; /* Safari */
40
+ }
41
+ *:first-child+html button[type] {
42
+ padding:4px 10px 3px 7px; /* IE7 */
43
+ }
44
+ button img {
45
+ margin:0 3px -3px 0 !important;
46
+ padding:0;
47
+ border:none;
48
+ width:16px;
49
+ height:16px;
50
+ float:none;
51
+ }
52
+
53
+
54
+ /* Button colors
55
+ -------------------------------------------------------------- */
56
+
57
+ /* Standard */
58
+ button:hover {
59
+ background-color:#dff4ff;
60
+ border:1px solid #c2e1ef;
61
+ color:#336699;
62
+ }
63
+
64
+ /* Positive */
65
+ body .positive {
66
+ color:#529214;
67
+ }
68
+ button.positive:hover {
69
+ background-color:#E6EFC2;
70
+ border:1px solid #C6D880;
71
+ color:#529214;
72
+ }
73
+
74
+ /* Negative */
75
+ body .negative {
76
+ color:#d12f19;
77
+ }
78
+ button.negative:hover {
79
+ background:#fbe3e4;
80
+ border:1px solid #fbc2c4;
81
+ color:#d12f19;
82
+ }