U
    b+dN                     @   s   d dl 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 )   )ReducerSortDirectionc                       s   e Zd Z fddZ  ZS )FieldOnlyReducerc                    s   t  | || _d S N)super__init___fieldselffield	__class__ B/tmp/pip-unpacked-wheel-cdsyf3nb/redis/commands/search/reducers.pyr      s    zFieldOnlyReducer.__init__)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )countz3
    Counts the number of results in the group
    ZCOUNTc                    s   t    d S r   r   r   )r
   r   r   r   r      s    zcount.__init__r   r   r   __doc__NAMEr   r   r   r   r   r   r   
   s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )sumzS
    Calculates the sum of all the values in the given fields within the group
    ZSUMc                    s   t  | d S r   r   r	   r   r   r   r      s    zsum.__init__r   r   r   r   r   r      s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )minzK
    Calculates the smallest value in the given field within the group
    ZMINc                    s   t  | d S r   r   r	   r   r   r   r   '   s    zmin.__init__r   r   r   r   r   r       s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )maxzJ
    Calculates the largest value in the given field within the group
    MAXc                    s   t  | d S r   r   r	   r   r   r   r   2   s    zmax.__init__r   r   r   r   r   r   +   s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )avgzG
    Calculates the mean value in the given field within the group
    ZAVGc                    s   t  | d S r   r   r	   r   r   r   r   =   s    zavg.__init__r   r   r   r   r   r   6   s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )tolistz6
    Returns all the matched properties in a list
    ZTOLISTc                    s   t  | d S r   r   r	   r   r   r   r   H   s    ztolist.__init__r   r   r   r   r   r   A   s   r   c                       s$   e Zd ZdZdZ fddZ  ZS )count_distinctzs
    Calculate the number of distinct values contained in all the results in
    the group for the given field
    ZCOUNT_DISTINCTc                    s   t  | d S r   r   r	   r   r   r   r   T   s    zcount_distinct.__init__r   r   r   r   r   r   L   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
    ZCOUNT_DISTINCTISHN)r   r   r   r   r   r   r   r   r   r    X   s   r    c                       s$   e Zd ZdZdZ 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.
    ZQUANTILEc                    s   t  |t| || _d S r   )r   r   strr   )r
   r   Zpctr   r   r   r   j   s    zquantile.__init__r   r   r   r   r   r!   b   s   r!   c                       s$   e Zd ZdZdZ fddZ  ZS )stddevzG
    Return the standard deviation for the values within the group
    ZSTDDEVc                    s   t  | d S r   r   r	   r   r   r   r   v   s    zstddev.__init__r   r   r   r   r   r#   o   s   r#   c                       s$   e Zd ZdZdZ fddZ  ZS )first_valuezR
    Selects the first value within the group according to sorting parameters
    ZFIRST_VALUEc                    s   g }t |dkr:t|d tr:t|d tr:|d |g}|D ]}||j|jg7 }q>|g}|rl|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       ZBYN)
len
isinstancetype
issubclassr   r   Z	DIRSTRINGr   r   r   )r
   r   ZbyfieldsZ	fieldstrsfargsr   r   r   r      s    
zfirst_value.__init__r   r   r   r   r   r$   z   s   r$   c                       s$   e Zd ZdZdZ fddZ  ZS )random_samplezT
    Returns a random sample of items from the dataset, from the given property
    ZRANDOM_SAMPLEc                    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   sizer+   r   r   r   r      s    zrandom_sample.__init__r   r   r   r   r   r,      s   r,   N)Zaggregationr   r   r   r   r   r   r   r   r   r   r    r!   r#   r$   r,   r   r   r   r   <module>   s   
(