o
    ;Di%                     @   s   d dl mZmZ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 ddd	Zdddejfd
dZee_ee_G dd deZG dd deZG dd deZdd Zee_G dd deZdS )    )absolute_importprint_functiondivisionN)PY3)Table)onlinestats   c                 C   s   t | |||S )a  
    Report progress on rows passing through to a file or file-like object
    (defaults to sys.stderr). E.g.::

        >>> import petl as etl
        >>> table = etl.dummytable(100000)
        >>> table.progress(10000).tocsv('example.csv')  # doctest: +SKIP
        10000 rows in 0.13s (78363 row/s); batch in 0.13s (78363 row/s)
        20000 rows in 0.22s (91679 row/s); batch in 0.09s (110448 row/s)
        30000 rows in 0.31s (96573 row/s); batch in 0.09s (108114 row/s)
        40000 rows in 0.40s (99535 row/s); batch in 0.09s (109625 row/s)
        50000 rows in 0.49s (101396 row/s); batch in 0.09s (109591 row/s)
        60000 rows in 0.59s (102245 row/s); batch in 0.09s (106709 row/s)
        70000 rows in 0.68s (103221 row/s); batch in 0.09s (109498 row/s)
        80000 rows in 0.77s (103810 row/s); batch in 0.09s (108126 row/s)
        90000 rows in 0.90s (99465 row/s); batch in 0.13s (74516 row/s)
        100000 rows in 1.02s (98409 row/s); batch in 0.11s (89821 row/s)
        100000 rows in 1.02s (98402 row/s); batches in 0.10 +/- 0.02s [0.09-0.13] (100481 +/- 13340 rows/s [74516-110448])

    See also :func:`petl.util.timing.clock`.

    )ProgressView)table	batchsizeprefixout r   I/var/www/Datamplify/venv/lib/python3.10/site-packages/petl/util/timing.pyprogress   s   r   c                 C   s   t | ||||dS )a  
    Report progress on rows passing through to a python logger. If logger is
    none, a new logger will be created that, by default, streams to stdout. E.g.::

        >>> import petl as etl
        >>> table = etl.dummytable(100000)
        >>> table.log_progress(10000).tocsv('example.csv')  # doctest: +SKIP
        10000 rows in 0.13s (78363 row/s); batch in 0.13s (78363 row/s)
        20000 rows in 0.22s (91679 row/s); batch in 0.09s (110448 row/s)
        30000 rows in 0.31s (96573 row/s); batch in 0.09s (108114 row/s)
        40000 rows in 0.40s (99535 row/s); batch in 0.09s (109625 row/s)
        50000 rows in 0.49s (101396 row/s); batch in 0.09s (109591 row/s)
        60000 rows in 0.59s (102245 row/s); batch in 0.09s (106709 row/s)
        70000 rows in 0.68s (103221 row/s); batch in 0.09s (109498 row/s)
        80000 rows in 0.77s (103810 row/s); batch in 0.09s (108126 row/s)
        90000 rows in 0.90s (99465 row/s); batch in 0.13s (74516 row/s)
        100000 rows in 1.02s (98409 row/s); batch in 0.11s (89821 row/s)
        100000 rows in 1.02s (98402 row/s); batches in 0.10 +/- 0.02s [0.09-0.13] (100481 +/- 13340 rows/s [74516-110448])

    See also :func:`petl.util.timing.clock`.

    )level)LoggingProgressView)r   r   r   loggerr   r   r   r   log_progress*   s   r   c                   @   s.   e Zd ZdZdd Zejdd Zdd ZdS )	ProgressViewBasezA
    Abstract base class for reporting on proecessing status
    c                 C   s   || _ || _|| _d S N)innerr   r   )selfr   r   r   r   r   r   __init__N   s   
zProgressViewBase.__init__c                 C   s   d S r   r   r   messager   r   r   print_messageS   s   zProgressViewBase.print_messagec                 c   s\   t   }|}d}d\}}d\}}d\}}	t| jD ]\}
}|
| j dkr|
dkr|d7 }t   }|| }|d u s=||k r?|}|d u sG||krI|}|| }zt|
| }W n ty`   d}Y nw z	t| j| }W n tyu   d}Y nw |
||||f}| jd|  }| | |}t||||d\}}t||||	d\}}	|V  qt   }|| }zt|
| }W n ty   d}Y nw |dkr|d u rd}|d u rd}z	t| j| }W n ty   d}Y nw z	t| j| }W n ty   d}Y nw |
||||d ||t|t|	d t|t|f}| jd|  }n|
||f}| jd	|  }| | d S )
Nr   )NN)r   r      z6%s rows in %.2fs (%s row/s); batch in %.2fs (%s row/s))meanvarianceg      ?z]%s rows in %.2fs (%s row/s); batches in %.2f +/- %.2fs [%.2f-%.2f] (%s +/- %s rows/s [%s-%s])z%s rows in %.2fs (%s row/s))	time	enumerater   r   intZeroDivisionErrorr   r   r   )r   start
batchstartbatchnbatchtimeminbatchtimemaxbatchtimemeanbatchtimevarbatchratemeanbatchratevarnrbatchend	batchtimeelapsedtimerate	batchratevr   endbatchrateminbatchratemaxr   r   r   __iter__W   s   



zProgressViewBase.__iter__N)	__name__
__module____qualname____doc__r   abcabstractmethodr   r9   r   r   r   r   r   I   s    
r   c                       s(   e Zd ZdZ fddZdd Z  ZS )r
   zM
    Reports progress to a file_object like sys.stdout or a file handler
    c                    s0   |d u r	t j| _n|| _tt| ||| d S r   )sysstderrfile_objectsuperr
   r   )r   r   r   r   r   	__class__r   r   r      s   
zProgressView.__init__c                 C   s,   t || jd t| jdr| j  d S d S )N)fileflush)printrB   hasattrrG   r   r   r   r   r      s   zProgressView.print_message)r:   r;   r<   r=   r   r   __classcell__r   r   rD   r   r
      s    r
   c                       s.   e Zd ZdZejf fdd	Zdd Z  ZS )r   zC
    Reports progress to a logger, log handler, or log adapter
    c                    sF   |d u rt t| _| j| n|| _|| _tt| ||| d S r   )	logging	getLoggerr:   r   setLevelr   rC   r   r   )r   r   r   r   r   r   rD   r   r   r      s   zLoggingProgressView.__init__c                 C   s   | j | j| d S r   )r   logr   r   r   r   r   r      s   z!LoggingProgressView.print_message)	r:   r;   r<   r=   rK   INFOr   r   rJ   r   r   rD   r   r      s    	r   c                 C   s   t | S )a  
    Time how long is spent retrieving rows from the wrapped container. Enables
    diagnosis of which steps in a pipeline are taking the most time. E.g.::

        >>> import petl as etl
        >>> t1 = etl.dummytable(100000)
        >>> c1 = etl.clock(t1)
        >>> t2 = etl.convert(c1, 'foo', lambda v: v**2)
        >>> c2 = etl.clock(t2)
        >>> p = etl.progress(c2, 10000)
        >>> etl.tocsv(p, 'example.csv')  # doctest: +SKIP
        10000 rows in 0.23s (44036 row/s); batch in 0.23s (44036 row/s)
        20000 rows in 0.38s (52167 row/s); batch in 0.16s (63979 row/s)
        30000 rows in 0.54s (55749 row/s); batch in 0.15s (64624 row/s)
        40000 rows in 0.69s (57765 row/s); batch in 0.15s (64793 row/s)
        50000 rows in 0.85s (59031 row/s); batch in 0.15s (64707 row/s)
        60000 rows in 1.00s (59927 row/s); batch in 0.15s (64847 row/s)
        70000 rows in 1.16s (60483 row/s); batch in 0.16s (64051 row/s)
        80000 rows in 1.31s (61008 row/s); batch in 0.15s (64953 row/s)
        90000 rows in 1.47s (61356 row/s); batch in 0.16s (64285 row/s)
        100000 rows in 1.62s (61703 row/s); batch in 0.15s (65012 row/s)
        100000 rows in 1.62s (61700 row/s); batches in 0.16 +/- 0.02s [0.15-0.23] (62528 +/- 6173 rows/s [44036-65012])
        >>> # time consumed retrieving rows from t1
        ... c1.time  # doctest: +SKIP
        0.7243089999999492
        >>> # time consumed retrieving rows from t2
        ... c2.time  # doctest: +SKIP
        1.1704209999999766
        >>> # actual time consumed by the convert step
        ... c2.time - c1.time  # doctest: +SKIP
        0.4461120000000274

    See also :func:`petl.util.timing.progress`.

    )	ClockView)r   r   r   r   clock   s   %rQ   c                   @   s   e Zd Zdd Zdd ZdS )rP   c                 C   s
   || _ d S r   )wrapped)r   rR   r   r   r   r      s   
zClockView.__init__c                 c   sx    d| _ t| j}	 trt  nt  }zt|}W n
 ty$   Y d S w tr+t  nt  }|  j || 7  _ |V  q
)Nr   )r!   iterrR   r   perf_counterrQ   nextStopIteration)r   itbeforerowafterr   r   r   r9      s   
zClockView.__iter__N)r:   r;   r<   r   r9   r   r   r   r   rP      s    rP   )r   r	   N)
__future__r   r   r   r>   rK   r@   r!   petl.compatr   petl.util.baser   petl.util.statisticsr   r   rO   r   r   r
   r   rQ   rP   r   r   r   r   <module>   s$    
Y(