o
    tBh:?                     @   sB  d Z ddlZddlZddlZddlmZmZmZm	Z	 dZ
edZdd Zd	d
 Zd=ddZdd Zd=ddZd>ddZd=ddZdd Zd>ddZefddZdefddZd=ddZefdd Zdefd!d"Zd#d$ Zd%d& Zd'd( Zd>d)d*Zd?d+d,Zd-d. Z d/d0 Z!d1d2 Z"d3d4 Z#d5d6 Z$d=d7d8Z%d9d: Z&d;d< Z'dS )@zD
Numerical/mathematical related functions.

.. versionadded:: 2.1.0
    N   )UNSETiteratoriterator_with_defaultiteriteratee)addceilclampdividefloormax_max_bymeanmean_bymedianmin_min_bymoving_meanmultiplypowerround_scaleslopestd_deviationsum_sum_bysubtract	transposevariancezscoreinfc                 C   s   | | S )a  
    Adds two numbers.

    Args:
        a (number): First number to add.
        b (number): Second number to add.

    Returns:
        number

    Example:

        >>> add(10, 5)
        15

    .. versionadded:: 2.1.0

    .. versionchanged:: 3.3.0
        Support adding two numbers when passed as positional arguments.

    .. versionchanged:: 4.0.0
        Only support two argument addition.
     )abr!   r!   g/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/pydash/numerical.pyr   /      r   c                 C      t | S )a  
    Sum each element in `collection`.

    Args:
        collection (list|dict|number): Collection to process or first number to add.

    Returns:
        number: Result of summation.

    Example:

        >>> sum_([1, 2, 3, 4])
        10

    .. versionadded:: 2.1.0

    .. versionchanged:: 3.3.0
        Support adding two numbers when passed as positional arguments.

    .. versionchanged:: 4.0.0
        Move iteratee support to :func:`sum_by`. Move two argument addition to
        :func:`add`.
    )r   
collectionr!   r!   r$   r   J   r%   r   c                 C   s   t dd t| |D S )a  
    Sum each element in `collection`. If iteratee is passed, each element of `collection` is passed
    through a iteratee before the summation is computed.

    Args:
        collection (list|dict|number): Collection to process or first number to add.
        iteratee (mixed|number, optional): Iteratee applied per iteration or second number to add.

    Returns:
        number: Result of summation.

    Example:

        >>> sum_by([1, 2, 3, 4], lambda x: x ** 2)
        30

    .. versionadded:: 4.0.0
    c                 s       | ]}|d  V  qdS r   Nr!   ).0resultr!   r!   r$   	<genexpr>x       zsum_by.<locals>.<genexpr>)sumr   r(   iterateer!   r!   r$   r   e   s   r   c                 C   r&   )a  
    Calculate arithmetic mean of each element in `collection`.

    Args:
        collection (list|dict): Collection to process.

    Returns:
        float: Result of mean.

    Example:

        >>> mean([1, 2, 3, 4])
        2.5

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0

        - Removed ``average`` and ``avg`` aliases.
        - Moved iteratee functionality to :func:`mean_by`.
    )r   r'   r!   r!   r$   r   {   s   r   c                 C   s   t | |t|  S )a  
    Calculate arithmetic mean of each element in `collection`. If iteratee is passed, each element
    of `collection` is passed through a iteratee before the mean is computed.

    Args:
        collection (list|dict): Collection to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        float: Result of mean.

    Example:

        >>> mean_by([1, 2, 3, 4], lambda x: x ** 2)
        7.5

    .. versionadded:: 4.0.0
    )r   lenr0   r!   r!   r$   r      s   r   c                 C      t tj| |S )a  
    Round number up to precision.

    Args:
        x (number): Number to round up.
        precision (int, optional): Rounding precision. Defaults to ``0``.

    Returns:
        int: Number rounded up.

    Example:

        >>> ceil(3.275) == 4.0
        True
        >>> ceil(3.215, 1) == 3.3
        True
        >>> ceil(6.004, 2) == 6.01
        True

    .. versionadded:: 3.3.0
    )roundermathr   x	precisionr!   r!   r$   r         r   c                 C   s0   |du r|}| }| |k r|} | S | |kr|} | S )a  
    Clamps number within the inclusive lower and upper bounds.

    Args:
        x (number): Number to clamp.
        lower (number, optional): Lower bound.
        upper (number): Upper bound

    Returns:
        number

    Example:

        >>> clamp(-10, -5, 5)
        -5
        >>> clamp(10, -5, 5)
        5
        >>> clamp(10, 5)
        5
        >>> clamp(-10, 5)
        -10

    .. versionadded:: 4.0.0
    Nr!   )r7   lowerupperr!   r!   r$   r	      s   r	   c                 C      t | |tjdS )a  
    Divide two numbers.

    Args:
        dividend (int/float): The first number in a division.
        divisor (int/float): The second number in a division.

    Returns:
        int/float: Returns the quotient.

    Example:

        >>> divide(20, 5)
        4.0
        >>> divide(1.5, 3)
        0.5
        >>> divide(None, None)
        1.0
        >>> divide(5, None)
        5.0

    .. versionadded:: 4.0.0
    r   )call_math_operatoroperatortruediv)dividenddivisorr!   r!   r$   r
         r
   c                 C   r3   )a  
    Round number down to precision.

    Args:
        x (number): Number to round down.
        precision (int, optional): Rounding precision. Defaults to ``0``.

    Returns:
        int: Number rounded down.

    Example:

        >>> floor(3.75) == 3.0
        True
        >>> floor(3.215, 1) == 3.2
        True
        >>> floor(0.046, 2) == 0.04
        True

    .. versionadded:: 3.3.0
    )r4   r5   r   r6   r!   r!   r$   r     r9   r   c                 C      t | |dS )a  
    Retrieves the maximum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Maximum value.

    Example:

        >>> max_([1, 2, 3, 4])
        4
        >>> max_([], default=-1)
        -1

    .. versionadded:: 1.0.0

    .. versionchanged:: 4.0.0
        Moved iteratee iteratee support to :func:`max_by`.
    default)r   r(   rE   r!   r!   r$   r        r   c                 C   *   t | tr	|  } tt| |t|dS )a  
    Retrieves the maximum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        iteratee (mixed, optional): Iteratee applied per iteration.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Maximum value.

    Example:

        >>> max_by([1.0, 1.5, 1.8], math.floor)
        1.0
        >>> max_by([{'a': 1}, {'a': 2}, {'a': 3}], 'a')
        {'a': 3}
        >>> max_by([], default=-1)
        -1

    .. versionadded:: 4.0.0
    key)
isinstancedictvaluesmaxr   pydr1   r(   r1   rE   r!   r!   r$   r   6  s   
r   c                 C   sz   t | }|d d }tdd t| |D } t|r%| t|d  }|S t|d }t|d }| | | |  d }|S )a  
    Calculate median of each element in `collection`. If iteratee is passed, each element of
    `collection` is passed through a iteratee before the median is computed.

    Args:
        collection (list|dict): Collection to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        float: Result of median.

    Example:

        >>> median([1, 2, 3, 4, 5])
        3
        >>> median([1, 2, 3, 4])
        2.5

    .. versionadded:: 2.1.0
    r      c                 s   r)   r*   r!   )r+   retr!   r!   r$   r-   j  r.   zmedian.<locals>.<genexpr>g      ?g      ?)r2   sortedr   rO   is_oddint)r(   r1   lengthmiddler,   leftrightr!   r!   r$   r   S  s   
r   c                 C   rC   )a  
    Retrieves the minimum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Minimum value.

    Example:

        >>> min_([1, 2, 3, 4])
        1
        >>> min_([], default=100)
        100

    .. versionadded:: 1.0.0

    .. versionchanged:: 4.0.0
        Moved iteratee iteratee support to :func:`min_by`.
    rD   )r   rF   r!   r!   r$   r   v  rG   r   c                 C   rH   )a  
    Retrieves the minimum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        iteratee (mixed, optional): Iteratee applied per iteration.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Minimum value.

    Example:

        >>> min_by([1.8, 1.5, 1.0], math.floor)
        1.8
        >>> min_by([{'a': 1}, {'a': 2}, {'a': 3}], 'a')
        {'a': 1}
        >>> min_by([], default=100)
        100

    .. versionadded:: 4.0.0
    rI   )rK   rL   rM   minr   rO   r1   rP   r!   r!   r$   r     s   
r   c                 C   sV   g }t |}t|d t| d D ]}| || | }t||kr(|t| q|S )aN  
    Calculate moving mean of each element of `array`.

    Args:
        array (list): List to process.
        size (int): Window size.

    Returns:
        list: Result of moving average.

    Example:

        >>> moving_mean(range(10), 1)
        [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
        >>> moving_mean(range(10), 5)
        [2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
        >>> moving_mean(range(10), 10)
        [4.5]

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Rename to ``moving_mean`` and remove ``moving_average`` and ``moving_avg`` aliases.
    r   )rU   ranger2   appendr   )arraysizer,   iwindowr!   r!   r$   r     s   r   c                 C   r<   )a  
    Multiply two numbers.

    Args:
        multiplier (int/float): The first number in a multiplication.
        multiplicand (int/float): The second number in a multiplication.

    Returns:
        int/float: Returns the product.

    Example:

        >>> multiply(4, 5)
        20
        >>> multiply(10, 4)
        40
        >>> multiply(None, 10)
        10
        >>> multiply(None, None)
        1

    .. versionadded:: 4.0.0
    r   )r=   r>   mul)
multipliermultiplicandr!   r!   r$   r     rB   r   c                    s@   t | rt|  }|S t | r fdd| D }|S d}|S )a{  
    Calculate exponentiation of `x` raised to the `n` power.

    Args:
        x (number): Base number.
        n (number): Exponent.

    Returns:
        number: Result of calculation.

    Example:

        >>> power(5, 2)
        25
        >>> power(12.5, 3)
        1953.125

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Removed alias ``pow_``.
    c                    s   g | ]}t | qS r!   )powr+   itemnr!   r$   
<listcomp>  s    zpower.<locals>.<listcomp>N)rO   	is_numberrd   is_list)r7   rh   r,   r!   rg   r$   r     s   


r   c                 C   s   t t| |S )a  
    Round number to precision.

    Args:
        x (number): Number to round.
        precision (int, optional): Rounding precision. Defaults to ``0``.

    Returns:
        int: Rounded number.

    Example:

        >>> round_(3.275) == 3.0
        True
        >>> round_(3.275, 1) == 3.3
        True

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Remove alias ``curve``.
    )r4   roundr6   r!   r!   r$   r     rG   r   c                    s"   t | }||   fdd| D S )a  
    Scale list of value to a maximum number.

    Args:
        array (list): Numbers to scale.
        maximum (number): Maximum scale value.

    Returns:
        list: Scaled numbers.

    Example:

        >>> scale([1, 2, 3, 4])
        [0.25, 0.5, 0.75, 1.0]
        >>> scale([1, 2, 3, 4], 1)
        [0.25, 0.5, 0.75, 1.0]
        >>> scale([1, 2, 3, 4], 4)
        [1.0, 2.0, 3.0, 4.0]
        >>> scale([1, 2, 3, 4], 2)
        [0.5, 1.0, 1.5, 2.0]

    .. versionadded:: 2.1.0
    c                    s   g | ]}|  qS r!   r!   re   factorr!   r$   ri   A      zscale.<locals>.<listcomp>)rN   )r]   maximum	array_maxr!   rm   r$   r   '  s   r   c                 C   sH   | d | d }}|d |d }}||krt }|S || ||  }|S )aI  
    Calculate the slope between two points.

    Args:
        point1 (list|tuple): X and Y coordinates of first point.
        point2 (list|tuple): X and Y cooredinates of second point.

    Returns:
        float: Calculated slope.

    Example:

        >>> slope((1, 2), (4, 8))
        2.0

    .. versionadded:: 2.1.0
    r   r   )INFINITY)point1point2x1y1x2y2r,   r!   r!   r$   r   D  s   r   c                 C   s   t t| S )a\  
    Calculate standard deviation of list of numbers.

    Args:
        array (list): List to process.

    Returns:
        float: Calculated standard deviation.

    Example:

        >>> round(std_deviation([1, 18, 20, 4]), 2) == 8.35
        True

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Remove alias ``sigma``.
    )r5   sqrtr   )r]   r!   r!   r$   r   a  s   r   c                 C   r<   )a  
    Subtracts two numbers.

    Args:
        minuend (int/float): Value passed in by the user.
        subtrahend (int/float): Value passed in by the user.

    Returns:
        int/float: Result of the difference from the given values.

    Example:

        >>> subtract(10, 5)
        5
        >>> subtract(-10, 4)
        -14
        >>> subtract(2, 0.5)
        1.5

    .. versionadded:: 4.0.0
    r   )r=   r>   sub)minuend
subtrahendr!   r!   r$   r   x  s   r   c                 C   s>   g }t | D ]\}}t |D ]\}}t|||g|}qq|S )a  
    Transpose the elements of `array`.

    Args:
        array (list): List to process.

    Returns:
        list: Transposed list.

    Example:

        >>> transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

    .. versionadded:: 2.1.0
    )r   rO   set_)r]   transyrowr7   colr!   r!   r$   r     s   r   c                    s,   t |   fdd}t| |   S )a  
    Calculate the variance of the elements in `array`.

    Args:
        array (list): List to process.

    Returns:
        float: Calculated variance.

    Example:

        >>> variance([1, 18, 20, 4])
        69.6875

    .. versionadded:: 2.1.0
    c                    s   t |   dS )NrQ   )r   )r7   avgr!   r$   var  s   zvariance.<locals>.var)r   rO   _map_value)r]   r   r!   r   r$   r     s   r   c                    s0   t | |}t| t| fdd|D S )a
  
    Calculate the standard score assuming normal distribution. If iteratee is passed, each element
    of `collection` is passed through a iteratee before the standard score is computed.

    Args:
        collection (list|dict): Collection to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        float: Calculated standard score.

    Example:

        >>> results = zscore([1, 2, 3])

        # [-1.224744871391589, 0.0, 1.224744871391589]

    .. versionadded:: 2.1.0
    c                    s   g | ]}|   qS r!   r!   re   r   sigr!   r$   ri     s    zzscore.<locals>.<listcomp>)rO   r   r   r   )r(   r1   r]   r!   r   r$   r     s   r   c                 C   sn   | s|} |s|}t | szt| } W n	 ty   Y nw t |s2zt|}W n	 ty1   Y nw || |S )z<Return the result of the math operation on the given values.)rO   rj   float	Exception)value1value2oprE   r!   r!   r$   r=     s"   


r=   c                    sn   t d fddd }t|r|}|S t|r5zfdd|D }W |S  ty4   Y |S w |S )N
   c                    s    |   S Nr!   )rf   )funcr8   r!   r$   rounder_func  s   zrounder.<locals>.rounder_funcc                    s   g | ]} |qS r!   r!   re   )r   r!   r$   ri     ro   zrounder.<locals>.<listcomp>)rd   rO   rj   is_iterable	TypeError)r   r7   r8   r,   r!   )r   r8   r   r$   r4     s   


r4   r   )r   )r   )(__doc__r5   r>   pydashrO   helpersr   r   r   r   __all__r   rr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   r4   r!   r!   r!   r$   <module>   sD    



%

#%
!

 