
    tni                     j    d Z ddlZddlmZmZ ddlmZ  ej        e          Z	 G d de          Z
dS )z%Progress-to-logs tqdm implementation.    N)datetime	timedelta)tqdmc                        e Zd ZdZej        Z ed          Z fdZ	e
defd            Ze
defd            Zd fd	ZdefdZd Zd Z xZS )tqdm_loggingaM  A tqdm implementation that outputs to Python logger.

    - Any postfix progress bar arguments are passed as `extras` to the logging system

    - The log has structured data available; all logs are tagged with `{"tqdm": True}`
      so they can be filtered out in the log management service

    - Default rate of creating messages is lower than the usually progress bar
      update rate of 1 Htz, because we do not want to spam the logs

    See also

    - `Implementing structured logging <https://docs.python.org/3/howto/logging-cookbook.html#implementing-structured-logging>`_.
    
   secondsc                 t    t          ddd          | _         t          t          |           j        |i | d S )Ni     )r   last_log_message_atsuperr   __init__)selfargskwargs	__class__s      W/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/tqdm_loggable/tqdm_logging.pyr   ztqdm_logging.__init__#   s?    #+D!Q#7#7 *lD!!*D;F;;;;;    	log_levelc                     || _         dS )zSet log level to all tqdm_logging instances.

        Currently we do not support per-instance logging level
        to maintain argument compatibility with std.tqdm constructor.
        N)r   )clsr   s     r   	set_levelztqdm_logging.set_level'   s     "r   ratec                 B    t          |t                    sJ || _        dS )z-Set the rate how often we post a log message.N)
isinstancer   log_message_rate)r   r   s     r   set_log_rateztqdm_logging.set_log_rate0   s(     $	*****#r   NTc                 Z    || _          t          t          |           j        ||fi | dS )z$Overloaded to store the raw post-fixN)raw_postfixr   r   set_postfix)r   ordered_dictrefreshr   r   s       r   r!   ztqdm_logging.set_postfix6   s8    '-lD!!-lGNNvNNNNNr   returnc                 d    | j         rdS t          j                    | j        z
  | j        k    rdS dS )z5Check if we throttle down displays to reduce log spamFT)disabler   nowr   r   r   s    r   should_throttle_loggingz$tqdm_logging.should_throttle_logging;   s9     < 	5<>>D44t7LLL54r   c                 n   |                                  rdS | j        }|                    dd          }|                    dd          }|                    dd          }|                    dd          }|                    dd          }|                    d	d          }|                    d
d          }	|                    dd          }
|	r1|
r/|                     |	||          }|                     |
||          }n|	}|
}|pd}|pd}|r
|
r|
|	z
  |z  nd}|rt	          j        |          nd}	 |r&|
r$t          j                    t          |          z   nt          j	        d          }n# t          $ r t          j        }Y nw xY wt	          j        |          }|r|dk    r	|d| d}nd|z  dd| }nd}t          | di           }|pd}d|||||	|
||                                |d
}t                              | j        d||||||||
  
         t          j                    | _        dS )z,Create a log entry for the current progress.Nprefixunknownpostfixr   r   unitunit_divisorelapsedntotal-?r	   r   z,.1fz/szs/r    T)
r   progress_namer   r.   r0   r1   r2   r-   eta	remainingz?Progress on:%s %s/%s rate:%s remaining:%s elapsed:%s postfix:%s)extra)r)   format_dictgetformat_sizeof	tqdm_autoformat_intervalr   r'   r   utcfromtimestampOverflowErrormaxgetattr	isoformatloggerlogr   r   )r   r   r:   namer-   r   r.   r/   r0   r1   r2   n_formattedtotal_formattedr8   remaining_streta_dtelapsed_strrate_formattedr    postfix_strstructured_logss                        r   displayztqdm_logging.displayG   s    '')) 	F &x33//)T22vq))vt,,"~t<<//)Q//OOC##,, 	$ 	$,,QlCCK"00lKKOO K#O!(S)0S +/?5?UQY$&&a	@DM	1)<<<#	"J"'Jhlnny'C'C'CCC-5-Fq-I-I F 	" 	" 	"\FFF	"  /88 	!axx$(!7!7t!7!7!7$%dF!9!9!94!9!9 N dM266n ! ###%%"
 
  	

NM! 	 	
 	
 	
 $,<>>   s   4<E1 1F
	F
c                 N    | j         rd S d| _         |                                  d S NT)r&   rO   r(   s    r   closeztqdm_logging.close   s+    < 	F r   rQ   )__name__
__module____qualname____doc__loggingINFOr   r   r   r   classmethodintr   r   r!   boolr)   rO   rR   __classcell__)r   s   @r   r   r      s          I !y,,,< < < < < "# " " " [" $	 $ $ $ [$
O O O O O O

 
 
 
 
W2 W2 W2r      r   r   )rV   rW   r   r   	tqdm.autor   r=   	getLoggerrS   rD   r    r   r   <module>r`      s    + +  ( ( ( ( ( ( ( ( ' ' ' ' ' ' 
	8	$	$[ [ [ [ [9 [ [ [ [ [r   