def apply(self, context=None):
        """
        If constraints are satisfied, return a percentage rollout on provisioned.

        :return:
        """
        percentage = int(self.parameters['rollout'])
        activation_group = self.parameters['groupId']
        stickiness = self.parameters['stickiness']

        if stickiness == 'default':
            if 'userId' in context.keys():
                calculated_percentage = normalized_hash(
                    context['userId'], activation_group)
            elif 'sessionId' in context.keys():
                calculated_percentage = normalized_hash(
                    context['sessionId'], activation_group)
            else:
                calculated_percentage = self.random_hash()
        elif stickiness in ['userId', 'sessionId']:
            calculated_percentage = normalized_hash(context[stickiness],
                                                    activation_group)
        else:
            # This also handles the stickiness == random scenario.
            calculated_percentage = self.random_hash()

        return percentage > 0 and calculated_percentage <= percentage
Пример #2
0
    def get_variant(self, context):
        """
        Determines what variation a user is in.

        :param context:
        :return:
        """
        fallback_variant = copy.deepcopy(DISABLED_VARIATION)

        if self.variants:
            override_variant = self._apply_overrides(context)
            if override_variant:
                return self._format_variation(override_variant)

            total_weight = sum([x['weight'] for x in self.variants])
            if total_weight <= 0:
                return fallback_variant

            target = utils.normalized_hash(self._get_seed(context),
                                           self.feature_name, total_weight)
            counter = 0
            for variation in self.variants:
                counter += variation['weight']

                if counter >= target:
                    return self._format_variation(variation)

        # Catch all return.
        return fallback_variant
Пример #3
0
    def get_variant(self, context: dict) -> dict:
        """
        Determines what variation a user is in.

        :param context:
        :return:
        """
        fallback_variant = copy.deepcopy(DISABLED_VARIATION)

        if self.variants:
            override_variant = self._apply_overrides(context)
            if override_variant:
                return self._format_variation(override_variant)

            total_weight = sum(x['weight'] for x in self.variants)
            if total_weight <= 0:
                return fallback_variant

            stickiness_selector = self.variants[0]['stickiness'] if 'stickiness' in self.variants[0].keys() else "default"

            target = utils.normalized_hash(self._get_seed(context, stickiness_selector), self.feature_name, total_weight)
            counter = 0
            for variation in self.variants:
                counter += variation['weight']

                if counter >= target:
                    return self._format_variation(variation)

        # Catch all return.
        return fallback_variant
    def apply(self, context: dict = None) -> bool:
        """
        Returns true if userId is a member of id list.

        :return:
        """
        percentage = int(self.parameters["percentage"])
        activation_group = self.parameters["groupId"]

        return percentage > 0 and normalized_hash(context["sessionId"], activation_group) <= percentage
Пример #5
0
    def __call__(self, context: dict = None) -> bool:
        """
        Returns true if userId is a member of id list.

        :return:
        """
        percentage = self.parameters["percentage"]
        activation_group = self.parameters["groupId"]

        return percentage < normalized_hash(context["sessionId"], activation_group)
Пример #6
0
    def __call__(self, context=None):
        """
        Returns true if userId is a member of id list.

        :return:
        """
        percentage = int(self.parameters["percentage"])
        activation_group = self.parameters["groupId"]

        return percentage > 0 and normalized_hash(
            context["userId"], activation_group) <= percentage
Пример #7
0
    def apply(self, context: dict = None) -> bool:
        """
        If constraints are satisfied, return a percentage rollout on provisioned.

        :return:
        """
        percentage = int(self.parameters['rollout'])
        activation_group = self.parameters['groupId']
        stickiness = self.parameters['stickiness']  if "stickiness" in self.parameters else "default"

        if stickiness == 'default':
            if 'userId' in context.keys():
                calculated_percentage = normalized_hash(context['userId'], activation_group)
            elif 'sessionId' in context.keys():
                calculated_percentage = normalized_hash(context['sessionId'], activation_group)
            else:
                calculated_percentage = self.random_hash()
        elif stickiness == "random":
            calculated_percentage = self.random_hash()
        else:
            calculated_percentage = normalized_hash(context[stickiness], activation_group)

        return percentage > 0 and calculated_percentage <= percentage