HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/rich/__pycache__/_ratio.cpython-310.pyc
o

;j��@s ddlmZddlmZddlmZmZmZmZm	Z	Gdd�de	�Z
dedee
deefd	d
�Zdedeedeed
eedeef
dd�Z
	ddedeedeeedeefdd�Zedkr�ddlmZeGdd�d��Zededdd�eddd�eddd�g�Zeee��dSdS)�)�Fraction)�ceil)�cast�List�Optional�Sequence�Protocolc@s:eZdZUdZdZeeed<dZeed<dZ	eed<dS)�Edgez1Any object that defines an edge (such as Layout).N�size��ratio�minimum_size)
�__name__�
__module__�__qualname__�__doc__r
r�int�__annotations__rr
�rr�?/opt/saltstack/salt/lib/python3.10/site-packages/rich/_ratio.pyr	s

r	�total�edges�returncCs�dd�|D�}t}d|vrtdd�tt||��D�}|tdd�|D��}|dkr2dd�t||�D�S||td	d�|D���}|D]\}}||j|jkrS|j||<nq@|d�}	|D]\}}t||j|	d
�\}
}	|
||<qZnd|vs
ttt	|�S)a�Divide total space to satisfy size, ratio, and minimum_size, constraints.

    The returned list of integers should add up to total in most cases, unless it is
    impossible to satisfy all the constraints. For instance, if there are two edges
    with a minimum size of 20 each and `total` is 30 then the returned list will be
    greater than total. In practice, this would mean that a Layout object would
    clip the rows that would overflow the screen height.

    Args:
        total (int): Total number of characters.
        edges (List[Edge]): Edges within total space.

    Returns:
        List[int]: Number of characters for each edge.
    cSsg|]}|jpd�qS�N)r
)�.0�edgerrr�
<listcomp>sz!ratio_resolve.<locals>.<listcomp>NcSs$g|]\}\}}|dur||f�qSrr)r�indexr
rrrrr&s

�css�|]}|pdVqdS)rNr)rr
rrr�	<genexpr>,s�z ratio_resolve.<locals>.<genexpr>rcSs&g|]\}}|dur|jpdn|�qS)Nr)r
)rr
rrrrr/s���css�|]
\}}|jp
dVqdS)rN)r)r�_rrrrr5s�r)
r�	enumerate�zip�sumrr
�divmodrrr)rrZsizesZ	_FractionZflexible_edges�	remainingZportionrr�	remainderr
rrr�
ratio_resolves4���
�
�$r&�ratios�maximums�valuescCs�dd�t||�D�}t|�}|s|dd�S|}g}|j}t|||�D])\}}	}
|rH|dkrHt|	t|||��}||
|�||8}||8}q#||
�q#|S)adDivide an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        maximums (List[int]): List of maximums values for each slot.
        values (List[int]): List of values

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    cS�g|]
\}}|r
|nd�qS�rr)rrZ_maxrrrrY�z ratio_reduce.<locals>.<listcomp>Nr)r!r"�append�min�round)rr'r(r)�total_ratio�total_remaining�resultr-rZmaximum�value�distributedrrr�ratio_reduceKs

r5N�minimumscCs�|rdd�t||�D�}t|�}|dksJd��|}g}|j}|dur+dgt|�}n|}t||�D]"\}}	|dkrFt|	t|||��}
n|}
||
�||8}||
8}q2|S)a<Distribute an integer total in to parts based on ratios.

    Args:
        total (int): The total to divide.
        ratios (List[int]): A list of integer ratios.
        minimums (List[int]): List of minimum values for each slot.

    Returns:
        List[int]: A list of integers guaranteed to sum to total.
    cSr*r+r)rrZ_minrrrryr,z$ratio_distribute.<locals>.<listcomp>rzSum of ratios must be > 0N)r!r"r-�len�maxr)rr'r6r0r1Zdistributed_totalr-Z	_minimumsrZminimumr4rrr�ratio_distributeks$

r9�__main__)�	dataclassc@s6eZdZUdZeeed<dZeed<dZeed<dS)�ENr
rrr
)	rrrr
rrrrr
rrrrr<�s
r<�nrr)Z	fractionsr�mathr�typingrrrrrr	rr&r5r9rZdataclassesr;r<Zresolved�printr"rrrr�<module>sB=����
�!���
�
�$(�