
    ]ju                      n    d Z ddlmZ dZ G d d      Z G d d      Z G d d	      Z G d
 d      Zd Zy)a   # Data Manager module for the Label Studio SDK

    Classes can be used to filter, order, and select items in `label_studio_sdk.project.Project.get_tasks`
    and provides enumeration for all column names available in the Data Manager for tasks, and other helpers.

    See the [client](client.html), [project](project.html) or [utils](utils.html) modules for other operations you
    might want to perform.

    Example:

    ```python
    from label_studio_sdk.data_manager import Filters, Column, Operator, Type

    filters = Filters.create(Filters.OR, [
        Filters.item(
            Column.id,
            Operator.GREATER,
            Type.Number,
            Filters.value(42)
        ),
        Filters.item(
            Column.completed_at,
            Operator.IN,
            Type.Datetime,
            Filters.value(
                datetime(2021, 11, 1),
                datetime.now()
            )
        )
    ])
    tasks = project.get_tasks(filters=filters)
    ```
    )datetimez%Y-%m-%dT%H:%M:%S.%fZc                   ^    e Zd ZdZdZ	 dZ	 ed        Zed        Zed        Z	e
d	d       Zy)
Filtersz
    Use the methods and variables in this class to create and combine filters for tasks on the Label Studio Data Manager.
    orandc                     | |dS )a  Create a filter for `label_studio_sdk.project.Project.get_tasks()`

        Parameters
        ----------
        conjunction: str
            The conjunction operator between filters ('or' or 'and')
        items: list
            What to filter, use `Filter.item()` method to build it

        Returns
        -------
        dict
            containing specified parameters

        conjunctionitems r	   s     G/root/env/lib/python3.12/site-packages/label_studio_sdk/data_manager.pycreatezFilters.create2   s    "  +U;;    c                     d| z   |||dS )aU  Use in combination with other classes to specify the contents of a filter.

        Parameters
        ----------
        name: `Column` or str
            Column.id, Column.completed_at, Column.data('my_field'), etc
        operator: `Operator`
            Operator.EQUAL, Operator.GREATER_OR_EQUAL, Operator.IN, etc
        column_type: `Type`
            Type.Number, Type.Boolean, Type.String, etc
        value: `Filters.value()`
            Filters.value(42), Filters.value('test'), Filters.value(datetime(2021, 01, 01), datetime.now())

        Returns
        -------
        dict
        zfilter:filteroperatortypevaluer   )namer   column_typer   s       r   itemzFilters.itemE   s    (  $& 	
 	
r   c                 Z    t        | t              sJ d       | j                  t              S )zDate time string format for filtering the Data Manager.

        Parameters
        ----------
        dt
            datetime instance

        Returns
        -------
        str
            datetime in `'%Y-%m-%dT%H:%M:%S.%fZ'` format

        zdt must be datetime type)
isinstancer   strftimeDATETIME_FORMAT)dts    r   r   zFilters.datetime_   s)     "h'C)CC'{{?++r   Nc                     t        |t              r| j                  |      }|&t        |t              r| j                  |      }||dS |S )a  Set a filter value in the Data Manager.

        Parameters
        ----------
        value: str | int | float | datetime | boolean
            value to use for filtering. If the maximum parameter is passed, then this value field is the minimum.

        maximum: int | float  | datetime
            Specify a maximum for a filtering range with IN, NOT_IN operators.

        Returns
        -------
        any
            value for filtering

        minmax)r   r   )clsr   maximums      r   r   zFilters.valueq   sJ    $ eX&LL'E'8,,,w/ 11r   )N)__name__
__module____qualname____doc__ORANDstaticmethodr   r   r   classmethodr   r   r   r   r   r   (   sg     
B$
C%< <$ 
 
2 , ,"  r   r   c                   H    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZy)Operatorz3Specify the operator to use when creating a filter.equal	not_equallessgreaterless_or_equalgreater_or_equalinnot_inin_listnot_in_listemptycontainsnot_containsregexN)r$   r%   r&   r'   EQUAL	NOT_EQUALLESSGREATERLESS_OR_EQUALGREATER_OR_EQUALINNOT_ININ_LISTNOT_IN_LISTEMPTYCONTAINSNOT_CONTAINSREGEXr   r   r   r-   r-      sL    =EIDG#M)	BFGKEH!LEr   r-   c                   (    e Zd ZdZdZdZdZdZdZdZ	y)	Typez%Specify the type of data in a column.NumberDatetimeBooleanStringListUnknownN)
r$   r%   r&   r'   rL   rM   rN   rO   rP   rQ   r   r   r   rK   rK      s&    /FHGFDG=r   rK   c                       e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ		 dZ
	 d	Z	 d
Z	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 ed        Zy)ColumnzOSpecify the column on the Data Manager in Label Studio UI to use in the filter.ztasks:idztasks:inner_idztasks:ground_truthztasks:annotations_resultsztasks:reviewedztasks:predictions_scorez tasks:predictions_model_versionsztasks:predictions_resultsztasks:file_uploadztasks:created_atztasks:updated_atztasks:annotatorsztasks:total_predictionsztasks:cancelled_annotationsztasks:total_annotationsztasks:completed_atztasks:agreementztasks:reviewersztasks:reviews_rejectedztasks:reviews_acceptedztasks:commentsztasks:unresolved_comment_countc                     d| z   S )zCreate a filter name for the task data field

        Parameters
        ----------
        task_field

        Returns
        -------
        str
            Filter name for task data

        ztasks:data.r   )
task_fields    r   datazColumn.data   s     z))r   N)r$   r%   r&   r'   idinner_idground_truthannotations_resultsreviewedpredictions_scorepredictions_model_versionspredictions_resultsfile_upload
created_at
updated_at
annotatorstotal_predictionscancelled_annotationstotal_annotationscompleted_at	agreement	reviewersreviews_rejectedreviews_acceptedcommentsunresolved_comment_countr*   rV   r   r   r   rS   rS      s    Y	BH:'L*5*H@1'!C05*%K7#J&#J[#Jk129A1/'L.!IP!IS/O/OH&?1* *r   rS   c                     t         j                  t         j                  t         j                  t        j
                  t        j                  t        j                  t         j                  d            t         j                  t        j                  t        j                  t        j                  t         j                  t        ddd      t        ddd                  g      } | dddd	dd
ddddddd
gdk(  sJ y)zTest it*   i           r   zfilter:tasks:idr1   rL   r   zfilter:tasks:completed_atr4   rM   z2021-11-01T00:00:00.000000Zz2021-11-05T00:00:00.000000Zr   r	   N)r   r   r(   r   rS   rW   r-   r?   rK   rL   r   rf   rB   rM   r   )filterss    r   _testrs      s    nn

LLH$4$4dkk7==QSCTULL##T2q)T2q)		
G   ,% 	 6 "88	
   r   N)r'   r   r   r   r-   rK   rS   rs   r   r   r   <module>rt      sF    D )c cL &
> 
>>* >*B%r   