Skip to content

Commit 13e11b6

Browse files
cmantasandrew
authored andcommitted
Avoid z_score numeric exception for conversion rates >1 (#503)
At normal operation, it's not possible for an experiment to have a `participant_count` > `completed_count`. However, by manually using `increment_participation` (for a custom use-case or by accident) you can arrive on such a situation. If that happens, `Zscore.calculate` produces an error that propagates all the way up to the web view. Solution: In the cornercase of a conversion rates taking a value >1, it makes no sense to calculate a zscore value at all. An escape clause was added
1 parent 87fbd83 commit 13e11b6

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/split/alternative.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def z_score(goal = nil)
119119
n_a = alternative.participant_count
120120
n_c = control.participant_count
121121

122+
# can't calculate zscore for P(x) > 1
123+
return 'N/A' if p_a > 1 || p_c > 1
124+
122125
z_score = Split::Zscore.calculate(p_a, n_a, p_c, n_c)
123126
end
124127

spec/alternative_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@
273273
expect(control.z_score(goal1)).to eq('N/A')
274274
expect(control.z_score(goal2)).to eq('N/A')
275275
end
276+
277+
it "should not blow up for Conversion Rates > 1" do
278+
control = experiment.control
279+
control.participant_count = 3474
280+
control.set_completed_count(4244)
281+
282+
alternative2.participant_count = 3434
283+
alternative2.set_completed_count(4358)
284+
285+
expect { control.z_score }.not_to raise_error
286+
expect { alternative2.z_score }.not_to raise_error
287+
end
276288
end
277289

278290
describe "extra_info" do

0 commit comments

Comments
 (0)