conductor 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
@@ -24,6 +24,13 @@ class Conductor
24
24
  end
25
25
  end
26
26
 
27
+ # Computes the weights for a group based on the attribute for weighting and
28
+ # activity for the last two weeks.
29
+ #
30
+ # If no conversions have taken place yet for a group, all alternatives are weighted
31
+ # equally.
32
+ #
33
+ # TODO: add notification table and all notification if there are no conversions and we are out of the equalization period
27
34
  def compute(group_name, alternatives)
28
35
  # create the conditions after sanitizing sql.
29
36
  alternative_filter = alternatives.inject([]) {|res,x| res << "alternative = '#{Conductor.sanitize(x)}'"}.join(' OR ')
@@ -34,7 +41,7 @@ class Conductor
34
41
  unless group_rows.empty?
35
42
  Conductor::Experiment::Weight.delete_all(:group_name => group_name) # => remove all old data for group
36
43
  total = group_rows.sum_it(Conductor.attribute_for_weighting)
37
- data = total ? compute_weights_for_group(group_name, group_rows, total) : assign_equal_weights(group_rows)
44
+ data = total > 0 ? compute_weights_for_group(group_name, group_rows, total) : assign_equal_weights(group_rows)
38
45
  update_weights_in_db(group_name, data)
39
46
  end
40
47
  end
@@ -250,6 +250,22 @@ class TestConductor < Test::Unit::TestCase
250
250
  # rollup
251
251
  Conductor::RollUp.process
252
252
  end
253
+
254
+ should "correctly calculate weights even if there are no conversions" do
255
+ Conductor::Experiment::Daily.update_all('conversion_value = 0.00, conversions = 0')
256
+ Conductor.identity = ActiveSupport::SecureRandom.hex(16)
257
+
258
+ assert_nil Conductor::Experiment::Daily.all.detect {|x| x.conversions > 0 || x.conversion_value > 0}
259
+ assert_equal 3, Conductor::Experiment.weights('a_group', ["a", "b", "c"]).values.sum
260
+ end
261
+
262
+ should "correctly calculate weights even if an alternative has no conversions" do
263
+ Conductor::Experiment::Daily.update_all('conversion_value = 0.00, conversions = 0', "alternative = 'a'")
264
+ Conductor.identity = ActiveSupport::SecureRandom.hex(16)
265
+
266
+ assert_nil Conductor::Experiment::Daily.find_all_by_alternative('a').detect {|x| x.conversions > 0 || x.conversion_value > 0}
267
+ assert_equal 0, Conductor::Experiment.weights('a_group', ["a", "b", "c"])['a']
268
+ end
253
269
 
254
270
  should "allow for the number of conversions to be used for weighting instead of conversion_value" do
255
271
  Conductor.identity = ActiveSupport::SecureRandom.hex(16)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 1
9
- version: 0.7.1
8
+ - 2
9
+ version: 0.7.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Noctivity