import pandas as pd
import numpy as np
import datetime
from mvp import xgbreport
from mvp import lgbreport
from data.analyis import datacal
from models import xgboost
from models import lightgbm


from mvp import dhb

dhb = dhb.dhb()
df_sample = dhb.dhb_features_extract()
target = 'target'
features = dhb.features
df_sample[features] = df_sample[features].astype(float)
df_sample['target'] = df_sample['target'].astype(int)
print('period of time: ',dhb.start_time_period,'-',dhb.end_time_period)
print('----no.',len(features),'of samples of dhb----')

# to save model performance

if __name__ == '__main__':

    # data extraction

    ''' ## Old Edition here
    # if total sample more than 30000, it would use train-validation-test
    # else use CV to parameters tuning

    # if len(df_sample) >= 30000:
    #     df_train,df_val,df_test = datacal.train_test_split_general(df_sample, val_size=0.25, test_size=0.25, stratify='target', random_state=7)
    # else:
    #     df_train,df_test = datacal.train_test_split_general(df_sample, val_size=None, test_size=0.25, stratify='target', random_state=7)
    '''
    df_train, df_val, df_test = train_test_split_general()

    # data manipulation
    ## TODO



    # model refit



    #xgboost
    xgb_model_auc = {'training_auc' : None, 'val_auc' : None, 'test_auc' : None}
    xgb_model_auc['training_auc'] = None
    xgb_model_auc['val_auc'] = None

    #xgbreport.report(df_train, df_test, df_val, features, target, '','dhb模型迭代报告.doc', kfold = 2)

    ## 待加入 ： xgb 各dataset的 auc, KA 渠道 / 客群 的 auc

    #ligthtgbm
    lgb_model_auc = {'training_auc' : None, 'val_auc' : None, 'test_auc' : None}
    lgb_model_auc['training_auc'] = None
    lgb_model_auc['val_auc'] = None

    #dftrain,dftest = datacal.split_train_val(df_sample,trainsplit = 'timeSeries',trainsplitRatio=0.8,sort_col='applied_at')
    #lgbreport.report(df_train, df_test, df_val, features, target,'','dhb模型迭代报告.doc', kfold = 2)

    # merge as single dataframe full of models
    pd.DataFrame(xgb_model)





