a
    )ñ»jÍ  ã                   @   s
  d dl mZ d dlmZ d dlmZmZmZmZm	Z	 G dd„ de	ƒZ
eee
 ee dœdd„Zeee ee ee ee d	œd
d„Zdeee eee  ee dœdd„Zedk�rd dlmZ eG dd„ dƒƒZededddƒedddƒedddƒgƒZeeeƒƒ dS )é    )ÚFraction)Úceil)ÚcastÚListÚOptionalÚSequenceÚProtocolc                   @   s:   e Zd ZU dZdZee ed< dZeed< dZ	eed< dS )ÚEdgez1Any object that defines an edge (such as Layout).NÚsizeé   ÚratioÚminimum_size)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   ÚintÚ__annotations__r   r   © r   r   ú1E:\soccer\ml_env\Lib\site-packages\rich/_ratio.pyr	      s   
r	   )ÚtotalÚedgesÚreturnc                 C   sð   dd„ |D ƒ}t }d|v râdd„ tt||ƒƒD ƒ}| tdd„ |D ƒƒ }|dkrddd„ t||ƒD ƒS ||td	d„ |D ƒƒƒ}|D ]&\}}||j |jkr€|j||<  qq€|dƒ}	|D ](\}}t||j |	 d
ƒ\}
}	|
||< q´qâqttt	 |ƒ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.
    c                 S   s   g | ]}|j pd ‘qS ©N)r
   )Ú.0Úedger   r   r   Ú
<listcomp>   ó    z!ratio_resolve.<locals>.<listcomp>Nc                 S   s$   g | ]\}\}}|d u r||f‘qS r   r   )r   Úindexr
   r   r   r   r   r   &   s   
þc                 s   s   | ]}|pd V  qdS )r   Nr   )r   r
   r   r   r   Ú	<genexpr>,   r   z ratio_resolve.<locals>.<genexpr>r   c                 S   s&   g | ]\}}|d u r|j p dn|‘qS )Nr   )r   )r   r
   r   r   r   r   r   /   s   ÿc                 s   s   | ]\}}|j pd V  qdS )r   N)r   )r   Ú_r   r   r   r   r   5   r   r   )
r   Ú	enumerateÚzipÚsumr   r   Údivmodr   r   r   )r   r   ÚsizesÚ	_FractionÚflexible_edgesÚ	remainingÚportionr   r   Ú	remainderr
   r   r   r   Úratio_resolve   s0    þþÿ

r+   )r   ÚratiosÚmaximumsÚvaluesr   c                 C   sž   dd„ t ||ƒD ƒ}t|ƒ}|s,|dd… S | }g }|j}t |||ƒD ]R\}}	}
|r�|dkr�t|	t|| | ƒƒ}||
| ƒ ||8 }||8 }qF||
ƒ qF|S )ad  Divide 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.
    c                 S   s   g | ]\}}|r|nd ‘qS ©r   r   )r   r   Ú_maxr   r   r   r   Y   r   z ratio_reduce.<locals>.<listcomp>Nr   )r"   r#   ÚappendÚminÚround)r   r,   r-   r.   Útotal_ratioÚtotal_remainingÚresultr1   r   ÚmaximumÚvalueÚdistributedr   r   r   Úratio_reduceK   s    

r:   N)r   r,   Úminimumsr   c                 C   s®   |rdd„ t ||ƒD ƒ}t|ƒ}|dks0J dƒ‚| }g }|j}|du rVdgt|ƒ }n|}t ||ƒD ]D\}}	|dkrŒt|	t|| | ƒƒ}
n|}
||
ƒ ||8 }||
8 }qd|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.
    c                 S   s   g | ]\}}|r|nd ‘qS r/   r   )r   r   Ú_minr   r   r   r   y   r   z$ratio_distribute.<locals>.<listcomp>r   zSum of ratios must be > 0N)r"   r#   r1   ÚlenÚmaxr   )r   r,   r;   r4   r5   Údistributed_totalr1   Ú	_minimumsr   Úminimumr9   r   r   r   Úratio_distributek   s$    
rB   Ú__main__)Ú	dataclassc                   @   s6   e Zd ZU dZee ed< dZeed< dZeed< dS )ÚENr
   r   r   r   )	r   r   r   r
   r   r   r   r   r   r   r   r   r   rE   ’   s   
rE   én   r   )N)Ú	fractionsr   Úmathr   Útypingr   r   r   r   r   r	   r   r+   r:   rB   r   ÚdataclassesrD   rE   ZresolvedÚprintr#   r   r   r   r   Ú<module>   s$   >þ! ÿþ$
(