o
    0j                     @   s   d dl Z 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Z	ddl
mZ ddlmZmZ G dd	 d	ejZG d
d deZG dd deeeZdS )    N)UserList)Path   )logging   )	JsonMixinStrMixinc                   @   s    e Zd ZdZdd Zdd ZdS )CopyableWeakMethodz0
    A weak method that can be deep copied.
    c                 C   s   | S N )selfr   r   l/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/common/result/base_result.py__copy__!   s   zCopyableWeakMethod.__copy__c                 C   s   |   S r
   )r   )r   memor   r   r   __deepcopy__$   s   zCopyableWeakMethod.__deepcopy__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r	      s    r	   c                       s4   e Zd ZdZ fddZdd Z fddZ  ZS )AutoWeakListzE
    A list that automatically removes weak references to items.
    c                    s.   t |rt t| dS t | dS )z
        Append item to list.
        If item is a bound method, append a weak reference to the method.
        Otherwise, append the item itself.
        N)inspectismethodsuperappendr	   )r   item	__class__r   r   r   -   s   
zAutoWeakList.appendc                 c   s8    | j D ]}t|tr| }|dur|V  q|V  qdS )zIterate over items in the list.N)data
isinstancer	   )r   r   funcr   r   r   __iter__8   s   

zAutoWeakList.__iter__c                    s$   t  |}t|tr| }|S |S )zGet item at index.)r   __getitem__r   r	   )r   indexr   r   r   r   r   r!   B   s
   
zAutoWeakList.__getitem__)r   r   r   r   r   r    r!   __classcell__r   r   r   r   r   (   s
    
r   c                       sD   e Zd ZdZdeddf fddZdeddfdd	Zd
d Z  Z	S )
BaseResultzBase class for result objects that can save themselves.

    This class inherits from dict and provides properties and methods for handling result.
    r   returnNc                    s@   t  | t | _t|  t|  tjddd d| _dS )zrInitializes the BaseResult with the given data.

        Args:
            data (dict): The initial data.
        r   )	thresholdZ	edgeitemsN)	r   __init__r   _save_funcsr   r   npZset_printoptions_rand_fn)r   r   r   r   r   r'   Q   s   


zBaseResult.__init__	save_pathc                 C   s6   | j D ]}t|}d|jv r||d q|  qdS )zCalls all registered save methods with the given save path.

        Args:
            save_path (str): The path to save the result to.
        r+   )r+   N)r(   r   	signature
parameters)r   r+   r   r,   r   r   r   save_all^   s   


zBaseResult.save_allc                 C   s   |  dd d u r3| jr| jS tt }tdd}| d| }td| d t|j	| _| jS t
| d trA| d d }n| d }|}t|j	S )N
input_pathi  i'  _zThere is not input file name as reference for name of saved result file. So the saved result file would be named with timestamp and random number: `z`.r   )getr*   inttimerandomrandintr   debugr   namer   list)r   	timestampZrandom_numberfpr/   r   r   r   _get_input_fnk   s    

zBaseResult._get_input_fn)
r   r   r   r   dictr'   strr.   r;   r#   r   r   r   r   r$   K   s
    r$   )r   r4   r3   weakrefcollectionsr   pathlibr   numpyr)   utilsr   Zmixinr   r   
WeakMethodr	   r   r<   r$   r   r   r   r   <module>   s   #