Skip to content

Commit

Permalink
Merge branch 'skip-missing-metrics' into rbp-gchart
Browse files Browse the repository at this point in the history
  • Loading branch information
cgriego committed Jul 25, 2010
2 parents a4f03e2 + 6be94c4 commit 275c68f
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 178 deletions.
14 changes: 6 additions & 8 deletions lib/graphs/flay_grapher.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module MetricFu

class FlayGrapher < Grapher

attr_accessor :flay_score, :labels

def initialize
super
@flay_score = []
@labels = {}
end

def get_metrics(metrics, date)
@flay_score.push(metrics[:flay][:total_score].to_i)
@labels.update( { @labels.size => date })
if metrics && metrics[:flay]
@flay_score.push(metrics[:flay][:total_score].to_i)
@labels.update( { @labels.size => date })
end
end

end

end
20 changes: 9 additions & 11 deletions lib/graphs/flog_grapher.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
module MetricFu

class FlogGrapher < Grapher

attr_accessor :flog_average, :labels, :top_five_percent_average

def initialize
super
@flog_average = []
@labels = {}
@top_five_percent_average =[]
end

def get_metrics(metrics, date)
@top_five_percent_average.push(calc_top_five_percent_average(metrics))
@flog_average.push(metrics[:flog][:average])
@labels.update( { @labels.size => date })
if metrics && metrics[:flog]
@top_five_percent_average.push(calc_top_five_percent_average(metrics))
@flog_average.push(metrics[:flog][:average])
@labels.update( { @labels.size => date })
end
end

private

def calc_top_five_percent_average(metrics)
methods = metrics[:flog][:pages].inject([]) {|methods, page| methods << page[:scanned_methods]}
methods.flatten!
Expand All @@ -34,7 +34,5 @@ def calc_top_five_percent_average(metrics)
total_for_five_percent / number_of_methods_that_is_five_percent.to_f
end
end

end

end
14 changes: 6 additions & 8 deletions lib/graphs/rcov_grapher.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module MetricFu

class RcovGrapher < Grapher

attr_accessor :rcov_percent, :labels

def initialize
super
self.rcov_percent = []
self.labels = {}
end

def get_metrics(metrics, date)
self.rcov_percent.push(metrics[:rcov][:global_percent_run])
self.labels.update( { self.labels.size => date })
if metrics && metrics[:rcov]
self.rcov_percent.push(metrics[:rcov][:global_percent_run])
self.labels.update( { self.labels.size => date })
end
end

end

end
32 changes: 15 additions & 17 deletions lib/graphs/reek_grapher.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
module MetricFu

class ReekGrapher < Grapher

attr_accessor :reek_count, :labels

def initialize
super
@reek_count = {}
@labels = {}
end

def get_metrics(metrics, date)
counter = @labels.size
@labels.update( { @labels.size => date })

metrics[:reek][:matches].each do |reek_chunk|
reek_chunk[:code_smells].each do |code_smell|
# speaking of code smell...
@reek_count[code_smell[:type]] = [] if @reek_count[code_smell[:type]].nil?
if @reek_count[code_smell[:type]][counter].nil?
@reek_count[code_smell[:type]][counter] = 1
else
@reek_count[code_smell[:type]][counter] += 1
if metrics && metrics[:reek]
counter = @labels.size
@labels.update( { @labels.size => date })

metrics[:reek][:matches].each do |reek_chunk|
reek_chunk[:code_smells].each do |code_smell|
# speaking of code smell...
@reek_count[code_smell[:type]] = [] if @reek_count[code_smell[:type]].nil?
if @reek_count[code_smell[:type]][counter].nil?
@reek_count[code_smell[:type]][counter] = 1
else
@reek_count[code_smell[:type]][counter] += 1
end
end
end
end
end

end

end
14 changes: 6 additions & 8 deletions lib/graphs/roodi_grapher.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module MetricFu

class RoodiGrapher < Grapher

attr_accessor :roodi_count, :labels

def initialize
super
@roodi_count = []
@labels = {}
end

def get_metrics(metrics, date)
@roodi_count.push(metrics[:roodi][:problems].size)
@labels.update( { @labels.size => date })
if metrics && metrics[:roodi]
@roodi_count.push(metrics[:roodi][:problems].size)
@labels.update( { @labels.size => date })
end
end

end

end
17 changes: 7 additions & 10 deletions lib/graphs/stats_grapher.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@

module MetricFu

class StatsGrapher < Grapher

attr_accessor :loc_counts, :lot_counts, :labels

def initialize
super
self.loc_counts = []
self.lot_counts = []
self.labels = {}
end

def get_metrics(metrics, date)
self.loc_counts.push(metrics[:stats][:codeLOC].to_i)
self.lot_counts.push(metrics[:stats][:testLOC].to_i)
self.labels.update( { self.labels.size => date })
if metrics && metrics[:stats]
self.loc_counts.push(metrics[:stats][:codeLOC].to_i)
self.lot_counts.push(metrics[:stats][:testLOC].to_i)
self.labels.update( { self.labels.size => date })
end
end

end

end
51 changes: 35 additions & 16 deletions spec/graphs/flay_grapher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,56 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe FlayGrapher do
describe FlayGrapher do
before :each do
@flay_grapher = MetricFu::FlayGrapher.new
MetricFu.configuration
end

it "should respond to flay_score and labels" do
@flay_grapher.should respond_to(:flay_score)
@flay_grapher.should respond_to(:labels)
end

describe "responding to #initialize" do
it "should initialise flay_score and labels" do
@flay_grapher.flay_score.should == []
@flay_grapher.labels.should == {}
end
end

describe "responding to #get_metrics" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
@date = "1/2"
end

it "should push 476 to flay_score" do
@flay_grapher.flay_score.should_receive(:push).with(476)
@flay_grapher.get_metrics(@metrics, @date)
context "when metrics were not generated" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "metric_missing.yml")))
@date = "1/2"
end

it "should not push to flay_score" do
@flay_grapher.flay_score.should_not_receive(:push)
@flay_grapher.get_metrics(@metrics, @date)
end

it "should not update labels with the date" do
@flay_grapher.labels.should_not_receive(:update)
@flay_grapher.get_metrics(@metrics, @date)
end
end

it "should update labels with the date" do
@flay_grapher.labels.should_receive(:update).with({ 0 => "1/2" })
@flay_grapher.get_metrics(@metrics, @date)

context "when metrics have been generated" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
@date = "1/2"
end

it "should push to flay_score" do
@flay_grapher.flay_score.should_receive(:push).with(476)
@flay_grapher.get_metrics(@metrics, @date)
end

it "should update labels with the date" do
@flay_grapher.labels.should_receive(:update).with({ 0 => "1/2" })
@flay_grapher.get_metrics(@metrics, @date)
end
end
end
end
66 changes: 45 additions & 21 deletions spec/graphs/flog_grapher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,65 @@
@flog_grapher = MetricFu::FlogGrapher.new
MetricFu.configuration
end

it "should respond to flog_total, flog_average and labels" do
@flog_grapher.should respond_to(:flog_average)
@flog_grapher.should respond_to(:labels)
@flog_grapher.should respond_to(:top_five_percent_average)
end

describe "responding to #initialize" do
it "should initialize top_five_percent_average, flog_average and labels" do
@flog_grapher.flog_average.should == []
@flog_grapher.labels.should == {}
@flog_grapher.top_five_percent_average.should == []
end
end

describe "responding to #get_metrics" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
@date = "1/2"
end

it "should push to top_five_percent_average" do
average = (73.6 + 68.5 + 66.1 + 46.6 + 44.8 + 44.1 + 41.2 + 36.0) / 8.0
@flog_grapher.top_five_percent_average.should_receive(:push).with(average)
@flog_grapher.get_metrics(@metrics, @date)
end

it "should push 9.9 to flog_average" do
@flog_grapher.flog_average.should_receive(:push).with(9.9)
@flog_grapher.get_metrics(@metrics, @date)
context "when metrics were not generated" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "metric_missing.yml")))
@date = "1/2"
end

it "should not push to top_five_percent_average" do
@flog_grapher.top_five_percent_average.should_not_receive(:push)
@flog_grapher.get_metrics(@metrics, @date)
end

it "should not push to flog_average" do
@flog_grapher.flog_average.should_not_receive(:push)
@flog_grapher.get_metrics(@metrics, @date)
end

it "should not update labels with the date" do
@flog_grapher.labels.should_not_receive(:update)
@flog_grapher.get_metrics(@metrics, @date)
end
end

it "should update labels with the date" do
@flog_grapher.labels.should_receive(:update).with({ 0 => "1/2" })
@flog_grapher.get_metrics(@metrics, @date)

context "when metrics have been generated" do
before(:each) do
@metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
@date = "1/2"
end

it "should push to top_five_percent_average" do
average = (73.6 + 68.5 + 66.1 + 46.6 + 44.8 + 44.1 + 41.2 + 36.0) / 8.0
@flog_grapher.top_five_percent_average.should_receive(:push).with(average)
@flog_grapher.get_metrics(@metrics, @date)
end

it "should push to flog_average" do
@flog_grapher.flog_average.should_receive(:push).with(9.9)
@flog_grapher.get_metrics(@metrics, @date)
end

it "should update labels with the date" do
@flog_grapher.labels.should_receive(:update).with({ 0 => "1/2" })
@flog_grapher.get_metrics(@metrics, @date)
end
end
end
end
Loading

0 comments on commit 275c68f

Please sign in to comment.