Files
aircraftrouting_arara/scripts/02_build_fleet_reference.py
Eduardo Carlos 3607965c88 Add OARMP routing engine, dashboard and documentation
- Complete routing engine: ingest, optimizer (CG+B&B), maintenance
  monitor, metrics, pipeline, quality checks
- Streamlit dashboard with Input/Output tab structure, editable data
  editors, interactive Folium map with satellite layer and maintenance
  base highlights, FH stacked bar chart with TTM availability
- CSV data files: AERONAVES, CHECKS, AIRPORTS, ESCALA DE VOO
- README, CONTEXTO and CHANGELOG added
- Remove legacy pre_process scripts and raw binary files (PDFs/xlsx)
- Update .gitignore to exclude outputs/, data/, raw/*.pdf, raw/*.xlsx

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-17 11:52:34 -03:00

65 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
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}")