# tests/test_wf_visualizer.py

import sys
from pathlib import Path
import pandas as pd

# Añadir raíz del proyecto al path
sys.path.insert(0, str(Path(__file__).parent.parent))

from src.core.visualizers.walk_forward_visualizer import WalkForwardVisualizer


def test_wf_visualizer():
    """
    Test del WalkForwardVisualizer usando los CSV existentes
    """

    base_path = Path("backtest_results/walkforward")

    summary_df = pd.read_csv(base_path / "walkforward_summary.csv")
    windows_df = pd.read_csv(base_path / "walkforward_windows.csv")

    viz = WalkForwardVisualizer(
        summary_df=summary_df,
        windows_df=windows_df,
        name="BTC/USDT – MA + ADX"
    )

    # 📊 Plots
    viz.plot_avg_metrics()
    viz.plot_returns_by_window()
    viz.plot_drawdown_by_window()
    viz.plot_return_distribution()
    viz.plot_parameter_stability("fast_period")
    viz.plot_parameter_stability("slow_period")
    viz.plot_parameter_stability("adx_threshold")


if __name__ == "__main__":
    test_wf_visualizer()
