
    +h|                     F   d dl mZ ddlmZmZmZmZ  G d de      Z G d de      Z G d d	e      Z	 G d
 de      Z
 G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    )Union   )AscDescReducerSortDirectionc                   ,     e Zd ZdZdeddf fdZ xZS )FieldOnlyReducerzHSee https://redis.io/docs/interact/search-and-query/search/aggregations/fieldreturnNc                 2    t         |   |       || _        y N)super__init___fieldselfr   	__class__s     Q/var/www/html/venv/lib/python3.12/site-packages/redis/commands/search/reducers.pyr   zFieldOnlyReducer.__init__	   s        )__name__
__module____qualname____doc__strr   __classcell__r   s   @r   r
   r
      s    Rc d  r   r
   c                   (     e Zd ZdZdZd fdZ xZS )countz3
    Counts the number of results in the group
    COUNTc                 "    t         |           y r   r   r   )r   r   s    r   r   zcount.__init__   s    r   )r   N)r   r   r   r   NAMEr   r   r   s   @r   r   r      s     D r   r   c                   0     e Zd ZdZdZdeddf fdZ xZS )sumzS
    Calculates the sum of all the values in the given fields within the group
    SUMr   r   Nc                 $    t         |   |       y r   r"   r   s     r   r   zsum.__init__        r   r   r   r   r   r#   r   r   r   r   s   @r   r%   r%      '     D c  d    r   r%   c                   0     e Zd ZdZdZdeddf fdZ xZS )minzK
    Calculates the smallest value in the given field within the group
    MINr   r   Nc                 $    t         |   |       y r   r"   r   s     r   r   zmin.__init__+   r(   r   r)   r   s   @r   r,   r,   $   r*   r   r,   c                   0     e Zd ZdZdZdeddf fdZ xZS )maxzJ
    Calculates the largest value in the given field within the group
    MAXr   r   Nc                 $    t         |   |       y r   r"   r   s     r   r   zmax.__init__6   r(   r   r)   r   s   @r   r0   r0   /   r*   r   r0   c                   0     e Zd ZdZdZdeddf fdZ xZS )avgzG
    Calculates the mean value in the given field within the group
    AVGr   r   Nc                 $    t         |   |       y r   r"   r   s     r   r   zavg.__init__A   r(   r   r)   r   s   @r   r4   r4   :   r*   r   r4   c                   0     e Zd ZdZdZdeddf fdZ xZS )tolistz6
    Returns all the matched properties in a list
    TOLISTr   r   Nc                 $    t         |   |       y r   r"   r   s     r   r   ztolist.__init__L   r(   r   r)   r   s   @r   r8   r8   E   '     D c  d    r   r8   c                   0     e Zd ZdZdZdeddf fdZ xZS )count_distinctzs
    Calculate the number of distinct values contained in all the results in
    the group for the given field
    COUNT_DISTINCTr   r   Nc                 $    t         |   |       y r   r"   r   s     r   r   zcount_distinct.__init__X   r(   r   r)   r   s   @r   r=   r=   P   s'    
 D c  d    r   r=   c                       e Zd ZdZdZy)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   rA   rA   \   s     Dr   rA   c                   4     e Zd ZdZdZdededdf fdZ xZS )quantilezp
    Return the value for the nth percentile within the range of values for the
    field within the group.
    QUANTILEr   pctr   Nc                 F    t         |   |t        |             || _        y r   )r   r   r   r   )r   r   rG   r   s      r   r   zquantile.__init__n   s    C)r   )	r   r   r   r   r#   r   floatr   r   r   s   @r   rE   rE   f   s.    
 Dc  $  r   rE   c                   0     e Zd ZdZdZdeddf fdZ xZS )stddevzG
    Return the standard deviation for the values within the group
    STDDEVr   r   Nc                 $    t         |   |       y r   r"   r   s     r   r   zstddev.__init__z   r(   r   r)   r   s   @r   rK   rK   s   r;   r   rK   c                   >     e Zd ZdZdZdedeeef   ddf fdZ	 xZ
S )first_valuezR
    Selects the first value within the group according to sorting parameters
    FIRST_VALUEr   byfieldsr   Nc                    g }t        |      dk(  r2t        |d   t              rt        |d   t              r |d   |      g}|D ]  }||j
                  |j                  gz  } |g}|r	|dg|z   z  }t        |    |  || _	        y)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   rQ   	fieldstrsfargsr   s         r   r   zfirst_value.__init__   s     	MQ8A;-8A;6#E*+H 	0A!''1;;//I	0 wTFY&&D$r   )r   r   r   r   r#   r   r   r   r   r   r   r   s   @r   rO   rO   ~   s7     Dc eCI.> 4  r   rO   c                   4     e Zd ZdZdZdededdf fdZ xZS )random_samplezT
    Returns a random sample of items from the dataset, from the given property
    RANDOM_SAMPLEr   sizer   Nc                 F    |t        |      g}t        |   |  || _        y)z
        ### Parameter

        **field**: Field to sample from
        **size**: Return this many items (can be less)
        N)r   r   r   r   )r   r   r_   r[   r   s       r   r   zrandom_sample.__init__   s'     s4y!$r   )	r   r   r   r   r#   r   intr   r   r   s   @r   r]   r]      s.     D	c 	 	 	 	r   r]   N)typingr   aggregationr   r   r   r   r
   r   r%   r,   r0   r4   r8   r=   rA   rE   rK   rO   r]   rC   r   r   <module>rd      s     : :w G  
   
   
   
     	 % 	 ( 
w 
   %' %PG r   