'Determine if there\'s an active variant of the specified experiment
for the current user.
Sends a bucketing event.'

def _is_experiment_enabled(self, experiment, user=None):

    if (not experiment.get('enabled', True)):
        return False
    variant = None
    if FeatureState.is_user_experiment(experiment):
        variant = self._get_user_experiment_variant(experiment, user)
    elif FeatureState.is_page_experiment(experiment):
        (content_id, _) = FeatureState.get_content_id()
        variant = self._get_page_experiment_variant(experiment)
    if (not c.have_sent_bucketing_event):
        c.have_sent_bucketing_event = set()
    if ((variant is not None) and self.world.valid_experiment_request()):
        if FeatureState.is_user_experiment(experiment):
            loid = self.world.current_loid()
            if self.world.is_user_loggedin(user):
                bucketing_id = user._id
            else:
                bucketing_id = loid
            key = ('user', self.name, bucketing_id)
            if (g.running_as_script or (key not in c.have_sent_bucketing_event)):
                g.events.bucketing_event(experiment_id=experiment.get('experiment_id'), experiment_name=self.name, variant=variant, user=user, loid=self.world.current_loid_obj())
                c.have_sent_bucketing_event.add(key)
        else:
            key = ('page', self.name, content_id)
            if (g.running_as_script or (key not in c.have_sent_bucketing_event)):
                g.events.page_bucketing_event(experiment_id=experiment.get('experiment_id'), experiment_name=self.name, variant=variant, content_id=content_id, request=request, context=c)
                c.have_sent_bucketing_event.add(key)
    return self._is_variant_enabled(variant)
