o
    Á¿ix  ã                   @   s    d dl mZ G dd„ deƒZdS )é    )Údivisionc                   @   sJ   e Zd ZdZdZdeddfdd„Zdefdd	„Zd
ededdfdd„Z	dS )ÚSimpleMovingAveragez/
    Simple Moving Average implementation.
    )ÚsizeÚindexÚcountsÚtotalsÚ	sum_countÚ	sum_totalr   ÚreturnNc                 C   sB   t d|ƒ}d| _|| _d| _d| _dg| j | _dg| j | _dS )zu
        :param size: The size of the window to calculate the moving average.
        :type size: :obj:`int`
        é   r   N)Úmaxr   r   r   r	   r   r   )Úselfr   © r   úH/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/sma.pyÚ__init__   s   
zSimpleMovingAverage.__init__c                 C   s   | j dkrdS t| jƒ| j  S )Nr   g        )r	   Úfloatr   )r   r   r   r   Úget"   s   
zSimpleMovingAverage.getÚcountÚtotalc                 C   sl   t ||ƒ}|  j|| j| j  7  _|  j|| j| j  7  _|| j| j< || j| j< | jd | j | _dS )a  
        Set the value of the next bucket and update the SMA value.

        :param count: The valid quantity of the next bucket.
        :type count: :obj:`int`
        :param total: The total quantity of the next bucket.
        :type total: :obj:`int`
        r   N)Úminr   r   r   r	   r   r   )r   r   r   r   r   r   Úset(   s   
	zSimpleMovingAverage.set)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__Úintr   r   r   r   r   r   r   r   r      s    	r   N)Ú
__future__r   Úobjectr   r   r   r   r   Ú<module>   s    