Permalink
Browse files

Add ab_test_chosen? helper and chosen? method on experiment

  • Loading branch information...
1 parent 067b8d1 commit 7194b70bd3d01edab17012828864070d97efba92 Ariel Salomon committed with sideshowbandana Aug 3, 2011
View
5 lib/vanity/adapters/abstract_adapter.rb
@@ -110,6 +110,11 @@ def ab_add_participant(experiment, alternative, identity)
fail "Not implemented"
end
+ # Indicates which alternative has been picked for this participant. See #ab_add_participant.
+ def ab_chosen(experiment, identity)
+ false # TODO: default to false for now; should add to each adapter
+ end
+
# Records a conversion in this experiment for the given alternative.
# Associates a value with the conversion (default to 1). If implicit is
# true, add particpant if not already recorded for this experiment. If
View
6 lib/vanity/adapters/active_record_adapter.rb
@@ -220,6 +220,12 @@ def ab_add_participant(experiment, alternative, identity)
VanityParticipant.retrieve(experiment, identity, true, :seen => alternative)
end
+ # Indicates which alternative has been picked for this participant. See #ab_add_participant.
+ def ab_chosen(experiment, identity)
+ participant = VanityParticipant.retrieve(experiment, identity, false)
+ participant && participant.seen
+ end
+
# Records a conversion in this experiment for the given alternative.
# Associates a value with the conversion (default to 1). If implicit is
# true, add particpant if not already recorded for this experiment. If
View
12 lib/vanity/experiment/ab_test.rb
@@ -279,6 +279,18 @@ def showing?(alternative)
end
end
+ # True if this experiment has been selected for the current id (see #chooses).
+ def chosen?
+ # True if experiment is active and a value has been chosen for current identity
+ !!if @playground.collecting? # return a boolean value
+ active? && (connection.ab_showing(@id, identity()) ||
+ connection.ab_chosen(@id, identity()))
+ # TODO: implement ab_chosen on all vanity adapters!!
+ else
+ @showing && @showing[identity()]
+ end
+ end
+
# -- Reporting --
View
5 lib/vanity/helpers.rb
@@ -50,6 +50,11 @@ def ab_test(name, &block)
end
end
+ # Check whether the specified experiment has had a value chosen yet
+ def ab_test_chosen?(id)
+ Vanity.playground.experiment(id).chosen?
+ end
+
# Tracks an action associated with a metric.
#
# @example

0 comments on commit 7194b70

Please sign in to comment.