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 +1 -1
- data/lib/conductor/weights.rb +8 -1
- data/test/test_conductor.rb +16 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
data/lib/conductor/weights.rb
CHANGED
@@ -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
|
data/test/test_conductor.rb
CHANGED
@@ -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)
|