o
    $i	                     @   s*   d dl Zd dlmZ eG dd dZdS )    N)OldAPIStackc                   @   s`   e Zd ZdZdedefddZddd	Zdefd
dZ	defddZ
dejfddZdd ZdS )
WindowStata  Handles/stores incoming dataset and provides window-based statistics.

    .. testcode::
        :skipif: True

        win_stats = WindowStat("level", 3)
        win_stats.push(5.0)
        win_stats.push(7.0)
        win_stats.push(7.0)
        win_stats.push(10.0)
        # Expect 8.0 as the mean of the last 3 values: (7+7+10)/3=8.0
        print(win_stats.mean())

    .. testoutput::

        8.0
    namenc                 C   s*   || _ || _dg| j  | _d| _d| _dS )zInitializes a WindowStat instance.

        Args:
            name: The name of the stats to collect and return stats for.
            n: The window size. Statistics will be computed for the last n
                items received from the stream.
        Nr   )window_sizer   itemsidxcount)selfr   r    r   `/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/rllib/utils/metrics/window_stat.py__init__   s
   	
zWindowStat.__init__returnNc                 C   s@   || j | j< |  jd7  _|  jd7  _|  jt| j ;  _dS )z/Pushes a new value/object into the data buffer.   N)r   r   r	   len)r
   objr   r   r   push-   s   zWindowStat.pushc                 C      t t| jd| j S )z<Returns the (NaN-)mean of the last `self.window_size` items.N)floatnpnanmeanr   r	   r
   r   r   r   mean8      zWindowStat.meanc                 C   r   )z>Returns the (NaN)-stddev of the last `self.window_size` items.N)r   r   nanstdr   r	   r   r   r   r   std<   r   zWindowStat.stdc                 C   s6   | j stjg tjdS t| jd| j  g d S )z8Returns ndarray with 0, 10, 50, 90, and 100 percentiles.)dtypeN)r   
   2   Z   d   )r	   r   ndarrayfloat32nanpercentiler   tolistr   r   r   r   	quantiles@   s   zWindowStat.quantilesc              	   C   s>   | j d t| j| j d |  | j d |  | j d |  iS )N_count_mean_std
_quantiles)r   intr	   r   r   r%   r   r   r   r   statsI   s
   zWindowStat.stats)r   N)__name__
__module____qualname____doc__strr*   r   r   r   r   r   r   r!   r%   r+   r   r   r   r   r      s    
	r   )numpyr   ray.rllib.utils.annotationsr   r   r   r   r   r   <module>   s    