# scripts/plot_illuminance_focus.py
from __future__ import annotations

from pathlib import Path

from meteo.dataset import load_raw_csv
from meteo.analysis import compute_seasonal_hourly_profile, compute_monthly_daylight_hours
from meteo.plots import plot_seasonal_hourly_profiles, plot_daylight_hours


CSV_PATH = Path("data/weather_minutely.csv")
OUTPUT_DIR = Path("figures/illuminance")
DAYLIGHT_THRESHOLD_LUX = 1000.0


def main() -> None:
    if not CSV_PATH.exists():
        print(f"⚠ Fichier introuvable : {CSV_PATH}")
        return

    df = load_raw_csv(CSV_PATH)
    if "illuminance" not in df.columns:
        print("⚠ La colonne 'illuminance' est absente du dataset.")
        return

    print(f"Dataset minuté chargé : {CSV_PATH}")
    print(f"  Lignes   : {len(df)}")
    print(f"  Colonnes : {list(df.columns)}")
    print()

    OUTPUT_DIR.mkdir(parents=True, exist_ok=True)

    seasonal_profile = compute_seasonal_hourly_profile(
        df=df,
        value_column="illuminance",
        season_column="season",
    )
    seasonal_path = OUTPUT_DIR / "seasonal_diurnal_illuminance.png"
    plot_seasonal_hourly_profiles(
        profile_df=seasonal_profile,
        output_path=seasonal_path,
        title="Illuminance moyenne par heure et par saison",
        ylabel="Illuminance (lux)",
    )
    print(f"✔ Profil saisonnier de l'illuminance : {seasonal_path}")

    daylight_hours = compute_monthly_daylight_hours(
        df=df,
        illuminance_column="illuminance",
        threshold_lux=DAYLIGHT_THRESHOLD_LUX,
    )
    daylight_path = OUTPUT_DIR / "monthly_daylight_hours.png"
    plot_daylight_hours(
        monthly_series=daylight_hours,
        output_path=daylight_path,
        title=f"Durée moyenne quotidienne > {DAYLIGHT_THRESHOLD_LUX:.0f} lx",
    )
    print(f"✔ Durée de luminosité mensuelle : {daylight_path}")

    print("✔ Graphiques dédiés à l'illuminance générés.")


if __name__ == "__main__":
    main()
