
    -if6                         d Z ddlmZmZ ddlmZ ddlZddiZddZdd
Z G d d          Z	 G d de	          Z
 G d de
          Z G d d          Z G d dee
          Z G d de
          Z	 	 	 	 	 ddZdS )zHImplements the generic progress logger class, and the ProgressBar class.    )tqdmtqdm_notebook)OrderedDictNnotebookFonc                 *    | dk    rdndt           d<   d S )Nr   TFr   )SETTINGS)turns    M/var/www/html/speakWrite/venv/lib/python3.11/site-packages/proglog/proglog.pyr   r   
   s    $(DLL44uHZ       c                 F    t          |           |k     r| n| d |         dz   S )Nz...)len)s
max_lengths     r   troncate_stringr      s)    Q*$$11AkzkNU,BCr   c                   F    e Zd ZdZddZd ZddZd Zd Zd Z	d	 Z
d
 ZdS )ProgressLoggerzGeneric class for progress loggers.

    A progress logger contains a "state" dictionary.

    Parameters
    ----------
    init_state : dict
        Dictionary representing the initial state.
    Nc                 z    i | _         i | _        g | _        d| _        || j                             |           d S d S )Nr   )statestoredlogs
log_indentupdate)self
init_states     r   __init__zProgressLogger.__init__   sH    
	!Jj))))) "!r   c                 P    | j                             d| j        z  |z              d S )N )r   appendr   )r   messages     r   logzProgressLogger.log&   s*    	#/7:;;;;;r   c                     |Xt          |d          5 }|                    d                    | j                             d d d            d S # 1 swxY w Y   d S d                    | j                  S )Na
)openwritejoinr   )r   filepathfs      r   	dump_logszProgressLogger.dump_logs)   s    h$$ .		$),,---. . . . . . . . . . . . . . . . . . 99TY'''s   .AAAc                     dS )zExecute something after the state has been updated by the given
        state elements.

        This default callback does nothing, overwrite it by subclassing.
        N r   kws     r   callbackzProgressLogger.callback0   	     	r   c                 T    | j                             |            | j        di | dS )a  Store objects in the logger and trigger ``self.store_callback``.

        This works exactly like ``logger()``, but the later is meant for simple
        data objects (text, numbers) that will be sent over the network or
        written to a file. The ``store`` method expects rather large objects
        which are not necessarily serializable, and will be used eg to draw
        plots on the fly.
        Nr-   )r   r   store_callbackr.   s     r   storezProgressLogger.store8   s9     	2!!b!!!!!r   c                     dS )zExecute something after the store has been updated by the given
        state elements.

        This default callback does nothing, overwrite it by subclassing
        Nr-   r.   s     r   r3   zProgressLogger.store_callbackD   r1   r   c              +   d   K   |                                 D ]\  }}|D ]} | di ||i |V  dS )a  Iterate through a list while updating the state.

        Examples
        --------
        >>> for username in logger.iter(user=['tom', 'tim', 'lea']):
        >>>     # At every loop, logger.state['user'] is updated
        >>>     print(username)
        Nr-   )items)r   r/   fielditerableits        r   iterzProgressLogger.iterL   sf        "xxzz 	 	OE8  ##r{###	 	r   c                 T    | j                             |            | j        di | d S )Nr-   )r   r   r0   r.   s     r   __call__zProgressLogger.__call__Z   s6    
"r   N)__name__
__module____qualname____doc__r   r"   r+   r0   r4   r3   r;   r=   r-   r   r   r   r      s         * * * *< < <( ( ( (  
" 
" 
"        r   r   c                   h    e Zd ZdZdZ	 	 	 	 	 	 ddZed             Zd Zd	 Z	d
 Z
ddZddZd ZdS )ProgressBarLoggera  Generic class for progress loggers.

    A progress logger contains a "state" dictionary.

    Parameters
    ----------
    init_state : dict
        Initial state of the logger.
    bars : None, list, tuple, or dict, optional
        Either None (will be initialized with no bar) or a list/tuple of bar
        names (e.g., ['main', 'sub']) which will be initialized with index -1 and
        no total, or a dictionary (possibly ordered) of bars, of the form
        `{bar_1: {title: 'bar1', index: 2, total: 23}, bar_2: {...}}`.
    ignored_bars : None, list of str, or 'all_others', optional
        Either None (newly met bars will be added) or a list of blacklisted bar
        names, or 'all_others' to signify that all bar names not already in
        `self.bars` will be ignored.
    logged_bars
    min_time_interval : int or float
        Time in seconds between progress bar updates.
    ignore_bars_under : int
       Nallr   c                 j   t                               | |           |t                      }n5t          |t          t
          f          rt          d |D                       }t          |t          t
          f          rt          |          }|| _        || _        || j	        d<   || _
        || _        d S )Nc           
      :    g | ]}|t          |d ddd          fS )Nr   )titleindextotalr!   indent)dict).0bs     r   
<listcomp>z.ProgressBarLogger.__init__.<locals>.<listcomp>   sA        1BdDQRSSST  r   bars)r   r   r   
isinstancelisttuplesetignored_barslogged_barsr   min_time_intervalignore_bars_under)r   r   rR   rW   rX   rY   rZ   s          r   r   zProgressBarLogger.__init__y   s     	j111<==DDtUm,, 	 !   D lT5M22 	-|,,L(&!
6!2!2r   c                     | j         d         S )zReturn ``self.state['bars'].``rR   )r   )r   s    r   rR   zProgressBarLogger.bars   s     z&!!r   c                 N    | j         dS | j         dk    r	|| j        vS || j         v S )NF
all_others)rW   rR   r   bars     r   bar_is_ignoredz ProgressBarLogger.bar_is_ignored   s9    $5,..di''$+++r   c                 @    | j         sdS | j         dk    rdS || j         v S )NFrF   T)rX   r^   s     r   bar_is_loggedzProgressBarLogger.bar_is_logged   s3     	+5&&4$***r   c                 b    t          |d          rt          |          nd }|d uo
|| j        k     S )N__len__)hasattrr   rZ   )r   r9   lengths      r   iterable_is_too_shortz'ProgressBarLogger.iterable_is_too_short   s8    ")(I">">HXDd"I$2H)HIr    c                 J    d|v r|                     d          nd|                                \                                 s                               rS |z   t	          d          r  di dz   t                    i  fd} |            S )a  Iterate through a list while updating a state bar.

        Parameters
        ----------
        bar_prefix : str
            Bar prefix.

        Examples
        --------
        >>> for username in logger.iter_bar(user=['tom', 'tim', 'lea']):
        >>>     # At every loop, logger.state['bars']['user'] is updated
        >>>     # to {index: i, total: 3, title:'user'}
        >>>     print (username)

        bar_messageNrd   __totalc            	   3   l  K   t          j                     } d}t                    D ]W\  }}t          j                     }|dk    s|| z
  j        k    r' di dz    |          i  di dz   |i |} |V  Xj                 d         |k    r di dz   |i  di dz   |dz   i d S )Nr   	__message__indexrK      r-   )time	enumeraterY   rR   )	last_timeir:   now_timer_   rj   r9   r   s       r   new_iterablez0ProgressBarLogger.iter_bar.<locals>.new_iterable   s     	IA"8,,  29;;FF9 4t7M M M".DDk 1;;r??CDDDD00C)OQ/000 (Iy~g&!++,,i+,,,D,,C)OQU+,,,,,r   r-   )poppopitemr`   rg   re   r   )r   
bar_prefixr/   ru   r_   rj   r9   s   `   @@@r   iter_barzProgressBarLogger.iter_bar   s      B&&//KKK

Xs## 	t'A'A('K'K 	O38Y'' 	5D44C)OS]]3444	- 	- 	- 	- 	- 	- 	- 	-  |~~r   c                     dS )a  Execute a custom action after the progress bars are updated.

        Parameters
        ----------
        bar
          Name/ID of the bar to be modified.

        attr
          Attribute of the bar attribute to be modified

        value
          New value of the attribute

        old_value
          Previous value of this bar's attribute.

        This default callback does nothing, overwrite it by subclassing.
        Nr-   )r   r_   attrvalue	old_values        r   bars_callbackzProgressBarLogger.bars_callback   s	    & 	r   c           	         t          |                                d           }|D ]7\  }}d|v r,|                    d          \  }}|                     |          r9|                    |           || j        vrt          |dd d           | j        |<   | j        |         |         }|                     |          ru|dk    o||k     }|dk    s|r| j        | j        |         d<   n| j        |         d         | _        | 	                    d	|d
|d|           | xj        | j
        z  c_        || j        |         |<   |                     ||||           9| j                            |            | j        di | d S )Nc                 :    | d                              d           S )Nr   rL   )endswith)kvs    r   <lambda>z,ProgressBarLogger.__call__.<locals>.<lambda>   s    bennW6M6M2M r   )key__rI   )rJ   rK   rL   r!   rK   rL   rM   [z] z: r-   )sortedr7   splitr`   rv   rR   rN   rb   r   r"   
bar_indentr~   r   r   r0   )	r   r/   r7   r   r|   r_   r{   r}   new_bars	            r   r=   zProgressBarLogger.__call__   s   rxxzz'M'MNNN 	@ 	@JCs{{IIdOO	T&&s++ sdi''%)2TSW%X%X%XDIcN IcN40	%%c** 7#wGUY5FGW37?	#x00*.)C.*BHHHccc444?@@@OOt6OO',	#t$""3eY???
"r   )NNNrF   r   r   )rh   r>   )r?   r@   rA   rB   r   r   propertyrR   r`   rb   rg   ry   r~   r=   r-   r   r   rD   rD   _   s         . J 3 3 3 36 " " X", , ,+ + +J J J, , , ,\   *    r   rD   c                   D    e Zd ZdZ	 	 	 	 	 	 	 	 	 ddZd	 Zd
 Zd Zd ZdS )TqdmProgressBarLoggera^  Tqdm-powered progress bar for console or Notebooks.

    Parameters
    ----------
    init_state : dict
        Initial state of the logger.
    bars : None, list, tuple, or dict, optional
        Either None (will be initialized with no bar) or a list/tuple of bar
        names (e.g., ['main', 'sub']) which will be initialized with index -1 and
        no total, or a dictionary (possibly ordered) of bars, of the form
        `{bar_1: {title: 'bar1', index: 2, total: 23}, bar_2: {...}}`.
    leave_bars : bool, optional
        Whether to leave the progress bars displayed upon completion.
    ignored_bars : None, list of str, or 'all_others', optional
        Either None (newly met bars will be added) or a list of blacklisted bar
        names, or 'all_others' to signify that all bar names not already in
        `self.bars` will be ignored.
    notebook : bool, optional
        True will make the bars look nice (HTML) in the Jupyter notebook. It is
        advised to leave to 'default' as the default can be globally set from
        inside a notebook with `import proglog; proglog.notebook_mode()`.
    print_messages : bool
        If True, every `logger(message='something')` will print a message in
        the console or notebook.
    min_time_interval : int or float
        Time in seconds between progress bar updates.
    ignore_bars_under : int
    NFrF   defaultTr   c
           	         t                               | |||||	|           || _        t          d | j        D                       | _        |dk    rt          d         }|| _        || _        | j        rt          nt          | _
        d S )N)r   rR   rW   rX   rZ   rY   c                     g | ]}|d fS r>   r-   )rO   r_   s     r   rQ   z2TqdmProgressBarLogger.__init__.<locals>.<listcomp>@  s    %G%G%GcsDk%G%G%Gr   r   r   )rD   r   
leave_barsr   rR   	tqdm_barsr	   r   print_messagesr   r   )
r   r   rR   r   rW   rX   r   r   rY   rZ   s
             r   r   zTqdmProgressBarLogger.__init__*  s     	""!%#// 	# 	
 	
 	
 %$%G%GTY%G%G%GHHy  
+H ,%)]<MM			r   c                 6   || j         v r"| j         |         |                     |           | j        |         }|                     |d         |d         t	          t          t          |d                                       | j                  | j         |<   dS )z:Create a new tqdm bar, possibly replacing an existing one.NrL   rJ   r!   now)rL   descpostfixleave)r   close_tqdm_barrR   r   rN   r   strr   )r   r_   infoss      r   new_tqdm_barz"TqdmProgressBarLogger.new_tqdm_barG  s    4>!!s(;(G$$$	#"ii.w_Sy1A-B-BCCDDD/	 ( 
 
sr   c                 j    | j         |                                          | j        sd| j         |<   dS dS )zClose and erase the tqdm bar.N)r   closer   r^   s     r   r   z$TqdmProgressBarLogger.close_tqdm_barS  sA    s!!###} 	'"&DN3	' 	'r   c                 \   || j         vs| j         |         |                     |           |dk    r||k    rW| j        |         d         }|r||k    r|                     |           d S | j         |                             ||z
             d S |                     |           | j         |                             |dz              d S |dk    r]| j         |                             t          t          |                               | j         |                             d           d S d S )NrK   rL   ro   r!   r   r   )r   r   rR   r   r   set_postfixr   r   )r   r_   r{   r|   r}   rL   s         r   r~   z#TqdmProgressBarLogger.bars_callbackY  s=   t~%%4>#+>+Fc"""7??	!!	#w/ Beunn'',,,,,N3'..uy/@AAAAA!!#&&&s#**51955555YN3++E

0K0K+LLLN3&&q))))) r   c                     | j         rLd|v rJ|d         rD| j        rt          |d                    d S | j                            |d                    d S d S d S d S )Nr!   )r   r   printr   r'   r.   s     r   r0   zTqdmProgressBarLogger.callbackj  so     	/IOOIO} /bm$$$$$	9.....		/ 	/OOOOr   )	NNFNrF   r   Tr   r   )	r?   r@   rA   rB   r   r   r   r~   r0   r-   r   r   r   r     s         > = = = =:

 

 

' ' '* * *"/ / / / /r   r   c                       e Zd Zd Zd ZdS )RqWorkerProgressLoggerc                     || _         d| j         j        vr*i | j         j        d<   | j                                          d S d S Nprogress_data)jobmetasave)r   r   s     r   r   zRqWorkerProgressLogger.__init__s  sA    $(-//-/DHM/*HMMOOOOO 0/r   c                 `    | j         | j        j        d<   | j                                         d S r   )r   r   r   r   r.   s     r   r0   zRqWorkerProgressLogger.callbacky  s%    )-o&r   N)r?   r@   rA   r   r0   r-   r   r   r   r   r  s2              r   r   c                        e Zd Z	 	 	 	 	 ddZdS )RqWorkerBarLoggerNr-   rF   r   c                 |    t                               | |           t                              | |||||           d S )N)r   rR   rW   rX   rY   )r   r   rD   )r   r   r   rR   rW   rX   rY   s          r   r   zRqWorkerBarLogger.__init__  sS     	''c222""!%#/ 	# 	
 	
 	
 	
 	
r   )NNr-   rF   r   )r?   r@   rA   r   r-   r   r   r   r   ~  s9        
 
 
 
 
 
 
r   r   c                       e Zd Zd ZdS )MuteProgressBarLoggerc                     dS )NTr-   r^   s     r   r`   z$MuteProgressBarLogger.bar_is_ignored  s    tr   N)r?   r@   rA   r`   r-   r   r   r   r     s#            r   r   rF   c                 Z    | dk    rt          |||||          S | t                      S | S )Nr_   )rR   rW   rX   rY   rZ   )r   r   )loggerrR   rW   rX   rY   rZ   s         r   default_bar_loggerr     sK     $%#//
 
 
 	
 
$&&&r   )r   )r   )NNrF   r   r   )rB   r   r   collectionsr   rp   r	   r   r   r   rD   r   r   r   r   r   r-   r   r   <module>r      s   N N $ $ $ $ $ $ $ $ # # # # # # = = = =D D D DJ J J J J J J JZj j j j j j j jZc/ c/ c/ c/ c/- c/ c/ c/L	 	 	 	 	 	 	 	
 
 
 
 
.0A 
 
 
,    -    
     r   