def show_alternative(self, experiment_name, experiment_user, alternative, experiment_manager): """ does the real work """ try: experiment = experiment_manager[experiment_name] # use cache where possible except KeyError: return alternative == CONTROL_GROUP if experiment.state == CONTROL_STATE: return alternative == CONTROL_GROUP if experiment.state == GARGOYLE_STATE: if not gargoyle.is_active(experiment.switch_key, experiment_user.request): return alternative == CONTROL_GROUP if experiment.state != ENABLED_STATE and experiment.state != GARGOYLE_STATE: raise Exception("Invalid experiment state %s!" % experiment.state) # Add new alternatives to experiment model if alternative not in experiment.alternatives: experiment.alternatives[alternative] = {} experiment.alternatives[alternative]['enabled'] = True experiment.save() # Lookup User alternative assigned_alternative = experiment_user.get_enrollment(experiment) # No alternative so assign one if assigned_alternative is None: assigned_alternative = random.choice(experiment.alternatives.keys()) experiment_user.set_enrollment(experiment, assigned_alternative) return alternative == assigned_alternative
def is_accepting_new_users(self, request): if self.state == CONTROL_STATE: return False elif self.state == ENABLED_STATE: return True elif self.state == GARGOYLE_STATE: return gargoyle.is_active(self.switch_key, request) elif self.state == TRACK_STATE: return False else: raise Exception("Invalid experiment state %s!" % self.state)
def should_increment(self, experiment, goals, goal_name): # Increments goal if enabled+gargoyle switch conditions met or just enabled # Goal uniquely incremented for all enrollments at once if experiment.state == CONTROL_STATE: # Control state, experiment not running return False elif experiment.state == ENABLED_STATE and experiment.switch_key: # Gargoyle state only increment actives. if gargoyle.is_active(experiment.switch_key, self.request): if goal_name not in goals: # Check if already recorded for this enrollment return True if goal_name not in goals: # Check if already recorded for this enrollment return True return False
def show_alternative(self, experiment_name, experiment_user, alternative, experiment_manager): """ does the real work """ try: experiment = experiment_manager[ experiment_name] # use cache where possible except KeyError: return alternative == CONTROL_GROUP if experiment.state == CONTROL_STATE: return alternative == CONTROL_GROUP if experiment.state == GARGOYLE_STATE: if not gargoyle.is_active(experiment.switch_key, experiment_user.request): return alternative == CONTROL_GROUP if experiment.state != ENABLED_STATE and experiment.state != GARGOYLE_STATE: raise Exception("Invalid experiment state %s!" % experiment.state) # Add new alternatives to experiment model if alternative not in experiment.alternatives: experiment.alternatives[alternative] = {} experiment.alternatives[alternative]['enabled'] = True experiment.save() # Lookup User alternative assigned_alternative = experiment_user.get_enrollment(experiment) # No alternative so assign one if assigned_alternative is None: assigned_alternative = random.choice( experiment.alternatives.keys()) experiment_user.set_enrollment(experiment, assigned_alternative) return alternative == assigned_alternative