HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/thorium/__pycache__/calc.cpython-310.pyc
o

�N�g�@s�dZzddlZdZWneydZYnwdd�Zddd�Zdd	d
�Zddd�Zdd
d�Zddd�Z	ddd�Z
ddd�Zddd�Zddd�Z
dS)z�
Used to manage the thorium register. The thorium register is where compound
values are stored and computed, such as averages etc.

.. versionadded:: 2016.11.0

:depends: statistics PyPi module
�NTFcCstS)z5
    The statistics module must be pip installed
    )�	HAS_STATS�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/thorium/calc.py�__virtual__src	Cs|iddd�}|tvr|�d�|d<d|d<dd	�}d
d�}||tjtjtjtjtjtjd�}	d
}
g}t|d��t|dD]}|
d7}
|
|krMn|durW|�	|�qA|�	||�qA|	||�}
|d
krq|
|krqd|d<d
|kr{|
kr�nnd|d<t
|�||
d�|d<|S)a�
    Perform a calculation on the ``num`` most recent values. Requires a list.
    Valid values for ``oper`` are:

    - add: Add last ``num`` values together
    - mul: Multiple last ``num`` values together
    - mean: Calculate mean of last ``num`` values
    - median: Calculate median of last ``num`` values
    - median_low: Calculate low median of last ``num`` values
    - median_high: Calculate high median of last ``num`` values
    - median_grouped: Calculate grouped median of last ``num`` values
    - mode: Calculate mode of last ``num`` values

    USAGE:

    .. code-block:: yaml

        foo:
          calc.calc:
            - name: myregentry
            - num: 5
            - oper: mean
    �T)�name�changes�comment�resultz not found in registerr	Fr
cSsd}|D]}||}q|S�Nrr)�vals�sum�valrrr�opadd6�
zcalc.<locals>.opaddcSsd}|D]}||}q|Srr)r�prodrrrr�opmul<rzcalc.<locals>.opmul)�add�mul�mean�median�
median_low�median_high�median_grouped�moderr�N)zNumber of valuesZOperatorZAnswerr)Z__reg__�
statisticsrrrrrr�reverse�append�len)r�num�oper�minimum�maximum�ref�retrr�ops�countrZregitemZanswerrrr�calcsF�
�r(cC�t||d|||d�S)z�
    Adds together the ``num`` most recent values. Requires a list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.add:
            - name: myregentry
            - num: 5
    r�rr r!r"r#r$�r(�rr r"r#r$rrrri�
�rcCr))z�
    Multiplies together the ``num`` most recent values. Requires a list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.mul:
            - name: myregentry
            - num: 5
    rr*r+r,rrrr{r-rcCr))z�
    Calculates the mean of the ``num`` most recent values. Requires a list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.mean:
            - name: myregentry
            - num: 5
    rr*r+r,rrrr�r-rcCr))z�
    Calculates the mean of the ``num`` most recent values. Requires a list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.median:
            - name: myregentry
            - num: 5
    rr*r+r,rrrr�r-rcCr))z�
    Calculates the low mean of the ``num`` most recent values. Requires a list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.median_low:
            - name: myregentry
            - num: 5
    rr*r+r,rrrr�r-rcCr))z�
    Calculates the high mean of the ``num`` most recent values. Requires a list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.median_high:
            - name: myregentry
            - num: 5
    rr*r+r,rrrr�s
�rcCr))z�
    Calculates the grouped mean of the ``num`` most recent values. Requires a
    list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.median_grouped:
            - name: myregentry
            - num: 5
    rr*r+r,rrrr�s�rcCr))z�
    Calculates the mode of the ``num`` most recent values. Requires a list.

    USAGE:

    .. code-block:: yaml

        foo:
          calc.mode:
            - name: myregentry
            - num: 5
    rr*r+r,rrrr�r-r)rrN)�__doc__rr�ImportErrorrr(rrrrrrrrrrrr�<module>s"	�

P