
    soj%                         d dl Z dededefdZdedefdZdededefd	Zd
eeef         defdZ	ddededefdZ
ddededefdZdededefdZdededefdZdee         defdZddededeez  fdZdS )    Ntotal
percentagereturnc                     | |z  dz  S )z
    Gets a value from a percentage
    :param total: The value to get the percentage from
    :param percentage: The percentage to get the value from
    :return: The value from the percentage
    d    )r   r   s     /app/src/utils/math_utils.pyget_value_from_percentager
      s     J#%%    c                 :    | dz  t          j        dd          k    S )z
    Gets a random win based on the percentage
    :param percentage: The percentage to get a win for
    :return: True if the percentage is greater than a random number, False otherwise
    i'  r   i@B randomrandint)r   s    r	   get_random_winr      s      7!;!;;;r   	min_value	max_valuec                 ,    t          j        | |          S )z
    Gets a random int between the min and max values
    :param min_value: The minimum value
    :param max_value: The maximum value
    :return: The random int
    r   )r   r   s     r	   get_random_intr      s     >)Y///r   probability_dictc                    t          |                                           }t          d|          }d}|                                 D ]\  }}||z  }||k    r|c S t	          |                                           d         S )a  
    This function returns a random key from a dictionary based on the probability associated with
    each key.
    The input dictionary, 'probability_dict', should have keys of any type and values of type
    float, representing the probability associated with each key.

    :param probability_dict: The dictionary containing keys and their associated probabilities
    :return: A random key from the dictionary based on the associated probabilities
       r   )sumvaluesr   itemslistkeys)r   total_probabilityrandom_numberaccumulated_probabilitykeyprobabilitys         r	   #get_random_key_based_on_probabilityr#   #   s     ,335566 #1&788M   -2244  [;. #]22JJJ 3  %%''((,,r   Tvaluec                 \    	 | |z  dz  }|st          |          S |S # t          $ r Y dS w xY w)  
    Gets a percentage from a value
    :param value: The value to get the percentage from
    :param total: The total value
    :param add_decimal: True if the percentage should have a decimals, False otherwise
    :return: The percentage from the value
    r   r   )intZeroDivisionError)r$   r   add_decimalresults       r	   get_percentage_from_valuer+   D   sP    %-3& 	v;;   qqs     
++c                 *    t          | ||          dz
  S )r&   r   )r+   )r$   r   r)   s      r	   "get_interest_percentage_from_valuer-   W   s     %UE;??#EEr   c                 <    ||dk    r| S | t          | |          z   S )z
    Adds a percentage to a value
    :param value: The value to add the percentage to
    :param percentage: The percentage to add to the value
    :return: The value with the percentage added
    Nr   r
   r$   r   s     r	   add_percentage_to_valuer1   c   s-     Z1__,UJ????r   c                 (    | t          | |          z
  S )z
    Subtracts a percentage from a value
    :param value: The value to subtract the percentage from
    :param percentage: The percentage to subtract from the value
    :return: The value with the percentage subtracted
    r/   r0   s     r	   subtract_percentage_from_valuer3   q   s     ,UJ????r   percentagesc                 <    d}d}| D ]}||z  dz  }||z  }||z  }|S )an  
    Calculate the cumulative sum of percentages.
    This function takes a list of percentages and calculates the cumulative sum by iteratively
    adding each percentage to the result and adjusting the remaining percentage for subsequent
    iterations.
    :param percentages: A list of percentages to sum.
    :return: The cumulative sum of the percentages.
    r   r   r   )r4   r*   remaining_percentager   "percentage_of_remaining_percentages        r	   get_cumulative_percentage_sumr8   |   sP     F! C C
.BZ.OSV-V*44 BBMr      decimalsc                 R    | dz  dk    rt          |           S t          | |          S )z
    Convert a percentage to an integer value or a float value with specified decimals.

    :param percentage: The percentage to convert.
    :param decimals: Number of decimal places (default is 2).
    :return: An integer or float value.
    r   r   )r'   round)r   r:   s     r	   format_percentage_valuer=      s/     A~:X&&&r   )T)r9   )r   floatr
   boolr   r'   r   dictanyr#   r+   r-   r1   r3   r   r8   r=   r   r   r	   <module>rB      s   &U & &% & & & &<u < < < < <0c 0c 0c 0 0 0 0-$sEz:J -s - - - -B U 5 u    &	F 	Fe 	FE 	FX] 	F 	F 	F 	F@5 @e @ @ @ @ @@% @U @u @ @ @ @tE{ u    *' ' ' 'S5[ ' ' ' ' ' 'r   