o
    e                     @  s   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	Z
ddlmZmZ ddlmZ ddlmZmZ dd	lmZ ed
 e G dd deeeZdS )zgr.Timeseries() component.    )annotations)Path)AnyCallableLiteralN)documentset_documentation_group)JSONSerializable)IOComponent	_Keywords)
Changeable	componentc                   @  s   e Zd ZdZ	d1ddddddddddddddd2ddZd d! Zeejddddddddf	d3d#d$Z	d4d(d)Z
d5d+d,Zd6d/d0ZdS )7
Timeseriesa  
    Creates a component that can be used to upload/preview timeseries csv files or display a dataframe consisting of a time series graphically.
    Preprocessing: passes the uploaded timeseries data as a {pandas.DataFrame} into the function
    Postprocessing: expects a {pandas.DataFrame} or {str} path to a csv to be returned, which is then displayed as a timeseries graph
    Examples-format: a {str} filepath of csv data with time series data.
    Demos: fraud_detector
    NT   )xycolorslabelevery
show_label	containerscale	min_widthinteractivevisibleelem_idelem_classesvaluestr | Callable | Noner   
str | Noner   str | list[str] | Noner   list[str] | Noner   r   float | Noner   bool | Noner   boolr   
int | Noner   intr   r   r   r   list[str] | str | Nonec                K  sP   || _ t|tr|g}|| _|| _tj| f|||||	|
|||||d| dS )a	  
        Parameters:
            value: File path for the timeseries csv file. If callable, the function will be called whenever the app loads to set the initial value of the component.
            x: Column name of x (time) series. None if csv has no headers, in which case first column is x series.
            y: Column name of y series, or list of column names if multiple series. None if csv has no headers, in which case every column after first is a y series.
            label: component name in interface.
            every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
            colors: an ordered list of colors to use for each line plot
            show_label: if True, will display label.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            interactive: if True, will allow users to upload a timeseries csv; if False, can only be used to display timeseries data. If not provided, this is inferred based on whether the component is used as an input or output.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
        )r   r   r   r   r   r   r   r   r   r   r   N)r   
isinstancestrr   r   r
   __init__)selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   kwargs r-   LD:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/timeseries.pyr*      s,   $

zTimeseries.__init__c                 C  s    | j | j| j| jdt| S )N)r   r   r   r   )r   r   r   r   r
   
get_config)r+   r-   r-   r.   r/   U   s   zTimeseries.get_config(Any | Literal[_Keywords.NO_VALUE] | Nonec	           	      C  s   ||||||||| dd
S )Nupdate)
r   r   r   r   r   r   r   r   r   Z__type__r-   )	r   r   r   r   r   r   r   r   r   r-   r-   r.   r1   ^   s   zTimeseries.updatedict | Nonereturnpd.DataFrame | Nonec                 C  s   |du r|S | drt|d }ntj|d |d d}| ddurE|j|| jp,d |d d k }|j|| jp<d |d d	 k }|S )
a  
        Parameters:
            x: Dict with keys 'data': 2D array of str, numeric, or bool data, 'headers': list of strings for header names, 'range': optional two element list designating start of end of subrange.
        Returns:
            Dataframe of timeseries data
        Nis_filenamedataheaders)r7   columnsranger      )getpdread_csv	DataFramelocr   )r+   r   	dataframer-   r-   r.   
preprocessw   s   
  zTimeseries.preprocessstr | pd.DataFrame | Nonec                 C  sd   |du rdS t |trt|}|jj |j dS t |tjr.|jj |j dS td)z
        Parameters:
            y: csv or dataframe with timeseries data
        Returns:
            JSON object with key 'headers' for list of header names, 'data' for 2D array of string or numeric data
        N)r8   r7   z'Cannot process value as Timeseries data)	r(   r)   r=   r>   r9   valuestolistr?   
ValueError)r+   r   rA   r-   r-   r.   postprocess   s   


zTimeseries.postprocess
input_datar)   c                 C  s   |rt |jS dS )N )r   r6   )r+   rH   r-   r-   r.   
as_example   s   zTimeseries.as_example)N)r   r   r   r   r   r    r   r!   r   r   r   r"   r   r#   r   r$   r   r%   r   r&   r   r#   r   r$   r   r   r   r'   )r   r0   r   r!   r   r   r   r#   r   r#   r   r%   r   r%   r   r#   r   r#   )r   r2   r3   r4   )r   rC   r3   r2   )rH   r   r3   r)   )__name__
__module____qualname____doc__r*   r/   staticmethodr   ZNO_VALUEr1   rB   rG   rJ   r-   r-   r-   r.   r      sB    
9	

r   )rN   
__future__r   pathlibr   typingr   r   r   Zpandasr=   Zgradio_client.documentationr   r   Zgradio_client.serializingr	   Zgradio.components.baser
   r   Zgradio.eventsr   r   r-   r-   r-   r.   <module>   s    