jscruggs-metric_fu 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,10 @@
1
+ === MetricFu 1.1.3 / 2009-7-10
2
+
3
+ * MetricFu is now Ruby 1.9x compatible
4
+ * Removed the check for deprecated ways of configuring metric_fu as the tests were causing Ruby 1.9x problems and it's been forever since they were supported.
5
+ * Removed total flog score from graph (which will always go up and so doesn't mean much) and replacing it with top_five_percent_average which is an average of the worst 5 percent of your methods.
6
+ * Sort Flog by highest score in the class which I feel is more important than the total flog flog score.
7
+
1
8
  === MetricFu 1.1.2 / 2009-7-09
2
9
 
3
10
  * Removed dependency on gruff and rmagick (unless the user wants graphs, of course).
@@ -51,7 +51,6 @@ module MetricFu
51
51
  class Configuration
52
52
 
53
53
  def initialize #:nodoc:#
54
- warn_about_deprecated_config_options
55
54
  reset
56
55
  add_attr_accessors_to_self
57
56
  add_class_methods_to_metric_fu
@@ -82,25 +81,6 @@ module MetricFu
82
81
  end
83
82
  end
84
83
 
85
- # Check if certain constants that are deprecated have been
86
- # assigned. If so, warn the user about them, and the
87
- # fact that they will have no effect.
88
- def warn_about_deprecated_config_options
89
- if defined?(::MetricFu::CHURN_OPTIONS)
90
- raise("Use config.churn instead of MetricFu::CHURN_OPTIONS")
91
- end
92
- if defined?(::MetricFu::DIRECTORIES_TO_FLOG)
93
- raise("Use config.flog[:dirs_to_flog] "+
94
- "instead of MetricFu::DIRECTORIES_TO_FLOG")
95
- end
96
- if defined?(::MetricFu::SAIKURO_OPTIONS)
97
- raise("Use config.saikuro instead of MetricFu::SAIKURO_OPTIONS")
98
- end
99
- if defined?(SAIKURO_OPTIONS)
100
- raise("Use config.saikuro instead of SAIKURO_OPTIONS")
101
- end
102
- end
103
-
104
84
  # This allows us to have a nice syntax like:
105
85
  #
106
86
  # MetricFu.run do |config|
@@ -197,7 +177,7 @@ module MetricFu
197
177
  end
198
178
 
199
179
  def platform #:nodoc:
200
- return PLATFORM
180
+ return RUBY_PLATFORM
201
181
  end
202
182
 
203
183
  def is_cruise_control_rb?
@@ -1,5 +1,4 @@
1
1
  require 'chronic'
2
- require 'generator'
3
2
  module MetricFu
4
3
 
5
4
  class Churn < Generator
@@ -1,4 +1,3 @@
1
- require 'generator'
2
1
  module MetricFu
3
2
 
4
3
  class Flay < Generator
@@ -62,7 +62,7 @@ module MetricFu
62
62
  def to_h
63
63
  number_of_methods = @pages.inject(0) {|count, page| count += page.scanned_methods.size}
64
64
  total_flog_score = @pages.inject(0) {|total, page| total += page.score}
65
- sorted_pages = @pages.sort_by {|page| page.score }.reverse
65
+ sorted_pages = @pages.sort_by {|page| page.highest_score }.reverse
66
66
  {:flog => { :total => total_flog_score,
67
67
  :average => average_score(total_flog_score, number_of_methods),
68
68
  :pages => sorted_pages.map {|page| page.to_h}}}
@@ -2,17 +2,17 @@ module MetricFu
2
2
 
3
3
  class FlogGrapher < Grapher
4
4
 
5
- attr_accessor :flog_total, :flog_average, :labels
5
+ attr_accessor :flog_average, :labels, :top_five_percent_average
6
6
 
7
7
  def initialize
8
8
  super
9
- self.flog_total = []
10
9
  self.flog_average = []
11
10
  self.labels = {}
11
+ self.top_five_percent_average =[]
12
12
  end
13
13
 
14
14
  def get_metrics(metrics, date)
15
- self.flog_total.push(metrics[:flog][:total])
15
+ self.top_five_percent_average.push(calc_top_five_percent_average(metrics))
16
16
  self.flog_average.push(metrics[:flog][:average])
17
17
  self.labels.update( { self.labels.size => date })
18
18
  end
@@ -22,7 +22,7 @@ module MetricFu
22
22
  g.title = "Flog: code complexity"
23
23
  g.theme = MetricFu.graph_theme
24
24
  g.font = MetricFu.graph_font
25
- g.data('flog total', self.flog_total)
25
+ g.data('top five percent average', self.top_five_percent_average)
26
26
  g.data('flog average', self.flog_average)
27
27
  g.labels = self.labels
28
28
  g.title_font_size = MetricFu.graph_title_font_size
@@ -32,6 +32,20 @@ module MetricFu
32
32
  g.write(File.join(MetricFu.output_directory, 'flog.png'))
33
33
  end
34
34
 
35
+ private
36
+
37
+ def calc_top_five_percent_average(metrics)
38
+ methods = metrics[:flog][:pages].inject([]) {|methods, page| methods << page[:scanned_methods]}
39
+ methods.flatten!
40
+
41
+ methods = methods.sort_by {|method| method[:score]}.reverse
42
+
43
+ number_of_methods_that_is_five_percent = (methods.size * 0.05).ceil
44
+
45
+ total_for_five_percent = methods[0...number_of_methods_that_is_five_percent].inject(0) {|total, method| total += method[:score]}
46
+ total_for_five_percent / number_of_methods_that_is_five_percent.to_f
47
+ end
48
+
35
49
  end
36
50
 
37
51
  end
@@ -8,8 +8,8 @@ module MetricFu
8
8
  require 'gruff'
9
9
  rescue LoadError
10
10
  puts "#"*99 + "\n" +
11
- "If you want to use metric_fu's graphing features then you'll need to install the gems 'topfunky-gruff' and 'rmagick' "+
12
- "(and rmagick requires ImageMagick). "+
11
+ "If you want to use metric_fu's graphing features then you'll need to install the gems " +
12
+ "'topfunky-gruff' (or 'umang-gruff' if you use 1.9x) and 'rmagick' (and rmagick requires ImageMagick). "+
13
13
  "If you don't want to deal with that, then make sure you set config.graphs = [] (see the metric_fu's homepage for more details) "+
14
14
  "to indicate that you don't want graphing." +
15
15
  "\n" + "#"*99
@@ -1,4 +1,5 @@
1
1
  require 'rake'
2
+ require 'yaml'
2
3
  # Load a few things to make our lives easier elsewhere.
3
4
  module MetricFu
4
5
  LIB_ROOT = File.dirname(__FILE__)
@@ -30,53 +30,6 @@ describe MetricFu::Configuration do
30
30
  @config.instance_variable_get(:@metric_fu_root_directory)
31
31
  end
32
32
 
33
- describe '#warn_about_deprecated_config_options' do
34
-
35
- def get_new_config_and_raise_runtime_error
36
- lambda { get_new_config }.should raise_error
37
- end
38
-
39
- describe 'when ::MetricFu::CHURN_OPTIONS is present' do
40
- before(:each) { ::MetricFu::CHURN_OPTIONS = 'option' }
41
- after(:each) { ::MetricFu.send(:remove_const, 'CHURN_OPTIONS') }
42
-
43
- it 'should raise a RuntimeError with "Use config.churn '+
44
- 'instead of MetricFu::CHURN_OPTIONS"' do
45
- get_new_config_and_raise_runtime_error
46
- end
47
- end
48
-
49
- describe 'when ::MetricFu::DIRECTORIES_TO_FLOG is present' do
50
- before(:each) { ::MetricFu::DIRECTORIES_TO_FLOG = 'option' }
51
- after(:each) { ::MetricFu.send(:remove_const,'DIRECTORIES_TO_FLOG')}
52
-
53
- it 'should raise a RuntimeError with "Use config.flog '+
54
- '[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG' do
55
- get_new_config_and_raise_runtime_error
56
- end
57
- end
58
-
59
- describe 'when ::MetricFu::SAIKURO_OPTIONS is present' do
60
- before(:each) { ::MetricFu::SAIKURO_OPTIONS = 'option' }
61
- after(:each) { ::MetricFu.send(:remove_const,'SAIKURO_OPTIONS')}
62
-
63
- it 'should raise a RuntimeError with "Use config.saikuro '+
64
- 'instead of MetricFu::SAIKURO_OPTIONS' do
65
- get_new_config_and_raise_runtime_error
66
- end
67
- end
68
-
69
- describe 'when SAIKURO_OPTIONS is present' do
70
- before(:each) { SAIKURO_OPTIONS = 'option' }
71
- after(:each) { Object.send(:remove_const,'SAIKURO_OPTIONS')}
72
-
73
- it 'should raise a RuntimeError with "Use config.saikuro '+
74
- 'instead of SAIKURO_OPTIONS' do
75
- get_new_config_and_raise_runtime_error
76
- end
77
- end
78
- end
79
-
80
33
  describe "#reset" do
81
34
 
82
35
  before(:each) { get_new_config }
@@ -318,7 +271,7 @@ describe MetricFu::Configuration do
318
271
  before(:each) { get_new_config }
319
272
 
320
273
  it 'should return the value of the PLATFORM constant' do
321
- this_platform = PLATFORM
274
+ this_platform = RUBY_PLATFORM
322
275
  @config.platform.should == this_platform
323
276
  end
324
277
  end
@@ -7,16 +7,16 @@ describe MetricFu::FlogGrapher do
7
7
  end
8
8
 
9
9
  it "should respond to flog_total, flog_average and labels" do
10
- @flog_grapher.should respond_to(:flog_total)
11
10
  @flog_grapher.should respond_to(:flog_average)
12
11
  @flog_grapher.should respond_to(:labels)
12
+ @flog_grapher.should respond_to(:top_five_percent_average)
13
13
  end
14
14
 
15
15
  describe "responding to #initialize" do
16
- it "should initialize flog_total, flog_average and labels" do
17
- @flog_grapher.flog_total.should == []
16
+ it "should initialize top_five_percent_average, flog_average and labels" do
18
17
  @flog_grapher.flog_average.should == []
19
18
  @flog_grapher.labels.should == {}
19
+ @flog_grapher.top_five_percent_average.should == []
20
20
  end
21
21
  end
22
22
 
@@ -26,8 +26,9 @@ describe MetricFu::FlogGrapher do
26
26
  @date = "01022003"
27
27
  end
28
28
 
29
- it "should push 1491.1 to flog_total" do
30
- @flog_grapher.flog_total.should_receive(:push).with(1491.1)
29
+ it "should push to top_five_percent_average" do
30
+ average = (73.6 + 68.5 + 66.1 + 46.6 + 44.8 + 44.1 + 41.2 + 36.0) / 8.0
31
+ @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
31
32
  @flog_grapher.get_metrics(@metrics, @date)
32
33
  end
33
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jscruggs-metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs