本文整理匯總了Python中experiments.experiment_counters.ExperimentCounter.increment_goal_count方法的典型用法代碼示例。如果您正苦於以下問題:Python ExperimentCounter.increment_goal_count方法的具體用法?Python ExperimentCounter.increment_goal_count怎麽用?Python ExperimentCounter.increment_goal_count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類experiments.experiment_counters.ExperimentCounter
的用法示例。
在下文中一共展示了ExperimentCounter.increment_goal_count方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: WebUser
# 需要導入模塊: from experiments.experiment_counters import ExperimentCounter [as 別名]
# 或者: from experiments.experiment_counters.ExperimentCounter import increment_goal_count [as 別名]
class WebUser(object):
"""Represents a user (either authenticated or session based) which can take part in experiments"""
def __init__(self):
self.experiment_counter = ExperimentCounter()
def enroll(self, experiment_name, alternatives, force_alternative=None):
"""
Enroll this user in the experiment if they are not already part of it. Returns the selected alternative
force_alternative: Optionally force a user in an alternative at enrollment time
"""
chosen_alternative = conf.CONTROL_GROUP
experiment = experiment_manager.get(experiment_name, None)
if experiment and experiment.is_displaying_alternatives():
if isinstance(alternatives, collections.Mapping):
if conf.CONTROL_GROUP not in alternatives:
experiment.ensure_alternative_exists(conf.CONTROL_GROUP, 1)
for alternative, weight in alternatives.items():
experiment.ensure_alternative_exists(alternative, weight)
else:
alternatives_including_control = alternatives + [conf.CONTROL_GROUP]
for alternative in alternatives_including_control:
experiment.ensure_alternative_exists(alternative)
assigned_alternative = self._get_enrollment(experiment)
if assigned_alternative:
chosen_alternative = assigned_alternative
elif experiment.is_accepting_new_users():
if force_alternative:
chosen_alternative = force_alternative
else:
chosen_alternative = experiment.random_alternative()
self._set_enrollment(experiment, chosen_alternative)
return chosen_alternative
def get_alternative(self, experiment_name):
"""Get the alternative this user is enrolled in. If not enrolled in the experiment returns 'control'"""
experiment = experiment_manager.get(experiment_name, None)
if experiment and experiment.is_displaying_alternatives():
alternative = self._get_enrollment(experiment)
if alternative is not None:
return alternative
return "control"
def set_alternative(self, experiment_name, alternative):
"""Explicitly set the alternative the user is enrolled in for the specified experiment.
This allows you to change a user between alternatives. The user and goal counts for the new
alternative will be increment, but those for the old one will not be decremented. The user will
be enrolled in the experiment even if the experiment would not normally accept this user."""
experiment = experiment_manager.get(experiment_name, None)
if experiment:
self._set_enrollment(experiment, alternative)
def goal(self, goal_name, count=1):
"""Record that this user has performed a particular goal
This will update the goal stats for all experiments the user is enrolled in."""
for enrollment in self._get_all_enrollments():
if enrollment.experiment.is_displaying_alternatives():
self._experiment_goal(enrollment.experiment, enrollment.alternative, goal_name, count)
def confirm_human(self):
"""Mark that this is a real human being (not a bot) and thus results should be counted"""
pass
def incorporate(self, other_user):
"""Incorporate all enrollments and goals performed by the other user
If this user is not enrolled in a given experiment, the results for the
other user are incorporated. For experiments this user is already
enrolled in the results of the other user are discarded.
This takes a relatively large amount of time for each experiment the other
user is enrolled in."""
for enrollment in other_user._get_all_enrollments():
if not self._get_enrollment(enrollment.experiment):
self._set_enrollment(
enrollment.experiment, enrollment.alternative, enrollment.enrollment_date, enrollment.last_seen
)
goals = self.experiment_counter.participant_goal_frequencies(
enrollment.experiment, enrollment.alternative, other_user._participant_identifier()
)
for goal_name, count in goals:
self.experiment_counter.increment_goal_count(
enrollment.experiment, enrollment.alternative, goal_name, self._participant_identifier(), count
)
other_user._cancel_enrollment(enrollment.experiment)
def visit(self):
"""Record that the user has visited the site for the purposes of retention tracking"""
for enrollment in self._get_all_enrollments():
if enrollment.experiment.is_displaying_alternatives():
# We have two different goals, VISIT_NOT_PRESENT_COUNT_GOAL and VISIT_PRESENT_COUNT_GOAL.
# VISIT_PRESENT_COUNT_GOAL will avoid firing on the first time we set last_seen as it is assumed that the user is
# on the page and therefore it would automatically trigger and be valueless.
# This should be used for experiments when we enroll the user as part of the pageview,
#.........這裏部分代碼省略.........