# dam_test.py
"""
Script para probar cositas
"""
import os
import sys
from dotenv import load_dotenv
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.data.storage import StorageManager
from src.core.walk_forward import WalkForwardValidator
from src.strategies import MovingAverageCrossover

def setup_environment():
    """Carga variables de entorno"""
    env_path = Path(__file__).parent.parent / 'config' / 'secrets.env'
    load_dotenv(dotenv_path=env_path)

def dam_test():
    # Setup
    setup_environment()
    
    # Cargar datos
    storage = StorageManager(
        db_host=os.getenv('DB_HOST'),
        db_port=int(os.getenv('DB_PORT', 5432)),
        db_name=os.getenv('DB_NAME'),
        db_user=os.getenv('DB_USER'),
        db_password=os.getenv('DB_PASSWORD'),
    )

    data = storage.load_ohlcv(
        symbol='BTC/USDT',
        timeframe='1h',
        start_date=None,
        end_date=None,
        use_cache=False
    )

    wf = WalkForwardValidator(
        strategy_class=MovingAverageCrossover,
        param_grid={},
        data=data,
        train_window=pd.Timedelta(days=365),
        test_window=pd.Timedelta(days=90),
    )

    windows = wf._generate_windows()

    print(f"Ventanas generadas: {len(windows)}")
    for w in windows[:3]:
        print(w)

if __name__ == "__main__":
    dam_test()