示例#1
0
 def setUp(self):
     self.experiment = Experiment.objects.create(name='test_experiment1', state=ENABLED_STATE)
     self.experiment_counter = ExperimentCounter()
     self.experiment_user = participant(session=DatabaseSession())
     self.alternative = self.experiment_user.enroll(self.experiment.name, ['alternative'])
     self.experiment_user.goal('my_goal')
     self.redis = get_redis_client()
示例#2
0
 def setUp(self):
     self.experiment = Experiment(name='backgroundcolor',
                                  state=ENABLED_STATE)
     self.experiment.save()
     self.request = request_factory.get('/',
                                        HTTP_USER_AGENT='GoogleBot/2.1')
     self.experiment_counter = ExperimentCounter()
示例#3
0
    def delete(self, request):
        if not request.user.has_perm('experiments.delete_experiment'):
            raise ExperimentException("You don't have permission to do that!")
        experiment_counter = ExperimentCounter()
        experiment = Experiment.objects.get(name=request.POST.get("name"))

        experiment.enrollment_set.all().delete()
        experiment_counter.delete(experiment)
        experiment.delete()
        return {'successful': True}
    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='******')
        self.user.is_confirmed_human = True

        request_factory = RequestFactory()
        self.request = request_factory.get('/')
        self.request.session = DatabaseSession()
        participant(self.request).confirm_human()
示例#5
0
    def test_reset_all(self):
        experiment = Experiment.objects.create(name='reset_test')
        other_experiment = Experiment.objects.create(name='reset_test_other')
        experiment_counter = ExperimentCounter()

        for exp in [experiment, other_experiment]:
            experiment_counter.increment_participant_count(exp, 'alt', 'fred')
            experiment_counter.increment_participant_count(exp, 'alt', 'fred')
            experiment_counter.increment_participant_count(exp, 'alt', 'fred')
            experiment_counter.increment_goal_count(exp, 'alt', 'goal1',
                                                    'fred')
            experiment_counter.increment_goal_count(exp, 'alt', 'goal2',
                                                    'fred')
            experiment_counter.increment_participant_count(
                exp, 'control', 'barney')
            experiment_counter.increment_participant_count(
                exp, 'control', 'wilma')
            experiment_counter.increment_participant_count(
                exp, 'control', 'betty')
            experiment_counter.increment_goal_count(exp, 'control', 'goal1',
                                                    'betty')

        self.counters.reset_prefix(experiment.name)
        self.assertEqual(
            experiment_counter.participant_count(experiment, 'alt'), 0)
        self.assertEqual(
            experiment_counter.participant_count(experiment, 'control'), 0)
        self.assertEqual(
            experiment_counter.goal_count(experiment, 'control', 'goal1'), 0)

        self.assertEqual(
            experiment_counter.participant_count(other_experiment, 'alt'), 1)
        self.assertEqual(
            experiment_counter.participant_count(other_experiment, 'control'),
            3)
        self.assertEqual(
            experiment_counter.goal_count(other_experiment, 'control',
                                          'goal1'), 1)
示例#6
0
def get_result_context(request, experiment):
    experiment_counter = ExperimentCounter()

    try:
        chi2_goals = experiment.relevant_chi2_goals.replace(" ", "").split(",")
    except AttributeError:
        chi2_goals = ['']
    try:
        mwu_goals = experiment.relevant_mwu_goals.replace(" ", "").split(",")
    except AttributeError:
        mwu_goals = ['']
    relevant_goals = set(chi2_goals + mwu_goals)

    alternatives = {}
    for alternative_name in experiment.alternatives.keys():
        alternatives[alternative_name] = experiment_counter.participant_count(
            experiment, alternative_name)
    alternatives = sorted(alternatives.items())

    control_participants = experiment_counter.participant_count(
        experiment, conf.CONTROL_GROUP)

    results = {}

    for goal in conf.ALL_GOALS:
        show_mwu = goal in mwu_goals

        alternatives_conversions = {}
        control_conversions = experiment_counter.goal_count(
            experiment, conf.CONTROL_GROUP, goal)
        control_conversion_rate = rate(control_conversions,
                                       control_participants)

        if show_mwu:
            mwu_histogram = {}
            control_conversion_distribution = fixup_distribution(
                experiment_counter.goal_distribution(experiment,
                                                     conf.CONTROL_GROUP, goal),
                control_participants)
            control_average_goal_actions = average_actions(
                control_conversion_distribution)
            mwu_histogram['control'] = control_conversion_distribution
        else:
            control_average_goal_actions = None
        for alternative_name in experiment.alternatives.keys():
            if not alternative_name == conf.CONTROL_GROUP:
                alternative_conversions = experiment_counter.goal_count(
                    experiment, alternative_name, goal)
                alternative_participants = experiment_counter.participant_count(
                    experiment, alternative_name)
                alternative_conversion_rate = rate(alternative_conversions,
                                                   alternative_participants)
                alternative_confidence = chi_squared_confidence(
                    alternative_participants, alternative_conversions,
                    control_participants, control_conversions)
                if show_mwu:
                    alternative_conversion_distribution = fixup_distribution(
                        experiment_counter.goal_distribution(
                            experiment, alternative_name, goal),
                        alternative_participants)
                    alternative_average_goal_actions = average_actions(
                        alternative_conversion_distribution)
                    alternative_distribution_confidence = mann_whitney_confidence(
                        alternative_conversion_distribution,
                        control_conversion_distribution)
                    mwu_histogram[
                        alternative_name] = alternative_conversion_distribution
                else:
                    alternative_average_goal_actions = None
                    alternative_distribution_confidence = None
                alternative = {
                    'conversions':
                    alternative_conversions,
                    'conversion_rate':
                    alternative_conversion_rate,
                    'improvement':
                    improvement(alternative_conversion_rate,
                                control_conversion_rate),
                    'confidence':
                    alternative_confidence,
                    'average_goal_actions':
                    alternative_average_goal_actions,
                    'mann_whitney_confidence':
                    alternative_distribution_confidence,
                }
                alternatives_conversions[alternative_name] = alternative

        control = {
            'conversions': control_conversions,
            'conversion_rate': control_conversion_rate,
            'average_goal_actions': control_average_goal_actions,
        }

        results[goal] = {
            "control":
            control,
            "alternatives":
            sorted(alternatives_conversions.items()),
            "relevant":
            goal in relevant_goals or relevant_goals == {''},
            "mwu":
            goal in mwu_goals,
            "mwu_histogram":
            conversion_distributions_to_graph_table(mwu_histogram)
            if show_mwu else None
        }

    return {
        'experiment': experiment.to_dict(),
        'alternatives': alternatives,
        'control_participants': control_participants,
        'results': results,
        'column_count': len(alternatives_conversions) * 3 +
        2,  # Horrible coupling with template design
        'user_alternative':
        participant(request).get_alternative(experiment.name),
    }
示例#7
0
 def __init__(self):
     self.experiment_counter = ExperimentCounter()
 def __init__(self, *args, **kwargs):
     super(WebUserIncorporateTestCase, self).__init__(*args, **kwargs)
     self.experiment_counter = ExperimentCounter()
示例#9
0
 def __init__(self):
     self.experiment_counter = ExperimentCounter()
     self.experiments_exposure = []
示例#10
0
 def setUp(self):
     self.experiment = Experiment(name=EXPERIMENT_NAME, state=ENABLED_STATE)
     self.experiment.save()
     self.request = request_factory.get('/')
     self.request.session = DatabaseSession()
     self.experiment_counter = ExperimentCounter()
示例#11
0
 def setUp(self):
     self.experiment = Experiment.objects.create(name='test_experiment1',
                                                 state=ENABLED_STATE)
     self.experiment_counter = ExperimentCounter()
示例#12
0
 def setUp(self):
     self.experiment = Experiment(name='backgroundcolor',
                                  state=ENABLED_STATE)
     self.experiment.save()
     self.experiment_counter = ExperimentCounter()