ablab 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ablab/base_controller.rb +4 -0
- data/app/helpers/ablab/ablab_helper.rb +35 -6
- data/app/views/ablab/base/dashboard.html.erb +7 -2
- data/lib/ablab.rb +10 -7
- data/lib/ablab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb383a7cb2da6ee78a368cd1786a6983d5301cf1
|
4
|
+
data.tar.gz: fd1ae010dd251e372613519fe3f5aa69d8a538da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65619f8b2894f0a333fd1f6d3997473f9fd63d690dc52830e2cddb5e5953a7fa1dc92b301345ae178c9fdd73dd65586c3082fad2a793866a9ed5c95745890769
|
7
|
+
data.tar.gz: a91d8d6d72af43bc5fd410cc331e67c00892bca39f83614127ac052449d0bb7cf14f5bc5a8b5cb547f32dba9cbb477a76f60cc698825798c42069b93cdee6689
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Ablab
|
2
2
|
module AblabHelper
|
3
|
-
def
|
3
|
+
def format_percentage(numerator, denominator, na = 'n/a')
|
4
4
|
return na if denominator == 0
|
5
|
-
|
5
|
+
number_to_percentage((numerator.to_f / denominator) * 100.0)
|
6
6
|
end
|
7
7
|
|
8
8
|
def format_number(number, na = 'n/a')
|
9
9
|
return na if number.nil? || number.try(:nan?)
|
10
|
-
number_with_delimiter(number
|
10
|
+
number_with_delimiter(number)
|
11
11
|
end
|
12
12
|
|
13
13
|
def format_decimal(decimal, na = 'n/a')
|
14
14
|
return na if decimal.nil? || decimal.nan?
|
15
|
-
|
15
|
+
number_with_precision(decimal, precision: 3)
|
16
16
|
end
|
17
17
|
|
18
18
|
def significant?(results)
|
@@ -22,6 +22,7 @@ module Ablab
|
|
22
22
|
|
23
23
|
def confidence(z_score, na = 'n/a')
|
24
24
|
return na if z_score.nil? || z_score.nan?
|
25
|
+
z_score = z_score.abs
|
25
26
|
if z_score >= 2.58
|
26
27
|
'99%'
|
27
28
|
elsif z_score >= 1.96
|
@@ -33,15 +34,43 @@ module Ablab
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
def cr_gain(results_a, results_b, na = 'n/a')
|
38
|
+
return na if results_a[:sessions] == 0 || results_b[:sessions] == 0
|
39
|
+
cr_a = results_a[:conversions].to_f / results_a[:sessions]
|
40
|
+
cr_b = results_b[:conversions].to_f / results_b[:sessions]
|
41
|
+
gain = cr_a - cr_b
|
42
|
+
"#{gain >= 0 ? '+' : ''}#{number_to_percentage(gain * 100.0)}"
|
43
|
+
end
|
44
|
+
|
36
45
|
def winner?(experiment, group_name)
|
37
|
-
|
46
|
+
winner(experiment) == group_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def winner(experiment)
|
50
|
+
@winners ||= {}
|
51
|
+
return @winners[experiment.name] if @winners.has_key?(experiment.name)
|
52
|
+
winner_name, winner_results = @results[experiment.name].max_by do |(_, r)|
|
38
53
|
if r[:sessions] > 0
|
39
54
|
r[:conversions].to_f / r[:sessions]
|
40
55
|
else
|
41
56
|
-1
|
42
57
|
end
|
43
58
|
end
|
44
|
-
|
59
|
+
@winners[experiment.name] = nil
|
60
|
+
@winners[experiment.name] = winner_name if significant?(winner_results)
|
61
|
+
@winners[experiment.name]
|
62
|
+
end
|
63
|
+
|
64
|
+
def gains(experiment, group_name)
|
65
|
+
result = experiment.results[group_name]
|
66
|
+
return nil if result[:sessions] == 0
|
67
|
+
cr = result[:conversions].to_f / result[:sessions]
|
68
|
+
experiment.results.reduce({}) do |hash, (g, r)|
|
69
|
+
if r[:sessions] > 0 && g != group_name
|
70
|
+
hash[g] = cr - (r[:conversions].to_f / r[:sessions])
|
71
|
+
end
|
72
|
+
hash
|
73
|
+
end
|
45
74
|
end
|
46
75
|
end
|
47
76
|
end
|
@@ -40,7 +40,7 @@
|
|
40
40
|
conversion rate, compared to the control group</i>
|
41
41
|
</th>
|
42
42
|
</tr>
|
43
|
-
<% experiment.
|
43
|
+
<% @results[experiment.name].each do |group_name, results| %>
|
44
44
|
<tr class="<%= 'winner' if winner?(experiment, group_name) %> <%= 'control' if results[:control] %>">
|
45
45
|
<td title="<%= results[:description] %>"><b><%= group_name.to_s.titleize %></b></td>
|
46
46
|
<td><%= results[:description] %></td>
|
@@ -48,7 +48,12 @@
|
|
48
48
|
<td><%= format_number results[:sessions] %></td>
|
49
49
|
<td><%= format_number results[:successes] %></td>
|
50
50
|
<td><%= format_number results[:conversions] %></td>
|
51
|
-
<td
|
51
|
+
<td>
|
52
|
+
<%= format_percentage results[:conversions].to_f, results[:sessions] %>
|
53
|
+
<% unless results[:control] %>
|
54
|
+
<em>(<%= cr_gain(results, @results[experiment.name][:control]) %>)</em>
|
55
|
+
<% end %>
|
56
|
+
</td>
|
52
57
|
<td><%= format_decimal results[:z_score] %></td>
|
53
58
|
<td><%= confidence results[:z_score] %></td>
|
54
59
|
</tr>
|
data/lib/ablab.rb
CHANGED
@@ -135,9 +135,8 @@ module Ablab
|
|
135
135
|
|
136
136
|
def group
|
137
137
|
return @group unless @group.nil?
|
138
|
-
|
139
|
-
|
140
|
-
end
|
138
|
+
forced = forced_group
|
139
|
+
return forced if forced
|
141
140
|
size = 1000.0 * (experiment.percentage_of_visitors) / 100.0
|
142
141
|
idx = (draw * experiment.groups.size / size).floor
|
143
142
|
@group = experiment.groups[idx].try(:name)
|
@@ -162,13 +161,17 @@ module Ablab
|
|
162
161
|
|
163
162
|
private def forced_group
|
164
163
|
return nil unless request && request.respond_to?(:params)
|
165
|
-
|
166
|
-
|
164
|
+
groups = parse_groups(request.params[:ablab_group])
|
165
|
+
group = groups[experiment.name.to_s]
|
166
|
+
group.to_sym if group && experiment.groups.map { |g| g.name.to_s }.include?(group)
|
167
|
+
end
|
168
|
+
|
169
|
+
private def parse_groups(str)
|
170
|
+
return {} unless str
|
171
|
+
hash = str.split(/\s*,\s*/).map do |s|
|
167
172
|
exp_group = s.split(/\s*:\s*/).take(2)
|
168
173
|
exp_group if exp_group.size == 2
|
169
174
|
end.compact.to_h
|
170
|
-
group = hash[experiment.name.to_s]
|
171
|
-
group.to_sym if group && experiment.groups.map { |g| g.name.to_s }.include?(group)
|
172
175
|
end
|
173
176
|
|
174
177
|
private def track!(event)
|
data/lib/ablab/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ablab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Ongaro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|