""" Script 02 – Build fleet reference table. Reads AERONAVES.csv + CHECKS.csv, computes TTM and the full check-cycle sequence for each aircraft, and saves the reference to data/reference/. """ import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) import pandas as pd from datetime import datetime from src.routing_engine.config import DEFAULT_CONFIG from src.routing_engine.inspect_files import read_aircraft, read_checks from src.routing_engine.ingest import build_fleet, _check_cycles cfg = DEFAULT_CONFIG aircraft_df = read_aircraft(cfg.raw_dir / cfg.aircraft_file) checks_df = read_checks(cfg.raw_dir / cfg.checks_file) print("Aircraft loaded:") print(aircraft_df.to_string(index=False)) print() print("Checks loaded:") print(checks_df.to_string(index=False)) print() # Build fleet planning_start = datetime(cfg.planning_year, 3, 18) # first OFRAG departure in the sample data fleet = build_fleet(aircraft_df, checks_df, planning_start) print("Fleet reference:") for _, row in fleet.iterrows(): print(f"\n {row['tail_number']} ({row['model']}) FH total = {row['fh_total']:.0f}") print(f" TTM before first check: {row['ttm_hours']:.1f} FH") for i, c in enumerate(row["checks"]): print(f" Cycle {i}: threshold={c['fh_threshold']:.0f} FH, " f"TTM={c['ttm']:.0f} FH, duration={c['duration_hours']:.0f} h") # Save to reference cfg.reference_dir.mkdir(parents=True, exist_ok=True) out_path = cfg.reference_dir / "fleet_reference.csv" flat_rows = [] for _, row in fleet.iterrows(): flat_rows.append( { "tail_number": row["tail_number"], "model": row["model"], "fh_total": row["fh_total"], "ttm_hours_cycle0": row["ttm_hours"], "n_check_cycles": len(row["checks"]), "cycles_json": str(row["checks"]), } ) pd.DataFrame(flat_rows).to_csv(out_path, index=False) print(f"\nFleet reference saved -> {out_path}")