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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b000e4eb969554a264a4abfc4293be995c35e1c
4
- data.tar.gz: 6ef436d7216b99eb8b7b31b8181cbeeccf53ed8c
3
+ metadata.gz: eb383a7cb2da6ee78a368cd1786a6983d5301cf1
4
+ data.tar.gz: fd1ae010dd251e372613519fe3f5aa69d8a538da
5
5
  SHA512:
6
- metadata.gz: ade19662889d8bef5926285e67a1715f586adb92ab10de8988ba367d2bc54a2145ec36f6946187b8a1f4acefdf25d4109f8beeeebc400449f9cc5b8b11fa692c
7
- data.tar.gz: 56e137554415c1dfa674e6aec64cd2cd3e102fa078b5445a5c2471d9680ffa1b6c5ea5a059436cc6f69fffddc399c741716d44c24b1d5b3f4eee7a47fdc5f376
6
+ metadata.gz: 65619f8b2894f0a333fd1f6d3997473f9fd63d690dc52830e2cddb5e5953a7fa1dc92b301345ae178c9fdd73dd65586c3082fad2a793866a9ed5c95745890769
7
+ data.tar.gz: a91d8d6d72af43bc5fd410cc331e67c00892bca39f83614127ac052449d0bb7cf14f5bc5a8b5cb547f32dba9cbb477a76f60cc698825798c42069b93cdee6689
@@ -20,6 +20,10 @@ module Ablab
20
20
 
21
21
  def dashboard
22
22
  @experiments = Ablab.experiments
23
+ @results = Ablab.experiments.reduce({}) do |h, (name, experiment)|
24
+ h[name] = experiment.results
25
+ h
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -1,18 +1,18 @@
1
1
  module Ablab
2
2
  module AblabHelper
3
- def format_ratio(numerator, denominator, na = 'n/a')
3
+ def format_percentage(numerator, denominator, na = 'n/a')
4
4
  return na if denominator == 0
5
- '%.3f' % (numerator.to_f / denominator)
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, separator: '.', delimiter: ',')
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
- '%.3f' % decimal
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
- winner_name, winner_results = experiment.results.max_by do |(_, r)|
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
- significant?(winner_results) && winner_name == group_name
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.results.each do |group_name, results| %>
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><%= format_ratio results[:conversions].to_f, results[:sessions] %></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>
@@ -135,9 +135,8 @@ module Ablab
135
135
 
136
136
  def group
137
137
  return @group unless @group.nil?
138
- if forced = forced_group
139
- return forced
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
- return nil unless forced = request.params[:ablab_group]
166
- hash = forced.split(/\s*,\s*/).map do |s|
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)
@@ -1,3 +1,3 @@
1
1
  module Ablab
2
- VERSION = "0.2.9"
2
+ VERSION = "0.2.10"
3
3
  end
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.9
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 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails