o
    a+)h`                     @   sH  d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 e j
dkr(d dlmZ nd dlmZ G dd deZd	ed
e	e dee fddZd	edee dee dee dee f
ddZ	dd	edee deee  dee fddZedkrd 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 dS )    N)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   VC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\pip/_vendor/rich/_ratio.pyr      s
   
 r   totaledgesreturnc                 C   s   dd |D }t }d|v rtdd tt||D }| tdd |D  }|dkr2dd t||D S ||td	d |D }|D ]\}}||j |jkrS|j||<  nq@|d}	|D ]\}}t||j |	 d
\}
}	|
||< qZnd|v s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>%   s    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>2   s    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   5   s     c                 s   s    | ]
\}}|j p
d V  qdS )r   N)r   )r   _r   r   r   r   r    ;   s    r   )
r   	enumeratezipsumr   r   divmodr   r   r   )r   r   sizes	_Fractionflexible_edges	remainingportionr   r   	remainderr   r   r   r   ratio_resolve   s4   

$r,   ratiosmaximumsvaluesc                 C   s   dd t ||D }t|}|s|dd S | }g }|j}t |||D ])\}}	}
|rH|dkrHt|	t|| | }||
|  ||8 }||8 }q#||
 q#|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      g | ]
\}}|r
|nd qS r   r   )r   r   _maxr   r   r   r   _       z ratio_reduce.<locals>.<listcomp>Nr   )r#   r$   appendminround)r   r-   r.   r/   total_ratiototal_remainingresultr4   r   maximumvaluedistributedr   r   r   ratio_reduceQ   s   

r=   minimumsc                 C   s   |rdd t ||D }t|}|dksJ d| }g }|j}|du r+dgt| }n|}t ||D ]"\}}	|dkrFt|	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.
    c                 S   r0   r1   r   )r   r   _minr   r   r   r      r3   z$ratio_distribute.<locals>.<listcomp>r   zSum of ratios must be > 0N)r#   r$   r4   lenmaxr   )r   r-   r>   r7   r8   distributed_totalr4   	_minimumsr   minimumr<   r   r   r   ratio_distributeq   s$   
rE   __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   rH      s   
 rH   n   r   r   )sys	fractionsr   mathr   typingr   r   r   r   version_infor
   Zpip._vendor.typing_extensionsr   r   r,   r=   rE   r   dataclassesrG   rH   resolvedprintr$   r   r   r   r   <module>   sJ    
=
!

$(