コード例 #1
0
 def _init_email_provider_type(self) -> str:
     """
     randomly select a provider type
     out of work, public and custom
     """
     weights = self.email_config.get("email_provider_type_weights",
                                     DEFAULT_EMAIL_PROVIDER_TYPE_WEIGHTS)
     return random_choice_weight_dict(weights)
コード例 #2
0
 def _init_address_type(self) -> np.str_:
     config = self.config
     cfg_address_type_weights = None
     if config:
         address_config = config.get("address", {})
         cfg_address_type_weights = address_config.get(
             "address_type_weights")
     if cfg_address_type_weights:
         weights = cfg_address_type_weights
     else:
         weights = ADDRESS_TYPE_WEIGHTS
     return random_choice_weight_dict(weights)
コード例 #3
0
    def _init_addresses_configuration(self) -> str:
        """
        Randomly selects an address configuration type out of, Customer's
        default address, a new address for the customer and a random address

        Returns:
            str: the key associated to the selected address config
        """
        order_config = self.config.get("orders", {}) if self.config else {}
        weights = order_config.get("address_configuration_weights",
                                   DEFAULT_ADDRESS_CONFIGURATION_WEIGHTS)
        return random_choice_weight_dict(weights)
コード例 #4
0
 def _init_promotion_value_type(self, value_type: str = None) -> str:
     """
     Returns:
         str: key promotion value type
     """
     if value_type and isinstance(value_type, str):
         return value_type
     if value_type:
         raise TypeError("value_type kwarg should be an instance of str")
     weights = self.promo_config.get(
         "promotion_value_type_weights", DEFAULT_PROMOTION_VALUE_TYPE_WEIGHTS
     )
     return random_choice_weight_dict(weights)
コード例 #5
0
    def _init_promotion_type(self, type_: str = None) -> str:
        """
        Assign or randomly generate a promotion type based on a weghted dict

        Returns:
            str: The key of the dictionary
        """
        if type_ and isinstance(type_, str):
            if type_ in {"coupon", "discount", "no_promotion"}:
                return type_
            raise ValueError(
                "type should be either coupon, discount or no_promotion"
            )
        if type_:
            raise TypeError("type kwarg should be an instance of str")
        weights = self.promo_config.get(
            "promotion_type_weights", DEFAULT_PROMOTION_TYPE_WEIGHTS
        )
        return random_choice_weight_dict(weights)
コード例 #6
0
    def _init_rand_int(self) -> int:
        """
        Assign a semi random integer

        Returns:
            int: Integer based on either the date of birth
            Or a random number, this number is to be used to
            fill the different email formats
        """
        date_of_birth = self.kwargs.get("date_of_birth")
        random_int = np.random.randint(low=0, high=100)
        if date_of_birth:

            random_int_val = {
                "year_of_birth": int(str(date_of_birth.year)[2:]),
                "random_int": random_int,
            }

            weights = self.email_config.get(
                "email_random_int_weights", DEFAULT_INTEGERS_IN_EMAILS_WEIGHTS)

            random_choice = random_choice_weight_dict(weights)
            return random_int_val.get(random_choice)
        return random_int
コード例 #7
0
 def _init_public_domain(self) -> str:
     weights = self.email_config.get("email_public_domain_weights",
                                     DEFAULT_PUBLIC_DOMAIN_WEIGHTS)
     return random_choice_weight_dict(weights)