import warnings

warnings.filterwarnings("ignore")

import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as _real_mpl_plt

_real_mpl_plt.show = lambda *a, **kw: None

import os
import sys
import time
import json
import traceback
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.metrics import accuracy_score, f1_score, classification_report, confusion_matrix, ConfusionMatrixDisplay
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler, LabelEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, VotingClassifier
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
from sklearn.impute import SimpleImputer
from sklearn.cluster import KMeans
from sklearn.mixture import GaussianMixture
from sklearn.metrics import silhouette_score
from sklearn.decomposition import PCA
import xgboost as xgb
import optuna
optuna.logging.set_verbosity(optuna.logging.WARNING)

from src.notebook_runner import execute_notebook
from src.runtime_paths import build_paths

paths = build_paths()
print(f"Project root : {paths.project_root}")
print(f"Notebook     : {paths.notebook}")
print(f"Data dir     : {paths.data_dir}")
print(f"Output dir   : {paths.output_dir}")

ns = vars()

result = execute_notebook(start_at=1, namespace=ns)
print(f"\nExecution finished: {result['status']}")
print(f"Cells run: {len([c for c in result['cells'] if c['status'] == 'ok'])}/{result['total']}")
print(f"Output dir: {result['outputs']['output_dir']}")