
    bi                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ  edd      d	        Z G d
 de	      Zy)    )annotationsN)default_timer)Callback)_deprecatedz2022.6.0zdask.utils.format_time)after_versionuse_insteadc                    t        | d      \  }}t        |d      \  }}|r|dd|dd|ddS |r
|dd|ddS |ddS )zFormat seconds into a human readable form.

    >>> format_time(10.4)  # doctest: +SKIP
    '10.4s'
    >>> format_time(1000.4)  # doctest: +SKIP
    '16min 40.4s'
    <   z2.0fzhr zmin z4.1fs)divmod)tmr   hs       T/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/dask/diagnostics/progress.pyformat_timer      sl     !R=DAq!R=DAqDQtHD422	
DaXQ''D|    c                  <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d	 Z
y)ProgressBara%  A progress bar for dask.

    Parameters
    ----------
    minimum : int, optional
        Minimum time threshold in seconds before displaying a progress bar.
        Default is 0 (always display)
    width : int, optional
        Width of the bar
    dt : float, optional
        Update resolution in seconds, default is 0.1 seconds
    out : file object, optional
        File object to which the progress bar will be written
        It can be ``sys.stdout``, ``sys.stderr`` or any other file object able to write ``str`` objects
        Default is ``sys.stdout``

    Examples
    --------

    Below we create a progress bar with a minimum threshold of 1 second before
    displaying. For cheap computations nothing is shown:

    >>> with ProgressBar(minimum=1.0):      # doctest: +SKIP
    ...     out = some_fast_computation.compute()

    But for expensive computations a full progress bar is displayed:

    >>> with ProgressBar(minimum=1.0):      # doctest: +SKIP
    ...     out = some_slow_computation.compute()
    [########################################] | 100% Completed | 10.4 s

    The duration of the last computation is available as an attribute

    >>> pbar = ProgressBar()                # doctest: +SKIP
    >>> with pbar:                          # doctest: +SKIP
    ...     out = some_computation.compute()
    [########################################] | 100% Completed | 10.4 s
    >>> pbar.last_duration                  # doctest: +SKIP
    10.4

    You can also register a progress bar so that it displays for all
    computations:

    >>> pbar = ProgressBar()                # doctest: +SKIP
    >>> pbar.register()                     # doctest: +SKIP
    >>> some_slow_computation.compute()     # doctest: +SKIP
    [########################################] | 100% Completed | 10.4 s
    Nc                n    |t         j                  }|| _        || _        || _        || _        d| _        y )Nr   )sysstdout_minimum_width_dt_filelast_duration)selfminimumwidthdtouts        r   __init__zProgressBar.__init__R   s6    ; **C
r   c                    d | _         t               | _        d| _        t	        j
                  | j                        | _        d| j                  _        | j                  j                          y )NT)target)
_stater   _start_time_running	threadingThread_timer_func_timerdaemonstart)r   dsks     r   _startzProgressBar._start^   sN    (?&&d.>.>?!r   c                `    || _         | j                  | j                  j                          y y N)r%   r   flush)r   keyr.   states       r   _pretaskzProgressBar._pretaskg   s(    ::!JJ "r   c                r   d| _         | j                  j                          t               | j                  z
  }|| _        || j                  k  ry |s| j                  d|       n| j                  |       | j                  6| j                  j                  d       | j                  j                          y y )NF   
)r'   r+   joinr   r&   r   r   	_draw_bar_update_barr   writer2   )r   r.   r4   erroredelapseds        r   _finishzProgressBar._finishl   s    /D$4$44$T]]"NN1g&W%::!JJT"JJ "r   c                    | j                   rdt               | j                  z
  }|| j                  kD  r| j	                  |       t        j                  | j                         | j                   rcyy)z/Background thread for updating the progress barN)r'   r   r&   r   r;   timesleepr   )r   r>   s     r   r*   zProgressBar._timer_func{   sN    mm#o(8(88G&  )JJtxx 	 mmr   c                    | j                   s| j                  d|       y t        d         }t        fddD              |z   }||k  r| j                  |r||z  nd|       y y )Nr   finishedc              3  :   K   | ]  }t        |           y wr1   )len).0kr   s     r   	<genexpr>z*ProgressBar._update_bar.<locals>.<genexpr>   s     H1S1YHs   )readywaitingrunning)r%   r:   rF   sum)r   r>   ndonentasksr   s       @r   r;   zProgressBar._update_bar   sf    KKNN1g&AjM"H(GHH5P6>NNV56>GD r   c                   ddl m} dt        | j                  |z        z  }t        d|z        } ||      }dj	                  || j                  ||      }t        j                  t              5  | j                  5| j                  j                  |       | j                  j                          d d d        y # 1 sw Y   y xY w)Nr   )r   #d   z"[{0:<{1}}] | {2}% Completed | {3})
dask.utilsr   intr   format
contextlibsuppress
ValueErrorr   r<   r2   )r   fracr>   r   barpercentmsgs          r   r:   zProgressBar._draw_bar   s    *Cd*++cDj/g&3::gw
   , 	#zz%

  %

  "	# 	# 	#s   /AB::C)r   (   g?N)__name__
__module____qualname____doc__r"   r/   r5   r?   r*   r;   r:    r   r   r   r       s,    /b

!E#r   r   )
__future__r   rV   r   r(   rA   timeitr   dask.callbacksr   rS   r   r   r   rb   r   r   <module>rf      sH    "  
     # " :3KL M$y#( y#r   