Skip to content

Commit

Permalink
Merge pull request splitrb#50 from elliotcm/master
Browse files Browse the repository at this point in the history
A refactor of the confidence helper
  • Loading branch information
andrew committed Apr 24, 2012
2 parents e2c7074 + af5bd61 commit 7a539b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
35 changes: 12 additions & 23 deletions lib/split/dashboard/helpers.rb
Expand Up @@ -19,30 +19,19 @@ def round(number, precision = 2)
def confidence_level(z_score)
return z_score if z_score.is_a? String

z = round(z_score.to_s.to_f, 3)
if z > 0.0
if z < 1.96
'no confidence'
elsif z < 2.57
'95% confidence'
elsif z < 3.29
'99% confidence'
else
'99.9% confidence'
end
elsif z < 0.0
if z > -1.96
'no confidence'
elsif z > -2.57
'95% confidence'
elsif z > -3.29
'99% confidence'
else
'99.9% confidence'
end
z = round(z_score.to_s.to_f, 3).abs

if z == 0.0
'No Change'
elsif z < 1.96
'no confidence'
elsif z < 2.57
'95% confidence'
elsif z < 3.29
'99% confidence'
else
"No Change"
'99.9% confidence'
end
end
end
end
end
10 changes: 9 additions & 1 deletion spec/dashboard_helpers_spec.rb
Expand Up @@ -8,5 +8,13 @@
it 'should handle very small numbers' do
confidence_level(Complex(2e-18, -0.03)).should eql('No Change')
end

it "should consider a z-score of 1.96 < z < 2.57 as 95% confident" do
confidence_level(2.12).should eql('95% confidence')
end

it "should consider a z-score of -1.96 > z > -2.57 as 95% confident" do
confidence_level(-2.12).should eql('95% confidence')
end
end
end
end

0 comments on commit 7a539b5

Please sign in to comment.