本文整理汇总了Python中experiments.utils.participant函数的典型用法代码示例。如果您正苦于以下问题:Python participant函数的具体用法?Python participant怎么用?Python participant使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了participant函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: render
def render(self, context):
# Get User object
if self.user_variable:
auth_user = self.user_variable.resolve(context)
user = participant(user=auth_user)
gargoyle_key = auth_user
else:
request = context.get('request', None)
user = participant(request)
gargoyle_key = request
# Extract session alternative, if any pertain to this experiment.
selected_alternative = None
if 'experiment' in request.session:
if request.session['experiment'] == self.experiment_name:
selected_alternative = request.session['alternative']
del request.session['experiment']
# Should we render?
if user.is_enrolled(self.experiment_name, self.alternative, gargoyle_key, selected_alternative):
response = self.node_list.render(context)
else:
response = ""
return response
开发者ID:dougvk,项目名称:django-experiments,代码行数:25,代码来源:experiments.py
示例2: test_visit_incorporate
def test_visit_incorporate(self):
alternative = participant(self.request).enroll(self.experiment.name, ['alternative'])
ExperimentsRetentionMiddleware().process_response(self.request, HttpResponse())
self.assertEqual(
dict(self.experiment_counter.participant_goal_frequencies(self.experiment,
alternative,
participant(self.request)._participant_identifier()))[conf.VISIT_NOT_PRESENT_COUNT_GOAL],
1
)
self.assertFalse(Enrollment.objects.all().exists())
self._login()
self.assertTrue(Enrollment.objects.all().exists())
self.assertIsNotNone(Enrollment.objects.all()[0].last_seen)
self.assertEqual(
dict(self.experiment_counter.participant_goal_frequencies(self.experiment,
alternative,
participant(self.request)._participant_identifier()))[conf.VISIT_NOT_PRESENT_COUNT_GOAL],
1
)
self.assertEqual(self.experiment_counter.goal_count(self.experiment, alternative, conf.VISIT_NOT_PRESENT_COUNT_GOAL), 1)
self.assertEqual(self.experiment_counter.participant_count(self.experiment, alternative), 1)
开发者ID:DjangoBD,项目名称:django-experiments,代码行数:25,代码来源:test_webuser_incorporate.py
示例3: change_alternative
def change_alternative(request, experiment_name, alternative_name):
experiment = get_object_or_404(Experiment, name=experiment_name)
if alternative_name not in experiment.alternatives.keys():
return HttpResponseBadRequest()
participant(request).set_alternative(experiment_name, alternative_name)
return HttpResponse('OK')
开发者ID:TomasM,项目名称:django-experiments,代码行数:7,代码来源:views.py
示例4: set_alternative
def set_alternative(self, request):
experiment_name = request.POST.get("experiment")
alternative_name = request.POST.get("alternative")
participant(request).set_alternative(experiment_name, alternative_name)
return {
'success': True,
'alternative': participant(request).get_alternative(experiment_name)
}
开发者ID:johnmarkschofield,项目名称:django-experiments,代码行数:8,代码来源:nexus_modules.py
示例5: setUp
def setUp(self):
self.experiment = Experiment.objects.create(name=EXPERIMENT_NAME, state=ENABLED_STATE)
self.experiment_counter = ExperimentCounter()
User = get_user_model()
self.user = User.objects.create(username='incorporate_user')
self.user.is_confirmed_human = True
request_factory = RequestFactory()
self.request = request_factory.get('/')
self.request.session = DatabaseSession()
participant(self.request).confirm_human()
开发者ID:DjangoBD,项目名称:django-experiments,代码行数:12,代码来源:test_webuser_incorporate.py
示例6: test_default_alternative
def test_default_alternative(self):
experiment = Experiment.objects.create(name='test_default')
self.assertEqual(experiment.default_alternative, conf.CONTROL_GROUP)
experiment.ensure_alternative_exists('alt1')
experiment.ensure_alternative_exists('alt2')
self.assertEqual(conf.CONTROL_GROUP, participant(session=DatabaseSession()).enroll('test_default', ['alt1', 'alt2']))
experiment.set_default_alternative('alt2')
experiment.save()
self.assertEqual('alt2', participant(session=DatabaseSession()).enroll('test_default', ['alt1', 'alt2']))
experiment.set_default_alternative('alt1')
experiment.save()
self.assertEqual('alt1', participant(session=DatabaseSession()).enroll('test_default', ['alt1', 'alt2']))
开发者ID:Dylgar,项目名称:django-experiments,代码行数:13,代码来源:test_webuser.py
示例7: test_transfer_enrollments
def test_transfer_enrollments(self):
User = get_user_model()
user = User.objects.create(username='test')
request = request_factory.get('/')
request.session = DatabaseSession()
participant(request).enroll('test_experiment1', ['alternative'])
request.user = user
transfer_enrollments_to_user(None, request, user)
# the call to the middleware will set last_seen on the experiment
# if the participant cache hasn't been wiped appropriately then the
# session experiment user will be impacted instead of the authenticated
# experiment user
ExperimentsRetentionMiddleware().process_response(request, HttpResponse())
self.assertIsNotNone(Enrollment.objects.all()[0].last_seen)
开发者ID:Dylgar,项目名称:django-experiments,代码行数:14,代码来源:test_webuser.py
示例8: test_record_goal_increments_counts
def test_record_goal_increments_counts(self):
experiment_user = participant(self.request)
experiment_user.confirm_human()
experiment_user.set_alternative(EXPERIMENT_NAME, TEST_ALTERNATIVE)
self.assertEqual(self.experiment_counter.goal_count(self.experiment, TEST_ALTERNATIVE, TEST_GOAL), 0)
experiment_user.goal(TEST_GOAL)
self.assertEqual(self.experiment_counter.goal_count(self.experiment, TEST_ALTERNATIVE, TEST_GOAL), 1, "Did not increment Goal count")
开发者ID:Dylgar,项目名称:django-experiments,代码行数:8,代码来源:test_webuser.py
示例9: setUp
def setUp(self):
super(LoggedInBotTestCase, self).setUp()
User = get_user_model()
self.user = User(username='brian')
self.user.is_confirmed_human = False
self.user.save()
self.experiment_user = participant(user=self.user)
开发者ID:Dylgar,项目名称:django-experiments,代码行数:8,代码来源:test_webuser.py
示例10: test_confirm_human_increments_goal_count
def test_confirm_human_increments_goal_count(self):
experiment_user = participant(self.request)
experiment_user.set_alternative(EXPERIMENT_NAME, TEST_ALTERNATIVE)
experiment_user.goal(TEST_GOAL)
self.assertEqual(self.experiment_counter.goal_count(self.experiment, TEST_ALTERNATIVE, TEST_GOAL), 0, "Counted goal before confirmed human")
experiment_user.confirm_human()
self.assertEqual(self.experiment_counter.goal_count(self.experiment, TEST_ALTERNATIVE, TEST_GOAL), 1, "Did not count goal after confirm human")
开发者ID:Dylgar,项目名称:django-experiments,代码行数:8,代码来源:test_webuser.py
示例11: set_alternative_view
def set_alternative_view(self, request):
"""
Allows the admin user to change their assigned alternative
"""
if not request.user.has_perm('experiments.change_experiment'):
return HttpResponseForbidden()
experiment_name = request.POST.get("experiment")
alternative_name = request.POST.get("alternative")
if not (experiment_name and alternative_name):
return HttpResponseBadRequest()
participant(request).set_alternative(experiment_name, alternative_name)
return JsonResponse({
'success': True,
'alternative': participant(request).get_alternative(experiment_name)
})
开发者ID:DjangoBD,项目名称:django-experiments,代码行数:17,代码来源:admin.py
示例12: test_visit_increases_goal
def test_visit_increases_goal(self):
experiment_user = participant(self.request)
self.confirm_human(experiment_user)
experiment_user.set_alternative(EXPERIMENT_NAME, TEST_ALTERNATIVE)
experiment_user.visit()
self.assertEqual(self.experiment.goal_distribution(TEST_ALTERNATIVE, VISIT_COUNT_GOAL), {1: 1})
开发者ID:ajvb,项目名称:django-experiments,代码行数:8,代码来源:webuser.py
示例13: test_set_alternative
def test_set_alternative(self):
experiment = Experiment.objects.create(name='test_experiment', state=ENABLED_STATE)
user = User.objects.create_superuser(username='user', email='[email protected]', password='pass')
self.client.login(username='user', password='pass')
participant(user=user).enroll('test_experiment', alternatives=['other1', 'other2'])
for alternative in ('other2', 'control', 'other1'):
response = self.client.post(reverse('admin:experiment_admin_set_alternative'), {
'experiment': experiment.name,
'alternative': alternative,
})
self.assertDictEqual(json.loads(response.content.decode()), {
'success': True,
'alternative': alternative,
})
self.assertEqual(participant(user=user).get_alternative('test_experiment'), alternative)
开发者ID:bjarnoldus,项目名称:django-experiments,代码行数:17,代码来源:test_admin.py
示例14: render
def render(self, context):
# Get User object
if self.user_variable:
auth_user = self.user_variable.resolve(context)
user = participant(user=auth_user)
gargoyle_key = auth_user
else:
request = context.get('request', None)
user = participant(request)
gargoyle_key = request
# Should we render?
if user.is_enrolled(self.experiment_name, self.alternative, gargoyle_key):
response = self.node_list.render(context)
else:
response = ""
return response
开发者ID:johnmarkschofield,项目名称:django-experiments,代码行数:18,代码来源:experiments.py
示例15: test_visit_twice_increases_once
def test_visit_twice_increases_once(self):
experiment_user = participant(self.request)
experiment_user.confirm_human()
experiment_user.set_alternative(EXPERIMENT_NAME, TEST_ALTERNATIVE)
experiment_user.visit()
experiment_user.visit()
self.assertEqual(self.experiment_counter.goal_distribution(self.experiment, TEST_ALTERNATIVE, VISIT_NOT_PRESENT_COUNT_GOAL), {1: 1}, "Visit was not correctly counted")
self.assertEqual(self.experiment_counter.goal_distribution(self.experiment, TEST_ALTERNATIVE, VISIT_PRESENT_COUNT_GOAL), {}, "Present Visit was not correctly counted")
开发者ID:Dylgar,项目名称:django-experiments,代码行数:10,代码来源:test_webuser.py
示例16: process_response
def process_response(self, request, response):
# Don't track, failed pages, ajax requests, logged out users or widget impressions.
# We detect widgets by relying on the fact that they are flagged as being embedable
if response.status_code != 200 or request.is_ajax() or getattr(response, 'xframe_options_exempt', False):
return response
experiment_user = participant(request)
experiment_user.visit()
return response
开发者ID:mixcloud,项目名称:django-experiments,代码行数:10,代码来源:middleware.py
示例17: test_second_force_enroll_does_not_change_alternative
def test_second_force_enroll_does_not_change_alternative(self):
alternatives = ['control', 'alternative1', 'alternative2']
experiment_user = participant(self.request)
experiment_user.enroll(EXPERIMENT_NAME, alternatives, force_alternative='alternative1')
alternative = experiment_user.get_alternative(EXPERIMENT_NAME)
self.assertIsNotNone(alternative)
other_alternative = random.choice(list(set(alternatives) - set(alternative)))
experiment_user.enroll(EXPERIMENT_NAME, alternatives, force_alternative=other_alternative)
self.assertEqual(alternative, experiment_user.get_alternative(EXPERIMENT_NAME))
开发者ID:Dylgar,项目名称:django-experiments,代码行数:10,代码来源:test_webuser.py
示例18: test_can_record_goal_multiple_times
def test_can_record_goal_multiple_times(self):
experiment_user = participant(self.request)
experiment_user.confirm_human()
experiment_user.set_alternative(EXPERIMENT_NAME, TEST_ALTERNATIVE)
experiment_user.goal(TEST_GOAL)
experiment_user.goal(TEST_GOAL)
experiment_user.goal(TEST_GOAL)
self.assertEqual(self.experiment_counter.goal_count(self.experiment, TEST_ALTERNATIVE, TEST_GOAL), 1, "Did not increment goal count correctly")
self.assertEqual(self.experiment_counter.goal_distribution(self.experiment, TEST_ALTERNATIVE, TEST_GOAL), {3: 1}, "Incorrect goal count distribution")
开发者ID:Dylgar,项目名称:django-experiments,代码行数:10,代码来源:test_webuser.py
示例19: render
def render(self, context):
experiment = experiment_manager.get_experiment(self.experiment_name)
if experiment:
experiment.ensure_alternative_exists(self.alternative, self.weight)
# Get User object
if self.user_variable:
auth_user = self.user_variable.resolve(context)
user = participant(user=auth_user)
else:
request = context.get("request", None)
user = participant(request)
# Should we render?
if user.is_enrolled(self.experiment_name, self.alternative):
response = self.node_list.render(context)
else:
response = ""
return response
开发者ID:matt-fournier,项目名称:django-experiments,代码行数:20,代码来源:experiments.py
示例20: test_visit_increases_goal
def test_visit_increases_goal(self):
thetime = timezone.now()
with patch('experiments.utils.now', return_value=thetime):
experiment_user = participant(self.request)
experiment_user.confirm_human()
experiment_user.set_alternative(EXPERIMENT_NAME, TEST_ALTERNATIVE)
experiment_user.visit()
self.assertEqual(self.experiment_counter.goal_distribution(self.experiment, TEST_ALTERNATIVE, VISIT_NOT_PRESENT_COUNT_GOAL), {1: 1}, "Not Present Visit was not correctly counted")
self.assertEqual(self.experiment_counter.goal_distribution(self.experiment, TEST_ALTERNATIVE, VISIT_PRESENT_COUNT_GOAL), {}, "Present Visit was not correctly counted")
with patch('experiments.utils.now', return_value=thetime + timedelta(hours=7)):
experiment_user.visit()
self.assertEqual(self.experiment_counter.goal_distribution(self.experiment, TEST_ALTERNATIVE, VISIT_NOT_PRESENT_COUNT_GOAL), {2: 1}, "No Present Visit was not correctly counted")
self.assertEqual(self.experiment_counter.goal_distribution(self.experiment, TEST_ALTERNATIVE, VISIT_PRESENT_COUNT_GOAL), {1: 1}, "Present Visit was not correctly counted")
开发者ID:Dylgar,项目名称:django-experiments,代码行数:15,代码来源:test_webuser.py
注:本文中的experiments.utils.participant函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论