o
    0j	                     @   s   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	 edr(d dl
mZ d dlZedd	ejd
ejfddZG dd de	ZdS )    N)Any)Image   )function_requires_depsis_dep_available   )BaseTSResultZ
matplotlibforecastreturnc                 C   s   t jdd | j}| jj | jt| _t j| j| |d  dddd t d t 	d	 t 
|d  t   t d
 t jtdt| dd t jdd t }t j|dd |d t   t|}|S )a  
    Visualizes both the time series forecast and actual results, returning them as a Pillow image.

    Args:
        forecast (pd.DataFrame): The DataFrame containing the forecast data.

    Returns:
        Image.Image: The visualized result as a Pillow image.
    )      )Zfigsizer   postZAnomalyred)wherelabelcolorzTime Series Anomaly DetectionZTimeT
   )Zticks-   )ZrotationZtight)Zbbox_inches)pltZfigurecolumnsindexnameZastypestrsteptitleZxlabelZylabelZlegendgridZxticksrangelenioBytesIOZsavefigseekcloser   open)r	   Zforecast_columnsbufimage r%   u/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/models/ts_anomaly_detection/result.py	visualize   s0   





r'   c                   @   s.   e Zd ZdZdejfddZdefddZdS )
TSAdResultzHA class representing the result of a time series anomaly detection task.r
   c                 C   s   | d }dt |iS )applyanomalyres)r'   )selfr*   r%   r%   r&   _to_imgG   s   zTSAdResult._to_imgc                 C   s   d| d iS )z
        Converts the anomaly detection results to a CSV format.

        Returns:
            Any: The anomaly data formatted for CSV output, typically a DataFrame or similar structure.
        r+   r*   r%   )r,   r%   r%   r&   _to_csvL   s   zTSAdResult._to_csvN)__name__
__module____qualname____doc__r   r-   r   r.   r%   r%   r%   r&   r(   D   s    r(   )r   typingr   ZPILr   Z
utils.depsr   r   Zcommon.resultr   Zmatplotlib.pyplotZpyplotr   ZpandaspdZ	DataFramer'   r(   r%   r%   r%   r&   <module>   s   '