
    &`i"                         d dl mZmZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ dZdZ e
d          Z e
de	          Z G d
 de          Z G d de          Z G d deee                   ZdS )    )ABCabstractmethod)Enum)DictGenericOptionalTupleTypeVar)Gaugeray_train_run_nameray_train_run_idTE)boundc            
           e Zd Zdedededeeef         fdZedefd            Zedefd	            Z	ed
             Z
deedf         fdZdS )Metricnamedefaultdescription	base_tagsc                 t    || _         || _        t          |||                                           | _        dS )a  
        Initialize a new metric.

        Args:
            name: The name of the metric.
            default: The default value of the metric.
            description: The description of the metric.
            base_tags: The base tags for the metric.
        )r   tag_keysN)_default
_base_tagsr   _get_tag_keys_gauge)selfr   r   r   r   s        w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/train/v2/_internal/metrics/base.py__init__zMetric.__init__   sA       ##''))
 
 
    valuec                     dS )zhUpdate the metric value.

        Args:
            value: The value to update the metric with.
        N r   r!   s     r   recordzMetric.record'   s	     	r    returnc                     dS )zGet the value of the metric.

        Returns:
            The value of the metric. If the metric has not been recorded,
            the default value is returned.
        Nr#   r   s    r   	get_valuezMetric.get_value0   s	     	r    c                     dS )z$Reset values and clean up resources.Nr#   r(   s    r   resetzMetric.reset:   s	     	r    .c                 N    t          | j                                                  S N)tupler   keysr(   s    r   r   zMetric._get_tag_keys?   s    T_))++,,,r    N)__name__
__module____qualname__strr   r   r   r   r%   r)   r+   r	   r   r#   r    r   r   r      s        

 
 	

 S>
 
 
 
0 A    ^ 1    ^   ^-uS#X - - - - - -r    r   c                   ^     e Zd ZdZdededeeef         f fdZdefdZdefd	Z	d
 Z
 xZS )
TimeMetricz#A metric for tracking elapsed time.r   r   r   c                 `    d| _         t                                          |d||           d S )Ng        r   r   r   r   )_current_valuesuperr   )r   r   r   r   	__class__s       r   r   zTimeMetric.__init__F   sD     "#	 	 	
 	
 	
 	
 	
r    r!   c                 p    | xj         |z  c_         | j                            | j         | j                   dS )zUpdate the time metric value by accumulating the time.

        Args:
            value: The time value to increment the metric by.
        N)r8   r   setr   r$   s     r   r%   zTimeMetric.recordT   s9     	u$+T_=====r    r&   c                     | j         S r-   )r8   r(   s    r   r)   zTimeMetric.get_value]   s    ""r    c                 h    | j         | _        | j                            | j         | j                   d S r-   )r   r8   r   r<   r   r(   s    r   r+   zTimeMetric.reset`   s,    "mt77777r    )r0   r1   r2   __doc__r3   r   r   floatr%   r)   r+   __classcell__r:   s   @r   r5   r5   C   s        --

 
 S>	
 
 
 
 
 
>E > > > >#5 # # # #8 8 8 8 8 8 8r    r5   c                        e Zd ZdZdZdZdededeeef         def fdZd	e	fd
Z
d	e	defdZd Zdeedf         fdZd	e	deeef         fdZ xZS )
EnumMetricz"A metric for tracking enum values.r      r   r   r   enum_tag_keyc                 x    || _         d | _        t                                          || j        ||           d S )Nr7   )_enum_tag_keyr8   r9   r   DEFAULT_VALUE)r   r   r   r   rF   r:   s        r   r   zEnumMetric.__init__k   sO     *+/&#	 	 	
 	
 	
 	
 	
r    
enum_valuec                    || j         k    rdS | j         :|                     | j                   }| j                            | j        |           |                     |          }| j                            | j        |           || _         dS )zRecord a specific enum value.

        The metric will be reset to 0 for the previous value and set to 1 for the new value.

        Args:
            enum_value: The enum value to record for.
        N)r8   	_get_tagsr   r<   r   RECORDED_VALUE)r   rJ   previous_tagscurrent_tagss       r   r%   zEnumMetric.record{   s     ,,,F* NN4+>??MKOODM=999~~j11+\:::(r    r&   c                 2    t          || j        k              S )zGet the value for a specific enum value.

        Args:
            enum_value: The enum value to get the value for

        Returns:
            The value for the enum value
        )intr8   )r   rJ   s     r   r)   zEnumMetric.get_value   s     :!44555r    c                     | j         :|                     | j                   }| j                            | j        |           d | _         d S r-   )r8   rL   r   r<   r   )r   tagss     r   r+   zEnumMetric.reset   sE    *>>$"566DKOODM4000"r    .c                 `    t          | j                                                  | j        fz   S r-   )r.   r   r/   rH   r(   s    r   r   zEnumMetric._get_tag_keys   s)    T_))++,,0B/DDDr    c                 V    | j                                         }|j        || j        <   |S r-   )r   copyr   rH   )r   rJ   rS   s      r   rL   zEnumMetric._get_tags   s)    ##%%#-?T r    )r0   r1   r2   r?   rI   rM   r3   r   r   r   r%   rQ   r)   r+   r	   r   rL   rA   rB   s   @r   rD   rD   e   s       ,,MN

 
 S>	

 
 
 
 
 
 
 ) ) ) ) )(	6A 	6# 	6 	6 	6 	6# # #EuS#X E E E EA $sCx.        r    rD   N)abcr   r   enumr   typingr   r   r   r	   r
   ray.util.metricsr   RUN_NAME_TAG_KEYRUN_ID_TAG_KEYr   r   r   r5   rD   r#   r    r   <module>r]      s1   # # # # # # # #       : : : : : : : : : : : : : : " " " " " "' #GCLLGCt2- 2- 2- 2- 2-S 2- 2- 2-j8 8 8 8 8 8 8 8DA A A A A A A A A Ar    