
    Mpj*,                     B   S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	J
r
Jr  S SKJr  S SKJrJr  0 r0 r " S S	5      r S S
KJrJrJrJr  S SKJr   " S S\5      r " S S5      r " S S\\5      r " S S\\5      r " S S\5      r  " S S5      r!g! \ a     Nf = f)    )Integral)Queue)Thread)get_context_path)close_listeneropen_listenersend)check_rich_support)Intervalvalidate_paramsc            
       d    \ rS rSrSr\" S\" \SSSS9S/0SS	9SS
 j5       rS r	S r
S rS rSrg)ProgressBar   aY  Callback that displays progress bars for each iterative step of an estimator.

Parameters
----------
max_propagation_depth : int, default=1
    The maximum depth of nested levels of estimators to display progress bars for.
    0 means that the progress of only the outermost estimator is displayed.
    If set to None, all levels are displayed.
max_propagation_depthr   Nleft)closedT)prefer_skip_nested_validationc                 4    [        S5        Xl        0 U l        g )NProgressbar)r
   r   _listener_handles)selfr   s     Y/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/sklearn/callback/_progressbar.py__init__ProgressBar.__init__   s    
 	=)%:" "$    c                     [        5       n[        UR                  5      U R                  UR                  '   [        US9nUR                  5         U[        UR                  '   U[        UR                  '   g )N)queue)	r   r   putr   	root_uuidRichProgressMonitorstart_run_queues_run_monitors)r   	estimatorcontextr   progress_monitors        r   setupProgressBar.setup+   sd      5B%))4Lw001.U; ).G%%&+;g''(r   c                 |   UR                   S:w  d  UR                  b  UR                  b  [        U5       Vs/ s H  o3R                  PM     nn[        U R                  UR                     SUUR                  UR                  UR                   UR                  UR                  UR                  S.5        g g s  snf )Nr   begin)eventpath	task_nametask_idmax_subtasksestimator_namesource_estimator_namesource_task_name)r/   parentr1   r   r.   r	   r   r   r-   r0   r2   )r   r$   r%   ctxr,   s        r   on_fit_task_beginProgressBar.on_fit_task_begin>   s       A%~~%,,8 ,<G+DE+DCKK+DDE&&w'8'89$ !(!2!2&$+$8$8&-&<&<-4-J-J(/(@(@	 9 Fs   B9c                     [        U R                  UR                     S[        U5       Vs/ s H  o3R                  PM     snS.5        g s  snf )Nend)r+   r,   )r	   r   r   r   r.   )r   r$   r%   r4   s       r   on_fit_task_endProgressBar.on_fit_task_endW   sG    ""7#4#450@0IJ0I0IJ	
 Ks   Ac                    [         R                  UR                  5      R                  S 5        [        R                  UR                  5      R                  5         [        U R                  R                  UR                  5      5        g N)r"   popr   r   r#   joinr   r   )r   r$   r%   s      r   teardownProgressBar.teardowna   s]     	))*..t4'++,113t--11'2C2CDEr   )r   r   )   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r'   r5   r9   r?   __static_attributes__ r   r   r   r      sP     	 8Haf#Mt"TU&*$	$<&2
Fr   r   )	BarColumnProgress
TextColumnTimeRemainingColumn)Stylec                       \ rS rSrS rSrg)	_Progressm   c              #   H   #    U R                  [        U S/ 5      5      v   g 7f)N_ordered_tasks)make_tasks_tablegetattrr   s    r   get_renderables_Progress.get_renderablesq   s      ''6F(KLLs    "rH   N)rB   rC   rD   rE   rV   rG   rH   r   r   rO   rO   m   s    	Mr   rO   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )_StyledColumnMixint   z8Apply finished/in-progress color style to rendered text.c                 h   > [         TU ]  U5      nUR                  (       a	  SUl        U$ SUl        U$ )N#29ABE2#F7931E)superrenderfinishedstyle)r   tasktext	__class__s      r   r_   _StyledColumnMixin.renderw   s2    7>$'D&*mmDJK :CDJKr   rH   )rB   rC   rD   rE   rF   r_   rG   __classcell__rd   s   @r   rY   rY   t   s    F	 	r   rY   c                       \ rS rSrSrSrg)_StyledTimeRemainingColumn|   zTime column with color styling.rH   NrB   rC   rD   rE   rF   rG   rH   r   r   ri   ri   |   s    -r   ri   c                       \ rS rSrSrSrg)_StyledPercentageColumn   z%Percentage column with color styling.rH   Nrk   rH   r   r   rm   rm      s    3r   rm   c                   >   ^  \ rS rSrSrU 4S jrS rS rS rSr	U =r
$ )r       a;  Thread monitoring the progress of an estimator with rich based display.

The display is a list of nested rich tasks using `rich.Progress`. There is one for
each non-leaf node in the task tree of the estimator.

Parameters
----------
queue : `queue.Queue` instance
    This thread will run until the queue is empty.
c                .   > [         TU ]  5         Xl        g r<   )r^   r   r   )r   r   rd   s     r   r   RichProgressMonitor.__init__   s    
r   c                    [        [        S5      [        [        SS9[        SS9[        SS9S9[	        S5      [        SS95      U l        S U l        U R                     U R                  R                  5       =n(       a[  UR                  S	5      S
:X  a  U R                  U5        OU R                  U5        U R                  R                  5       =n(       a  M[  U R                  R                  5         S S S 5        g ! , (       d  f       g = f)Nz([progress.description]{task.description}r]   )colorr\   )complete_stylefinished_stylepulse_stylez{task.percentage:>3.0f}%T)elapsed_when_finishedr+   r*   )rO   rK   rI   rM   rm   ri   progress_ctxroot_rich_taskr   getr=   _on_task_begin_on_task_endrefresh)r   	task_infos     r   runRichProgressMonitor.run   s    %AB$95$95!	2
 $$>?&TB	
 ##zz~~//)/==)W4''	2%%i0	  $zz~~//)/ %%' s   A;C>C>>
Dc                    UR                  S5      n[        U R                  U[        U5      S-
  S9nUR                  S:X  a  X0l        O/U R
                  R                  U5      S   nX4R                  US   '   U R
                   Vs/ s H%  oPR                  R                  UR                     PM'     snU R                  l
        gs  snf )zHCreate a progress bar for the task and update the list of ordered tasks.r,   rA   )ry   r   depthr   N)r=   RichTaskry   lenr   rz   get_descendantschildrentasksidrR   )r   r   r,   	rich_taskr3   rb   s         r   r|   "RichProgressMonitor._on_task_begin   s    }}V$**is4yST}
	 ??a"+((88>rBF(1OODH% :>9L9L,
9L##DGG,9L,
( ,
s   ,Cc                    UR                  S5      nU R                  R                  U5      Gt p4Uc3  [        U R                  U[        U5      S9nXCS   R                  US   '   O6UR                  Ul        U R                  R                  UR                  SSS9  [        U5       HO  nUR                  c  M  UR                  UR                  -  nU R                  R                  UR                  US9  MQ     g)z>Update the progress of the task and its ancestors recursively.r,   Nr   r   rA   )	completedtotal)r   )r=   rz   r   r   ry   r   r   r   r   updater   reversedprogress)r   r   r,   	ancestorsrb   ancestorr   s          r   r}    RichProgressMonitor._on_task_end   s    }}V$..>>tD<D--yIOD/3bM""48, "ZZDN$$TWW$C +H~~% ))HNN:I$$X[[I$F ,r   )ry   r   rz   )rB   rC   rD   rE   rF   r   r   r|   r}   rG   rf   rg   s   @r   r    r       s#    	(2
"G Gr   r    c                   @    \ rS rSrSrS r\S 5       rS rS r	S r
Srg	)
r      aa  A task, i.e. progressbar, in the tree of rich tasks.

There is a rich task for each non-leaf task in the context tree of the estimator.

Parameters
----------
progress_ctx : `rich.Progress` instance
    The progress context to which this task belongs.

task_info : dict
    Information about the task for which this rich task is created.

depth : int
    The depth of the task in the tree of rich tasks.

Attributes
----------
completed : int
    The number of completed subtasks.

total : int or None
    The total number of subtasks. None if the total number of subtasks is not known.

progress : float
    The fraction, between 0 and 1, of the task that is completed.

id : int
    The ID of the task in the Progress context.

children : dict
    A mapping from the index of a child to the child node `{idx: RichTask}`.
    For a leaf, it's an empty dictionary.
c                    0 U l         X0l        SU l        UR                  SS5      U l        U(       a0  U R                  U5      nUR                  X@R                  S9U l        g g )Nr   r/   )r   )r   r   r   r=   r   _format_task_descriptionadd_taskr   )r   ry   r   r   descriptions        r   r   RichTask.__init__   sX    
]]>15
77	BK"++Kzz+JDG r   c                     U R                   U R                  :X  a  gU R                  c  g[        S U R                  R	                  5        5       5      U R                  -  $ )z2Return the fraction of the task that is completed.g      ?g        c              3   8   #    U  H  oR                   v   M     g 7fr<   )r   ).0childs     r   	<genexpr>$RichTask.progress.<locals>.<genexpr>  s     F/Ee>>/Es   )r   r   sumr   valuesrU   s    r   r   RichTask.progress  sK     >>TZZ'::Ft}}/C/C/EFFSSr   c                     SU R                   -   nUS    SUS    3nU R                   S:  a  SUS    3OSnUS	   b  US	    SUS
    S3OSnU U U U 3$ )z,Return a formatted description for the task.z  r0   z - r-   r   z #r.    r1   r2   z | r   )r   r   indent	task_descid_marksource_task_descs         r   r   !RichTask._format_task_description  s    4::%& !1233y7M6NO	15aBy+,-R 01= 012#i@R6S5TTWX 	
 *+I;wi@@r   c                     [        U5      S:X  a  U /$ US   U R                  ;  a  U S/$ U /U R                  US      R                  USS 5      -   $ )z;Return the descendants from this task along the given path.rA   N)r   r   r   )r   r,   s     r   r   RichTask.get_descendants  sY    t9>6M7$--'$<vd1g.>>tABxHHHr   c              #      #    [        U S5      (       a0  U v   U R                  R                  5        H  nU Sh  vN   M     gg N
7f)zJPre-order depth-first traversal, only including tasks with a progress bar.r   N)hasattrr   r   )r   r   s     r   __iter__RichTask.__iter__!  sA     4J--/    0  !s   8AAA)r   r   r   r   r   N)rB   rC   rD   rE   rF   r   propertyr   r   r   r   rG   rH   r   r   r   r      s5     DK T T
AI!r   r   N)"numbersr   r   r   	threadingr   "sklearn.callback._callback_contextr   sklearn.callback._transportr   r   r	   $sklearn.utils._optional_dependenciesr
   sklearn.utils._param_validationr   r   r"   r#   r   rich.progressrI   rJ   rK   rL   
rich.stylerM   rO   rY   ri   rm   ImportErrorr    r   rH   r   r   <module>r      s       ? K K C E
 RF RFj	RR MH M .%79L .4"4j 4NG& NGbO! O!k  		s    ?B BB