edouard-metric_fu 1.0.3.8 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1 +1 @@
1
- See http://metric-fu.rubyforge.org/ for documentation, or the HISTORY file for a change log.
1
+ Same as jscruggs/metric_fu, but with awesome templates and graphs.
data/Rakefile CHANGED
@@ -20,8 +20,8 @@ namespace :metrics do
20
20
  task :all do
21
21
  MetricFu.metrics.each {|metric| MetricFu.report.add(metric) }
22
22
  MetricFu.report.save_output(MetricFu.report.to_yaml,
23
- MetricFu.base_directory,
24
- 'report.yml')
23
+ MetricFu.data_directory,
24
+ "#{Time.now.strftime("%Y%m%d")}.yml")
25
25
  MetricFu.report.save_templatized_report
26
26
  if MetricFu.report.open_in_browser?
27
27
  MetricFu.report.show_in_browser(MetricFu.output_directory)
@@ -34,8 +34,8 @@ namespace :metrics do
34
34
 
35
35
  MetricFu.report.add(metric)
36
36
  MetricFu.report.save_output(MetricFu.report.to_yaml,
37
- MetricFu.base_directory,
38
- 'report.yml')
37
+ MetricFu.data_directory,
38
+ "#{Time.now.strftime("%Y%m%d")}.yml")
39
39
  MetricFu.report.save_templatized_report
40
40
  if MetricFu.report.open_in_browser?
41
41
  MetricFu.report.show_in_browser(MetricFu.output_directory)
@@ -8,6 +8,7 @@ module MetricFu
8
8
  AVAILABLE_METRICS = [:churn, :flog, :flay, :reek,
9
9
  :roodi, :saikuro, :rcov]
10
10
 
11
+ AVAILABLE_GRAPHS = [:flog, :flay, :reek, :roodi, :rcov]
11
12
 
12
13
  # The @@configuration class variable holds a global type configuration
13
14
  # object for any parts of the system to use.
@@ -118,12 +119,14 @@ module MetricFu
118
119
  @base_directory = ENV['CC_BUILD_ARTIFACTS'] || 'tmp/metric_fu'
119
120
  @scratch_directory = File.join(@base_directory, 'scratch')
120
121
  @output_directory = File.join(@base_directory, 'output')
122
+ @data_directory = File.join(@base_directory, '_data')
121
123
  @metric_fu_root_directory = File.join(File.dirname(__FILE__),
122
124
  '..', '..')
123
125
  @template_directory = File.join(@metric_fu_root_directory,
124
126
  'lib', 'templates')
125
127
  @template_class = AwesomeTemplate
126
128
  set_metrics
129
+ set_graphs
127
130
  set_code_dirs
128
131
  @flay = { :dirs_to_flay => @code_dirs }
129
132
  @flog = { :dirs_to_flog => @code_dirs }
@@ -147,6 +150,14 @@ module MetricFu
147
150
  "--profile",
148
151
  "--rails",
149
152
  "--exclude /gems/,/Library/,/usr/,spec"]}
153
+
154
+ @graph_theme = { :colors => %w(orange purple green white red blue pink yellow),
155
+ :marker_color => 'blue',
156
+ :background_colors => %w(white white)}
157
+
158
+ relative_font_path = [File.dirname(__FILE__), '..', '..', 'vendor', '_fonts', 'monaco.ttf']
159
+ @graph_font = File.expand_path(File.join(relative_font_path))
160
+
150
161
  end
151
162
 
152
163
  # Perform a simple check to try and guess if we're running
@@ -166,6 +177,10 @@ module MetricFu
166
177
  @metrics = MetricFu::AVAILABLE_METRICS
167
178
  end
168
179
  end
180
+
181
+ def set_graphs
182
+ @graphs = MetricFu::AVAILABLE_GRAPHS
183
+ end
169
184
 
170
185
  # Add the 'app' directory if we're running within rails.
171
186
  def set_code_dirs
@@ -35,6 +35,7 @@ module MetricFu
35
35
  def initialize(options={})
36
36
  create_metric_dir_if_missing
37
37
  create_output_dir_if_missing
38
+ create_data_dir_if_missing
38
39
  end
39
40
 
40
41
  # Creates a new generator and returns the output of the
@@ -82,6 +83,12 @@ module MetricFu
82
83
  FileUtils.mkdir_p(MetricFu.output_directory, :verbose => false)
83
84
  end
84
85
  end
86
+
87
+ def create_data_dir_if_missing #:nodoc:
88
+ unless File.directory?(MetricFu.data_directory)
89
+ FileUtils.mkdir_p(MetricFu.data_directory, :verbose => false)
90
+ end
91
+ end
85
92
 
86
93
  # @return String
87
94
  # The path of the metric directory this class is using.
@@ -135,8 +142,8 @@ module MetricFu
135
142
  information.
136
143
  EOF
137
144
  end
138
-
139
- def to_h #:nodoc:
145
+
146
+ def to_graph #:nodoc:
140
147
  raise <<-EOF
141
148
  This method must be implemented by a concrete class descending
142
149
  from Generator. See generator class documentation for more
data/lib/base/graph.rb ADDED
@@ -0,0 +1,37 @@
1
+ module MetricFu
2
+
3
+ def self.graph
4
+ @graph ||= Graph.new
5
+ end
6
+
7
+ class Graph
8
+
9
+ attr_accessor :clazz
10
+
11
+ def initialize
12
+ self.clazz = []
13
+ end
14
+
15
+ def add(graph_type)
16
+ grapher_name = graph_type.to_s.capitalize + "Grapher"
17
+ self.clazz.push MetricFu.const_get(grapher_name).new
18
+ end
19
+
20
+
21
+ def generate
22
+ puts "Generating graphs"
23
+ Dir[File.join(MetricFu.data_directory, '*.yml')].each do |metric_file|
24
+ puts "Generating graphs for #{metric_file}"
25
+ date = metric_file.split('/')[3].split('.')[0]
26
+ metrics = YAML::load(File.open(metric_file))
27
+
28
+ self.clazz.each do |grapher|
29
+ grapher.get_metrics(metrics, date)
30
+ end
31
+ end
32
+ self.clazz.each do |grapher|
33
+ grapher.graph!
34
+ end
35
+ end
36
+ end
37
+ end
@@ -5,7 +5,6 @@ module MetricFu
5
5
  class Rcov < Generator
6
6
  NEW_FILE_MARKER = ("=" * 80) + "\n"
7
7
 
8
-
9
8
  class Line
10
9
  attr_accessor :content, :was_run
11
10
 
@@ -0,0 +1,31 @@
1
+ require 'graph'
2
+ require 'gruff'
3
+ module MetricFu
4
+
5
+ class FlayGrapher
6
+
7
+ attr_accessor :flay_score, :labels
8
+
9
+ def initialize
10
+ self.flay_score = []
11
+ self.labels = {}
12
+ end
13
+
14
+ def get_metrics(metrics, date)
15
+ self.flay_score.push(metrics[:flay][:total_score].to_i)
16
+ self.labels.update( { self.labels.size => date })
17
+ end
18
+
19
+ def graph!
20
+ g = Gruff::Line.new("1024x768")
21
+ g.title = "Flay: duplication"
22
+ g.theme = MetricFu.graph_theme
23
+ g.font = MetricFu.graph_font
24
+ g.data('flay', self.flay_score)
25
+ g.labels = self.labels
26
+ g.write(File.join(MetricFu.output_directory, 'flay.png'))
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,34 @@
1
+ require 'graph'
2
+ require 'gruff'
3
+ module MetricFu
4
+
5
+ class FlogGrapher
6
+
7
+ attr_accessor :flog_total, :flog_average, :labels
8
+
9
+ def initialize
10
+ self.flog_total = []
11
+ self.flog_average = []
12
+ self.labels = {}
13
+ end
14
+
15
+ def get_metrics(metrics, date)
16
+ self.flog_total.push(metrics[:flog][:total])
17
+ self.flog_average.push(metrics[:flog][:average])
18
+ self.labels.update( { self.labels.size => date })
19
+ end
20
+
21
+ def graph!
22
+ g = Gruff::Line.new("1024x768")
23
+ g.title = "Flog: code complexity"
24
+ g.theme = MetricFu.graph_theme
25
+ g.font = MetricFu.graph_font
26
+ g.data('flog total', self.flog_total)
27
+ g.data('flog average', self.flog_average)
28
+ g.labels = self.labels
29
+ g.write(File.join(MetricFu.output_directory, 'flog.png'))
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,31 @@
1
+ require 'graph'
2
+ require 'gruff'
3
+ module MetricFu
4
+
5
+ class RcovGrapher
6
+
7
+ attr_accessor :rcov_percent, :labels
8
+
9
+ def initialize
10
+ self.rcov_percent = []
11
+ self.labels = {}
12
+ end
13
+
14
+ def get_metrics(metrics, date)
15
+ self.rcov_percent.push(metrics[:rcov][:global_percent_run])
16
+ self.labels.update( { self.labels.size => date })
17
+ end
18
+
19
+ def graph!
20
+ g = Gruff::Line.new("1024x768")
21
+ g.title = "Rcov: code coverage"
22
+ g.theme = MetricFu.graph_theme
23
+ g.font = MetricFu.graph_font
24
+ g.data('rcov', self.rcov_percent)
25
+ g.labels = self.labels
26
+ g.write(File.join(MetricFu.output_directory, 'rcov.png'))
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,41 @@
1
+ require 'graph'
2
+ require 'gruff'
3
+ module MetricFu
4
+
5
+ class ReekGrapher
6
+
7
+ attr_accessor :reek_count, :labels
8
+
9
+ def initialize
10
+ self.reek_count = {}
11
+ self.labels= {}
12
+ end
13
+
14
+ def get_metrics(metrics, date)
15
+ counter = self.labels.size
16
+ self.labels.update( { counter => date })
17
+
18
+ metrics[:reek][:matches].each do |reek_chunk|
19
+ reek_chunk[:code_smells].each do |code_smell|
20
+ # speaking of code smell...
21
+ self.reek_count[code_smell[:type]] = [] if self.reek_count[code_smell[:type]].nil?
22
+ self.reek_count[code_smell[:type]][counter].nil? ? self.reek_count[code_smell[:type]][counter] = 1 : self.reek_count[code_smell[:type]][counter] += 1
23
+ end
24
+ end
25
+ end
26
+
27
+ def graph!
28
+ g = Gruff::Line.new("1024x768")
29
+ g.title = "Reek: code smells"
30
+ g.theme = MetricFu.graph_theme
31
+ g.font = MetricFu.graph_font
32
+ self.reek_count.each_pair do |type, count|
33
+ g.data(type, count)
34
+ end
35
+ g.labels = self.labels
36
+ g.write(File.join(MetricFu.output_directory, 'reek.png'))
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,31 @@
1
+ require 'graph'
2
+ require 'gruff'
3
+ module MetricFu
4
+
5
+ class RoodiGrapher
6
+
7
+ attr_accessor :roodi_count, :labels
8
+
9
+ def initialize
10
+ self.roodi_count = []
11
+ self.labels = {}
12
+ end
13
+
14
+ def get_metrics(metrics, date)
15
+ self.roodi_count.push(metrics[:roodi][:problems].size)
16
+ self.labels.update( { self.labels.size => date })
17
+ end
18
+
19
+ def graph!
20
+ g = Gruff::Line.new("1024x768")
21
+ g.title = "Roodi: design problems"
22
+ g.theme = MetricFu.graph_theme
23
+ g.font = MetricFu.graph_font
24
+ g.data('roodi', self.roodi_count)
25
+ g.labels = self.labels
26
+ g.write(File.join(MetricFu.output_directory, 'roodi.png'))
27
+ end
28
+
29
+ end
30
+
31
+ end
data/lib/metric_fu.rb CHANGED
@@ -5,11 +5,13 @@ end
5
5
  base_dir = File.join(MetricFu::LIB_ROOT, 'base')
6
6
  generator_dir = File.join(MetricFu::LIB_ROOT, 'generators')
7
7
  template_dir = File.join(MetricFu::LIB_ROOT, 'templates')
8
+ graph_dir = File.join(MetricFu::LIB_ROOT, 'graphs')
8
9
 
9
10
  # We need to require these two things first because our other classes
10
11
  # depend on them.
11
12
  require File.join(base_dir, 'report')
12
13
  require File.join(base_dir, 'generator')
14
+ require File.join(base_dir, 'graph')
13
15
 
14
16
  # Load the rakefile so users of the gem get the default metric_fu task
15
17
  load File.join(MetricFu::LIB_ROOT, '..', 'tasks', 'metric_fu.rake')
@@ -19,3 +21,4 @@ Dir[File.join(base_dir, '*.rb')].each{|l| require l }
19
21
  Dir[File.join(generator_dir, '*.rb')].each {|l| require l }
20
22
  Dir[File.join(template_dir, 'standard/*.rb')].each {|l| require l}
21
23
  Dir[File.join(template_dir, 'awesome/*.rb')].each {|l| require l}
24
+ Dir[File.join(graph_dir, '*.rb')].each {|l| require l}
@@ -1,6 +1,13 @@
1
1
  <h3>Flay Results</h3>
2
+
3
+ <p><a href='http://ruby.sadi.st/Flay.html'>Flay</a> analyzes ruby code for structural similarities.</p>
4
+
5
+ <a href="flay.png?<%= Time.now.localtime %>">
6
+ <img src="flay.png?<%= Time.now.localtime %>" width="400">
7
+ </a>
8
+
2
9
  <h4>Total Score (lower is better): <%= @flay[:total_score] %></h4>
3
- <p><a href='http://ruby.sadi.st/Flay.html'>Flay</a> analyzes ruby code for structural similarities.</p>
10
+
4
11
  <table>
5
12
  <tr>
6
13
  <th>Files</th>
@@ -1,7 +1,13 @@
1
1
  <h3>Flog Results</h3>
2
2
  <p><a href='http://ruby.sadi.st/Flog.html'>Flog</a> measures code complexity.</p>
3
+
4
+ <a href="flog.png?<%= Time.now.localtime %>">
5
+ <img src="flog.png?<%= Time.now.localtime %>" width="400">
6
+ </a>
7
+
3
8
  <h2>Total Flog score for all methods: <%= @flog[:total]%></h2>
4
9
  <h2>Average Flog score for all methods: <%= @flog[:average]%></h2>
10
+
5
11
  <table>
6
12
  <tr>
7
13
  <th>File</th>
@@ -1,5 +1,11 @@
1
1
  <h3>Rcov Code Coverage Results</h3>
2
+
2
3
  <p>C0 code coverage information.</p>
4
+
5
+ <a href="rcov.png?<%= Time.now.localtime %>">
6
+ <img src="rcov.png?<%= Time.now.localtime %>" width="400">
7
+ </a>
8
+
3
9
  <p>Total Coverage: <%= @rcov.delete(:global_percent_run) %>% </p>
4
10
  <table>
5
11
  <tr>
@@ -1,5 +1,11 @@
1
1
  <h3>Reek Results</h3>
2
+
2
3
  <p><a href="http://reek.rubyforge.org/">Reek</a> detects common code smells in ruby code.</p>
4
+
5
+ <a href="reek.png?<%= Time.now.localtime %>">
6
+ <img src="reek.png?<%= Time.now.localtime %>" width="400">
7
+ </a>
8
+
3
9
  <table>
4
10
  <tr>
5
11
  <th>File Path</th>
@@ -1,5 +1,11 @@
1
1
  <h3>Roodi Results</h3>
2
+
2
3
  <p><a href="http://roodi.rubyforge.org/">Roodi</a> parses your Ruby code and warns you about design issues you have based on the checks that is has configured.</p>
4
+
5
+ <a href="roodi.png?<%= Time.now.localtime %>">
6
+ <img src="roodi.png?<%= Time.now.localtime %>" width="400">
7
+ </a>
8
+
3
9
  <table>
4
10
  <tr>
5
11
  <th>File Path</th>
data/tasks/metric_fu.rake CHANGED
@@ -5,9 +5,13 @@ namespace :metrics do
5
5
  MetricFu::Configuration.run {}
6
6
  MetricFu.metrics.each {|metric| MetricFu.report.add(metric) }
7
7
  MetricFu.report.save_output(MetricFu.report.to_yaml,
8
- MetricFu.base_directory,
9
- 'report.yml')
8
+ MetricFu.data_directory,
9
+ "#{Time.now.strftime("%Y%m%d")}.yml")
10
10
  MetricFu.report.save_templatized_report
11
+
12
+ MetricFu.graphs.each {|graph| MetricFu.graph.add(graph) }
13
+ MetricFu.graph.generate
14
+
11
15
  if MetricFu.report.open_in_browser?
12
16
  MetricFu.report.show_in_browser(MetricFu.output_directory)
13
17
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edouard-metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3.8
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs
@@ -78,8 +78,18 @@ dependencies:
78
78
  - !ruby/object:Gem::Version
79
79
  version: 0.3.0
80
80
  version:
81
+ - !ruby/object:Gem::Dependency
82
+ name: topfunky-gruff
83
+ type: :runtime
84
+ version_requirement:
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.5
90
+ version:
81
91
  description: Code metrics from Flog, Flay, RCov, Saikuro, Churn, Reek, Roodi and Rails' stats task
82
- email: jake.scruggs@gmail.com
92
+ email: edouard.briere@gmail.com
83
93
  executables: []
84
94
 
85
95
  extensions: []
@@ -131,7 +141,14 @@ files:
131
141
  - lib/templates/awesome/awesome_template.rb
132
142
  - lib/templates/awesome/stats.html.erb
133
143
  - lib/templates/awesome/layout.html.erb
144
+ - lib/base/graph.rb
145
+ - lib/graphs/flay_grapher.rb
146
+ - lib/graphs/flog_grapher.rb
147
+ - lib/graphs/rcov_grapher.rb
148
+ - lib/graphs/reek_grapher.rb
149
+ - lib/graphs/roodi_grapher.rb
134
150
  - tasks/metric_fu.rake
151
+ - vendor/_fonts/monaco.ttf
135
152
  - tasks/railroad.rake
136
153
  - vendor/saikuro/saikuro.rb
137
154
  - Manifest.txt
@@ -161,7 +178,7 @@ rubyforge_project:
161
178
  rubygems_version: 1.2.0
162
179
  signing_key:
163
180
  specification_version: 2
164
- summary: A fistful of code metrics
181
+ summary: A fistful of code metrics, with awesome templates and graphs
165
182
  test_files:
166
183
  - spec/base/base_template_spec.rb
167
184
  - spec/base/configuration_spec.rb