o
    0j~                     @   s   d dl Z d dlmZ d dl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 edd	ej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actual_datareturnc                 C   s$  t jdd | j}| jj}||}|jt|_| jt| _tt	| t	|}|
|}t j|j||d  dddd t j| j| |d  dd	d
 t d t d t |d  t   t d t jtdd| 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.
        actual_data (pd.Series): The actual observed data for comparison.
        title (str): The title of the plot.

    Returns:
        Image.Image: The visualized result as a Pillow image.
    )      )Zfigsizer   zActual Databluez--)labelcolorZ	linestyleZForecastred)r   r   zTime Series ForecastZTimeT   
   )Zticks-   )ZrotationZtight)Zbbox_inches)pltZfigurecolumnsindexnameZ	set_indexZastypestrminlentailZplottitleZxlabelZylabelZlegendgridZxticksrangeioBytesIOZsavefigseekcloser   open)r	   r
   Zforecast_columnsZ
index_namelengthbufimage r(   o/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/models/ts_forecasting/result.py	visualize   s>   







r*   c                   @   s.   e Zd ZdZdejfddZdefddZdS )
TSFcResultzBA class representing the result of a time series forecasting task.r   c                 C   s   | d }| d }dt ||iS )applyr	   Z	cutoff_tsres)r*   )selfr	   Zts_inputr(   r(   r)   _to_imgS   s   zTSFcResult._to_imgc                 C   s   d| d iS )z
        Converts the forecasting results to a CSV format.

        Returns:
            Any: The forecast data formatted for CSV output, typically a DataFrame or similar structure.
        r-   r	   r(   )r.   r(   r(   r)   _to_csvY   s   zTSFcResult._to_csvN)__name__
__module____qualname____doc__r   r/   r   r0   r(   r(   r(   r)   r+   P   s    r+   )r    typingr   ZpandaspdZPILr   Z
utils.depsr   r   Zcommon.resultr   Zmatplotlib.pyplotZpyplotr   Z	DataFramer*   r+   r(   r(   r(   r)   <module>   s   3