# scripts/fill_formatted_1s.py
from __future__ import annotations

from pathlib import Path
import sys


PROJECT_ROOT = Path(__file__).resolve().parents[3]
if str(PROJECT_ROOT) not in sys.path:
    sys.path.insert(0, str(PROJECT_ROOT))

from meteo.dataset import load_raw_csv, fill_missing_with_previous


INPUT_CSV_PATH = Path("data/weather_formatted_1s.csv")
OUTPUT_CSV_PATH = Path("data/weather_filled_1s.csv")


def main() -> None:
    if not INPUT_CSV_PATH.exists():
        print(f"⚠ Fichier introuvable : {INPUT_CSV_PATH}")
        print('   Lancez d\'abord : python "docs/02 - Préparation des données/scripts/format_raw_csv.py"')
        return

    df_1s = load_raw_csv(INPUT_CSV_PATH)
    print(f"Fichier 1s formaté chargé : {INPUT_CSV_PATH}")
    print(f"  Lignes : {len(df_1s)}, colonnes : {list(df_1s.columns)}")

    df_filled = fill_missing_with_previous(df_1s)
    print(f"Après propagation des dernières valeurs connues : {len(df_filled)} lignes")

    OUTPUT_CSV_PATH.parent.mkdir(parents=True, exist_ok=True)
    df_filled.to_csv(OUTPUT_CSV_PATH, index_label="time")
    print(f"✔ Fichier 1s 'complet' écrit dans : {OUTPUT_CSV_PATH.resolve()}")


if __name__ == "__main__":
    main()
