# STANDARD SHARED CONFIG CELL
# Place this near the beginning of Notebooks 03-12.

import json
from pathlib import Path
import pandas as pd
import numpy as np

PROJECT_ROOT = Path("/content/Dissertation_Research")  # change once if your Drive path differs
CONFIG_DIR = PROJECT_ROOT / "config"

with open(CONFIG_DIR / "experiment_config.json", "r", encoding="utf-8") as f:
    CFG = json.load(f)

FEATURES = pd.read_csv(CONFIG_DIR / "feature_list.csv")["Feature_Name"].tolist()
TRAIN_INDEX = pd.read_csv(CONFIG_DIR / "train_indices.csv")["Dataset_Index"].to_numpy()
TEST_INDEX = pd.read_csv(CONFIG_DIR / "test_indices.csv")["Dataset_Index"].to_numpy()

print("Shared configuration loaded")
print("Random state:", CFG["random_state"])
print("Test size:", CFG["test_size"])
print("Features:", len(FEATURES))

# After loading the cleaned dataframe as `data`:
# X = data.loc[:, FEATURES].copy()
# y = data[CFG["target_column"]].copy()
# X_train, X_test = X.loc[TRAIN_INDEX], X.loc[TEST_INDEX]
# y_train, y_test = y.loc[TRAIN_INDEX], y.loc[TEST_INDEX]
#
# Optional safety checks:
# assert X_train.columns.tolist() == FEATURES
# assert X_test.columns.tolist() == FEATURES
# assert len(set(TRAIN_INDEX).intersection(set(TEST_INDEX))) == 0
