import pandas as pd
from kpi_impact_sim.preprocessing import preprocess_dataframe
from kpi_impact_sim.ridge_model import fit_ridge_model
from kpi_impact_sim.simulate import apply_simulation
from kpi_impact_sim.utils import tipo_variable
import os

# Cargar demo del paquete
demo_path = os.path.join(os.path.dirname(__file__), "..", "kpi_impact_sim", "data", "demo_data.csv")
df = pd.read_csv(demo_path)

df = preprocess_dataframe(df)

target = "contacto_efectivo/contacto"
features = [c for c in df.columns if c not in ("fecha", target)]

X = df[features]
y = df[target]

res = fit_ridge_model(X, y)

print("\n=== COEFICIENTES ===")
print(res["coefs"])

sim = apply_simulation(
    coef_series=res["coefs"],
    df_mes=df,
    target=target,
    incremento_pts=2.0,
    tipo_variable_func=tipo_variable
)

print("\n=== SIMULACIÓN ===")
print(sim["candidates"].head(10))
