
    j/              	           d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d dlmZ dd
edededdfdZ G d d          Z e            ZdS )    N)Path)Thread)Requesturlopen)SETTINGS__version__)ARGVENVIRONMENTGITIS_PIP_PACKAGEONLINEPYTHON_VERSIONRANKTESTS_RUNNING)GITHUB_ASSETS_NAMES)get_cpu_info      @urldatatimeoutreturnc                     	 t          j        |d                                          }t          | |ddi          }t	          ||                                           dS # t          $ r Y dS w xY w)z"Send a one-shot JSON POST request.),:)
separatorszContent-Typezapplication/json)r   headers)r   N)jsondumpsencoder   r   close	Exception)r   r   r   bodyreqs        ]/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/ultralytics/utils/events.py_postr%      s    z$:666==??c~?Q.RSSSW%%%++-----   s   AA# #
A10A1c                   (    e Zd ZdZdZddZdddZdS )	Eventsa  Collect and send anonymous usage analytics with rate-limiting.

    Event collection and transmission are enabled when sync is enabled in settings, the current process is rank -1 or 0,
    tests are not running, the environment is online, and the installation source is either pip or the official
    Ultralytics GitHub repository.

    Attributes:
        url (str): Measurement Protocol endpoint for receiving anonymous events.
        events (list[dict]): In-memory queue of event payloads awaiting transmission.
        rate_limit (float): Minimum time in seconds between POST requests.
        t (float): Timestamp of the last transmission in seconds since the epoch.
        metadata (dict): Static metadata describing runtime, installation source, and environment.
        enabled (bool): Flag indicating whether analytics collection is active.

    Methods:
        __init__: Initialize the event queue, rate limiter, and runtime metadata.
        __call__: Queue an event and trigger a non-blocking send when the rate limit elapses.
    zihttps://www.google-analytics.com/mp/collect?measurement_id=G-X8NCJYTQXM&api_secret=QLQrATrNSwGRFRLE-cbHJwr   Nc           
         g | _         d| _        d| _        t          t          d                   j        dk    t          j        rdn
t          rdndt          j
        dd	          d         t                      t          t          t          t          j                    d
z            dd| _        t"          d         o.t$          dv o%t&           ot(          ot          pt          j        dk    | _        dS )zRInitialize the Events instance with queue, rate limiter, and environment metadata.g      >@g        r   yologitpipother.   g  4&kCi  )cliinstallpythonCPUversionenv
session_idengagement_time_msecsync>   r   z.https://github.com/ultralytics/ultralytics.gitN)events
rate_limittr   r	   namer   is_repor   r   rsplitr   r   r
   roundrandommetadatar   r   r   r   originenabled)selfs    r$   __init__zEvents.__init__0   s    Q==%/ #Uuu.1Ug$+C33A6>>"$ 677$(

 

 V cc!!c c  a3:1a#a 	    c                 ~   | j         sdS t          | j                  dk     ri | j        |j        |j        t          v r|j        ndt          |          d}|j        dk    r
|j	        |d<   |j        dk    r|t          |          j        nd|d<   | j                            |j        |d	           t          j                    }|| j        z
  | j        k     rdS t!          | j                  }t#          t$          | j        t(          d
         |dfd                                           g | _        || _        dS )a  Queue an event and flush the queue asynchronously when the rate limit elapses.

        Args:
            cfg (IterableSimpleNamespace): The configuration object containing mode and task information.
            device (torch.device | str, optional): The device type (e.g., 'cpu', 'cuda').
            backend (object | None, optional): The inference backend instance used during prediction.
        N   custom)taskmodeldeviceexportformatpredictbackend)r<   paramsuuid)	client_idr9   T)targetargsdaemon)rC   lenr9   rA   rJ   rK   r   strmoderN   type__name__appendtimer;   r:   listr   r%   r   r   start)rD   cfgrL   rP   rQ   r;   payload_eventss          r$   __call__zEvents.__call__H   sZ    | 	F t{b  -&)i3F&F&FHf++	  F x8###&:x x9$$>E>QDMM$:$:W[y!KFCCDDD IKKJ$/))F dk**((6*:nUUV	
 	
 	
 %''' rF   )r   N)NN)r[   
__module____qualname____doc__r   rE   rb    rF   r$   r'   r'      sS         & vC
 
 
 
0) ) ) ) ) ) )rF   r'   )r   ) r   r@   r]   pathlibr   	threadingr   urllib.requestr   r   ultralyticsr   r   ultralytics.utilsr	   r
   r   r   r   r   r   r   ultralytics.utils.downloadsr   ultralytics.utils.torch_utilsr   rX   dictfloatr%   r'   r9   rf   rF   r$   <module>rp      sM                  + + + + + + + + - - - - - - - - q q q q q q q q q q q q q q q q q q q q ; ; ; ; ; ; 6 6 6 6 6 6 s $      W W W W W W W Wt 
rF   