#!/usr/bin/env python3
"""
Exports the exact numerical values frozen in the current manuscript and supplementary material.
These files are intended to reproduce the manuscript-facing tables exactly as currently written.
"""
from __future__ import annotations
from pathlib import Path
import pandas as pd

ROOT = Path(__file__).resolve().parents[1]
RESULTS = ROOT / "results"
RESULTS.mkdir(exist_ok=True)

def main() -> None:
    core = pd.DataFrame([
        {
            "result_block": "blind_holdout_validation",
            "subset": "validation_138",
            "n": 138,
            "mae_gpa_reported": 3.20,
            "rmse_gpa_reported": None,
            "cov_percent_reported": 12.70,
            "mean_signed_error_gpa_reported": None,
            "source": "frozen_manuscript_text",
        },
        {
            "result_block": "source_exclusive_verification",
            "subset": "pure_validation_source_subset",
            "n": None,
            "mae_gpa_reported": 3.25,
            "rmse_gpa_reported": 4.15,
            "cov_percent_reported": 12.91,
            "mean_signed_error_gpa_reported": -0.97,
            "source": "frozen_manuscript_text",
        },
    ])
    core.to_csv(RESULTS / "manuscript_frozen_core_metrics.csv", index=False)

    appendix_a = pd.DataFrame([
        {"regime":"NSC", "fc_range_mpa":"< 40", "A":8.2, "B":0.0045, "C":0.0095, "mae_gpa":1.85, "rmse_gpa":2.15, "cov_percent":7.22},
        {"regime":"HSC", "fc_range_mpa":"40 ≤ fc < 80", "A":9.9, "B":0.0055, "C":0.01100, "mae_gpa":2.90, "rmse_gpa":3.25, "cov_percent":7.89},
        {"regime":"UHPC", "fc_range_mpa":"≥ 80", "A":10.5, "B":0.0060, "C":0.01200, "mae_gpa":1.45, "rmse_gpa":2.95, "cov_percent":6.69},
    ])
    appendix_a.to_csv(RESULTS / "manuscript_frozen_appendix_a_table_a1.csv", index=False)

    benchmark = pd.DataFrame([
        {"model_equation":"Proposed Eq. (1)", "mae_gpa":2.67, "rmse_gpa":3.49, "cov_percent":10.38},
        {"model_equation":"Eurocode 2", "mae_gpa":3.36, "rmse_gpa":4.22, "cov_percent":12.57},
        {"model_equation":"NS 3473", "mae_gpa":3.61, "rmse_gpa":4.37, "cov_percent":12.99},
        {"model_equation":"Alberti et al. (2020)", "mae_gpa":4.16, "rmse_gpa":5.09, "cov_percent":15.14},
        {"model_equation":"ACI 318-19", "mae_gpa":4.18, "rmse_gpa":5.10, "cov_percent":15.17},
        {"model_equation":"Fib Model Code", "mae_gpa":4.12, "rmse_gpa":5.14, "cov_percent":15.28},
        {"model_equation":"Yoo et al. (2022)", "mae_gpa":4.77, "rmse_gpa":5.55, "cov_percent":16.51},
        {"model_equation":"Silva et al. (2022)", "mae_gpa":4.72, "rmse_gpa":5.93, "cov_percent":17.66},
        {"model_equation":"Kumar et al. (2022)", "mae_gpa":5.47, "rmse_gpa":6.21, "cov_percent":18.47},
        {"model_equation":"Zhang et al. (2023)", "mae_gpa":5.15, "rmse_gpa":7.16, "cov_percent":21.31},
        {"model_equation":"NBR 6118", "mae_gpa":7.28, "rmse_gpa":9.42, "cov_percent":28.02},
    ])
    benchmark.to_csv(RESULTS / "manuscript_frozen_benchmark_table_b1.csv", index=False)

    summary_table1 = pd.DataFrame([
        {"variable":"Compressive Strength, fc (MPa)", "minimum":21.30, "maximum":190.90, "mean":55.62, "standard_deviation":28.35},
        {"variable":"Fiber Volume, Vf (%)", "minimum":0.00, "maximum":4.30, "mean":1.03, "standard_deviation":0.74},
        {"variable":"Aspect Ratio, L/D (-)", "minimum":35.00, "maximum":80.00, "mean":62.72, "standard_deviation":12.86},
        {"variable":"Elastic Modulus, Ec (GPa)", "minimum":19.60, "maximum":50.50, "mean":33.60, "standard_deviation":5.78},
    ])
    summary_table1.to_csv(RESULTS / "manuscript_frozen_table1_summary.csv", index=False)

    print("Exported manuscript-frozen result tables.")

if __name__ == "__main__":
    main()
