# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#       jupytext_version: 1.7.1
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# %% [markdown]
# ### Method:
# from n000, trying method xyz, using data abc
#
# ### Notes:
# Put tmp stuff into n9xx
#
# ### Result:
# We noted that method xyz took 5 minutes to run and the result is 5% different compared to n000

# %% code_folding=[]
############### root_dir ###############
import sys
ROOT_DIR, = !git rev-parse --show-toplevel
SRC_DIR = f'{ROOT_DIR}'
sys.path.append(SRC_DIR)

############### general imports ###############
import numpy as np, pandas as pd, scipy, matplotlib.pyplot as plt, seaborn as sns, pickle, random, time, shutil

import datetime; DATETIME_FMT = "%Y-%m-%d %H:%M:%S"; DATETIME_FMT_SHORT = "%Y%m%d_%H%M%S"; TZINFO=datetime.datetime.now().astimezone().tzinfo;
import logging; format = "%(asctime)s [%(levelname)s][%(filename)s %(funcName)s:%(lineno)s] %(message)s"; formatter = logging.Formatter(format, DATETIME_FMT); logging.basicConfig(format=format, datefmt=DATETIME_FMT);
logger = logging.getLogger('__main__'); logger.setLevel(logging.DEBUG)
# f_logger = logging.FileHandler(filename=f'{ROOT_DIR}/logs/stdout-{datetime.datetime.now().strftime(DATETIME_FMT_SHORT)}.log'); f_logger.setLevel(logging.DEBUG); f_logger.setFormatter(formatter); logger.addHandler(f_logger)

from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

from pdb import set_trace as bp
from pathlib import Path

# import src.sdutils as sdutils # sdutils.dict.flatten_dict

############### settings ###############
# sdMANUAL
# # %matplotlib notebook
# %matplotlib inline
plt.style.use('seaborn-white')
pd.set_option('display.max_rows', 50)
pd.set_option('display.max_columns', 0)

# %load_ext memory_profiler
# %load_ext autoreload
# %autoreload

# sdMANUAL
seed = int(time.time()); random.seed(seed); np.random.seed(seed); print("Seed was:", seed)
# seed = 1519972733; random.seed(seed); np.random.seed(seed); print('Warning: MANUAL seed'); print("Seed was:", seed);

# %% code_folding=[]
# project imports
import modin.pandas as pd; print('import modin.pandas as pd')

# sanity check for NUM_TAG and comfirming OUTPUT_DIR
try:
    match = re.search(r'^.\d\d\d', theNotebook)
    NUM_TAG = match.group() # will error if not found
except:
    print('WARNING: Please check NUM_TAG and set it MANUALLY.')
    NUM_TAG = '001' #sdManual
NOTEBOOK_FNAME = !ls | grep n{NUM_TAG} | grep ipynb
NOTEBOOK_FNAME = NOTEBOOK_FNAME[0] if len(NOTEBOOK_FNAME) == 1 else None

OUTPUT_DIR = f'{ROOT_DIR}/notebook_assets/n{NUM_TAG}'
Path(OUTPUT_DIR).mkdir(parents=True, exist_ok=True) # mkdir -p
DATA_DIR = f'{ROOT_DIR}/data'
print(OUTPUT_DIR)

# %%
# # useful commands
from sklearn.model_selection import GridSearchCV, ParameterGrid, RandomizedSearchCV, train_test_split
from sklearn.pipeline import Pipeline
from sklearn.base import TransformerMixin, BaseEstimator

from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import VotingClassifier, AdaBoostClassifier, RandomForestClassifier
import scikitplot as skplt
from sklearn.metrics import classification_report
from sklearn.dummy import DummyClassifier

from imblearn.under_sampling import NearMiss
from imblearn.combine import SMOTETomek

import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics

import multiprocessing


# df_train = pd.read_csv('../data/xxx/file_train.csv')
# df_test = pd.read_csv('../data/xxx/file_test.csv')

# # !cat "{OUTPUT_DIR}/0_0_1_experiments_roc_summary.txt"
# # !rm "{OUTPUT_DIR}/0_0_1_experiments_roc_summary.txt"

# with open(f"{OUTPUT_DIR}/0_0_1_experiments_roc_summary.txt", "a") as fp:
#     print('hep', file= fp )
