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m	Z	 d dl
mZ d dlmZmZ d dlmZ dd ZdddZG dd deZd
deejd d
fdeejdfdejffd dfddZG dd deZdS )    )absolute_importprint_functiondivisionN)OrderedDict)partial)xrange	text_type)Tablec                  C   s"   t t  } t|  }|S )z^
    Obtain the hex digest of a sha256 hash of the
    current epoch time in nanoseconds.
    )strtimeencodehashlibsha256	hexdigest)time_ns	hash_time r   I/var/www/Datamplify/venv/lib/python3.10/site-packages/petl/util/random.py
randomseed   s   r      d   c                 C      t | |||dS )an  
    Construct a table with random numerical data. Use `numflds` and `numrows` to
    specify the number of fields and rows respectively. Set `wait` to a float
    greater than zero to simulate a delay on each row generation (number of
    seconds per row). E.g.::

        >>> import petl as etl
        >>> table = etl.randomtable(3, 100, seed=42)
        >>> table
        +----------------------+----------------------+---------------------+
        | f0                   | f1                   | f2                  |
        +======================+======================+=====================+
        |   0.6394267984578837 | 0.025010755222666936 | 0.27502931836911926 |
        +----------------------+----------------------+---------------------+
        |  0.22321073814882275 |   0.7364712141640124 |  0.6766994874229113 |
        +----------------------+----------------------+---------------------+
        |   0.8921795677048454 |  0.08693883262941615 |  0.4219218196852704 |
        +----------------------+----------------------+---------------------+
        | 0.029797219438070344 |  0.21863797480360336 |  0.5053552881033624 |
        +----------------------+----------------------+---------------------+
        | 0.026535969683863625 |   0.1988376506866485 |  0.6498844377795232 |
        +----------------------+----------------------+---------------------+
        ...
        <BLANKLINE>

    Note that the data are generated on the fly and are not stored in memory,
    so this function can be used to simulate very large tables.
    The only supported seed types are: None, int, float, str, bytes, and bytearray.

    )waitseed)RandomTable)numfldsnumrowsr   r   r   r   r   randomtable   s    r   c                   @   s&   e Zd ZdddZdd Zd	d
 ZdS )r   r   r   r   Nc                 C   s0   || _ || _|| _|d u rt | _d S || _d S N)r   r   r   r   r   )selfr   r   r   r   r   r   r   __init__<   s   
zRandomTable.__init__c                 c   sv    | j }| j}| j}t| dd t|D }t|V  t|D ]}| jr,t	| j tdd t|D V  q!d S )Nc                 S   s   g | ]}d | qS )zf%sr   .0nr   r   r   
<listcomp>N   s    z(RandomTable.__iter__.<locals>.<listcomp>c                 s   s    | ]}t  V  qd S r   )pyrandomrandomr!   r   r   r   	<genexpr>V       z'RandomTable.__iter__.<locals>.<genexpr>)
r   r   r   r%   rangetupler   r   r   sleep)r   nfnrr   flds_r   r   r   __iter__E   s   

zRandomTable.__iter__c                 C      t  | _d S r   r   r   r   r   r   r   reseedX      zRandomTable.reseedr   r   r   N)__name__
__module____qualname__r    r0   r4   r   r   r   r   r   ;   s    
	r   foobar)applespearsbananasorangesbazc                 C   r   )a	  
    Construct a table with dummy data. Use `numrows` to specify the number of
    rows. Set `wait` to a float greater than zero to simulate a delay on each
    row generation (number of seconds per row). E.g.::

        >>> import petl as etl
        >>> table1 = etl.dummytable(100, seed=42)
        >>> table1
        +-----+----------+----------------------+
        | foo | bar      | baz                  |
        +=====+==========+======================+
        |  81 | 'apples' | 0.025010755222666936 |
        +-----+----------+----------------------+
        |  35 | 'pears'  |  0.22321073814882275 |
        +-----+----------+----------------------+
        |  94 | 'apples' |   0.6766994874229113 |
        +-----+----------+----------------------+
        |  69 | 'apples' |   0.5904925124490397 |
        +-----+----------+----------------------+
        |   4 | 'apples' |  0.09369523986159245 |
        +-----+----------+----------------------+
        ...
        <BLANKLINE>

        >>> import random as pyrandom
        >>> from functools import partial
        >>> fields = [('foo', pyrandom.random),
        ...           ('bar', partial(pyrandom.randint, 0, 500)),
        ...           ('baz', partial(pyrandom.choice, ['chocolate', 'strawberry', 'vanilla']))]
        >>> table2 = etl.dummytable(100, fields=fields, seed=42)
        >>> table2
        +---------------------+-----+-------------+
        | foo                 | bar | baz         |
        +=====================+=====+=============+
        |  0.6394267984578837 |  12 | 'vanilla'   |
        +---------------------+-----+-------------+
        | 0.27502931836911926 | 114 | 'chocolate' |
        +---------------------+-----+-------------+
        |  0.7364712141640124 | 346 | 'vanilla'   |
        +---------------------+-----+-------------+
        |  0.8921795677048454 |  44 | 'vanilla'   |
        +---------------------+-----+-------------+
        |  0.4219218196852704 |  15 | 'chocolate' |
        +---------------------+-----+-------------+
        ...
        <BLANKLINE>

        >>> table3_1 = etl.dummytable(50)
        >>> table3_2 = etl.dummytable(100)
        >>> table3_1[5] == table3_2[5]
        False

    Data generation functions can be specified via the `fields` keyword
    argument.

    Note that the data are generated on the fly and are not stored in memory,
    so this function can be used to simulate very large tables.
    The only supported seed types are: None, int, float, str, bytes, and bytearray.

    r   fieldsr   r   )
DummyTablerA   r   r   r   
dummytable\   s   GrD   c                   @   s.   e Zd ZdddZdd Zdd	 Zd
d ZdS )rC   r   Nr   c                 C   sF   || _ || _|d u rt | _nt|| _|d u rt | _d S || _d S r   )r   r   r   rB   r   r   )r   r   rB   r   r   r   r   r   r       s   


zDummyTable.__init__c                 C   s   || j t|< d S r   )rB   r   )r   itemvaluer   r   r   __setitem__   s   zDummyTable.__setitem__c                 #   sz    | j }| j}| j  t| tdd   D }|V  t|D ]}| jr.t	
| j t fdd D V  q#d S )Nc                 s   s    | ]}t |V  qd S r   )r   r"   fr   r   r   r'      r(   z&DummyTable.__iter__.<locals>.<genexpr>c                 3   s    | ]} |  V  qd S r   r   rH   rB   r   r   r'      s    )r   r   rB   copyr%   r*   keysr   r   r   r+   )r   r-   r   hdrr/   r   rJ   r   r0      s   

zDummyTable.__iter__c                 C   r1   r   r2   r3   r   r   r   r4      r5   zDummyTable.reseed)r   Nr   N)r7   r8   r9   r    rG   r0   r4   r   r   r   r   rC      s
    
rC   r6   )
__future__r   r   r   r   r&   r%   r   collectionsr   	functoolsr   petl.compatr   r   petl.util.baser	   r   r   r   randintchoicerD   rC   r   r   r   r   <module>   s(    
#"
J