o
    h|                     @   s   d dl mZ ddlmZmZmZmZ G dd deZG dd deZG dd	 d	eZ	G d
d deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )    )Union   )AscDescReducerSortDirectionc                       s*   e Zd ZdZdeddf fddZ  ZS )FieldOnlyReducerzHSee https://redis.io/docs/interact/search-and-query/search/aggregations/fieldreturnNc                    s   t  | || _d S N)super__init___fieldselfr	   	__class__ `/var/www/html/optinet_system/venv/lib/python3.10/site-packages/redis/commands/search/reducers.pyr   	   s   
zFieldOnlyReducer.__init__)__name__
__module____qualname____doc__strr   __classcell__r   r   r   r   r      s    r   c                       s&   e Zd ZdZdZd fddZ  ZS )countz3
    Counts the number of results in the group
    COUNTr
   Nc                    s   t    d S r   r   r   )r   r   r   r   r      s   zcount.__init__)r
   N)r   r   r   r   NAMEr   r   r   r   r   r   r      s    r   c                       .   e Zd ZdZdZdeddf fddZ  ZS )sumzS
    Calculates the sum of all the values in the given fields within the group
    SUMr	   r
   Nc                       t  | d S r   r   r   r   r   r   r          zsum.__init__r   r   r   r   r   r   r   r   r   r   r   r   r           r    c                       r   )minzK
    Calculates the smallest value in the given field within the group
    MINr	   r
   Nc                    r"   r   r   r   r   r   r   r   +   r#   zmin.__init__r$   r   r   r   r   r&   $   r%   r&   c                       r   )maxzJ
    Calculates the largest value in the given field within the group
    MAXr	   r
   Nc                    r"   r   r   r   r   r   r   r   6   r#   zmax.__init__r$   r   r   r   r   r(   /   r%   r(   c                       r   )avgzG
    Calculates the mean value in the given field within the group
    AVGr	   r
   Nc                    r"   r   r   r   r   r   r   r   A   r#   zavg.__init__r$   r   r   r   r   r*   :   r%   r*   c                       r   )tolistz6
    Returns all the matched properties in a list
    TOLISTr	   r
   Nc                    r"   r   r   r   r   r   r   r   L   r#   ztolist.__init__r$   r   r   r   r   r,   E   r%   r,   c                       r   )count_distinctzs
    Calculate the number of distinct values contained in all the results in
    the group for the given field
    COUNT_DISTINCTr	   r
   Nc                    r"   r   r   r   r   r   r   r   X   r#   zcount_distinct.__init__r$   r   r   r   r   r.   P   s    r.   c                   @   s   e Zd ZdZdZdS )count_distinctishz
    Calculate the number of distinct values contained in all the results in the
    group for the given field. This uses a faster algorithm than
    `count_distinct` but is less accurate
    COUNT_DISTINCTISHN)r   r   r   r   r   r   r   r   r   r0   \   s    r0   c                       2   e Zd ZdZdZdededdf fddZ  ZS )	quantilezp
    Return the value for the nth percentile within the range of values for the
    field within the group.
    QUANTILEr	   pctr
   Nc                    s   t  |t| || _d S r   )r   r   r   r   )r   r	   r5   r   r   r   r   n   s   
zquantile.__init__)	r   r   r   r   r   r   floatr   r   r   r   r   r   r3   f   s    "r3   c                       r   )stddevzG
    Return the standard deviation for the values within the group
    STDDEVr	   r
   Nc                    r"   r   r   r   r   r   r   r   z   r#   zstddev.__init__r$   r   r   r   r   r7   s   r%   r7   c                       s:   e Zd ZdZdZdedeeef ddf fddZ	  Z
S )	first_valuezR
    Selects the first value within the group according to sorting parameters
    FIRST_VALUEr	   byfieldsr
   Nc                    s   g }t |dkrt|d trt|d tr|d |g}|D ]
}||j|jg7 }q|g}|r6|dg| 7 }t j|  || _	dS )a  
        Selects the first value of the given field within the group.

        ### Parameter

        - **field**: Source field used for the value
        - **byfields**: How to sort the results. This can be either the
            *class* of `aggregation.Asc` or `aggregation.Desc` in which
            case the field `field` is also used as the sort input.

            `byfields` can also be one or more *instances* of `Asc` or `Desc`
            indicating the sort order for these fields
        r   r   BYN)
len
isinstancetype
issubclassr   r	   	DIRSTRINGr   r   r   )r   r	   r;   	fieldstrsfargsr   r   r   r      s   
zfirst_value.__init__)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r9   ~   s    *r9   c                       r2   )	random_samplezT
    Returns a random sample of items from the dataset, from the given property
    RANDOM_SAMPLEr	   sizer
   Nc                    s"   |t |g}t j|  || _dS )z
        ### Parameter

        **field**: Field to sample from
        **size**: Return this many items (can be less)
        N)r   r   r   r   )r   r	   rG   rD   r   r   r   r      s   
zrandom_sample.__init__)	r   r   r   r   r   r   intr   r   r   r   r   r   rE      s    "rE   N)typingr   aggregationr   r   r   r   r   r   r    r&   r(   r*   r,   r.   r0   r3   r7   r9   rE   r   r   r   r   <module>   s    
(