
    Pf|                        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dS )    )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                 X    t                                          |           || _        d S N)super__init___fieldselfr   	__class__s     P/var/www/html/env/lib/python3.11/site-packages/redis/commands/search/reducers.pyr   zFieldOnlyReducer.__init__	   s&        )__name__
__module____qualname____doc__strr   __classcell__r   s   @r   r
   r
      sQ        R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
    COUNTr   Nc                 H    t                                                       d S 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      sN          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                 J    t                                          |           d S 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                 J    t                                          |           d S 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                 J    t                                          |           d S 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                 J    t                                          |           d S 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                 J    t                                          |           d S 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                 J    t                                          |           d S 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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   rA   rA   \   s          DDDr   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                 t    t                                          |t          |                     || _        d S 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   sc         
 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                 J    t                                          |           d S r   r"   r   s     r   r   zstddev.__init__z   r(   r   r)   r   s   @r   rK   rK   s   r;   r   rK   c                   D     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                 D   g }t          |          dk    rHt          |d         t                    r-t          |d         t                    r |d         |          g}|D ]}||j        |j        gz  }|g}|r	|dg|z   z  } 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   rQ   	fieldstrsfargsr   s         r   r   zfirst_value.__init__   s     	MMQ8A;-- 8A;66  $E**+H 	0 	0A!'1;//IIw 	'TFY&&D$r   )r   r   r   r   r#   r   r   r   r   r   r   r   s   @r   rO   rO   ~   sl          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                 d    |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   r_   r[   r   s       r   r   zrandom_sample.__init__   s4     s4yy!$r   )	r   r   r   r   r#   r   intr   r   r   s   @r   r]   r]      sc          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      sp         : : : : : : : : : : : :    w       G            
               
               
               
                     	  	  	  	  	 % 	  	  	     (   
 
 
 
 
w 
 
 
               % % % % %' % % %P    G     r   