#!/usr/bin/env python3
from pathlib import Path
import json
import pandas as pd

root = Path(__file__).resolve().parents[1]
errors = []
catalog = pd.read_csv(root / "data/prepared/galaxy_catalog.csv")
signatures = pd.read_csv(root / "runs/consolidated/galaxy_chamber_signatures_primary_121.csv")
curves = pd.read_csv(root / "runs/consolidated/struc_i_primary_121_profiles.csv")
manifest = pd.read_csv(root / "inputs/ladders/ladder_manifest.csv")
checks = {
    "source_galaxies": catalog["galaxy_id"].nunique() == 175,
    "paired_ladders": len(manifest) == 175,
    "primary_signatures": signatures["galaxy_id"].nunique() == 121,
    "curve_rows": len(curves) == 4840,
    "curve_points_per_galaxy": (curves.groupby("galaxy_id").size() == 40).all(),
    "no_interpolation": (~manifest["interpolation_used"].astype(bool)).all(),
}
checks = {name: bool(passed) for name, passed in checks.items()}
for name, passed in checks.items():
    if not passed:
        errors.append(name)
if errors:
    raise SystemExit("VALIDATION_FAIL " + ",".join(errors))
print("VALIDATION_PASS " + json.dumps(checks, sort_keys=True))
