#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import logging
import logging.config
import os.path

from config.constant import Values
import components.data
import model.feature_model
from semantic.taint import GroupLabel
import components.predict
import components.evaluate
import visitor.loader


from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import VotingClassifier
from sklearn.externals import joblib
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import ShuffleSplit
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import FunctionTransformer
from sklearn.preprocessing import LabelEncoder
from sklearn.svm import LinearSVC
from sklearn.linear_model import LinearRegression


label_encoder = None


def split_train_test_data():
	data = accessor.loader.JsonLoader.load(Values.all_labeled_tainted_groups_multiIMG_path)
	train, test = modules.data.split_set(groups=data, test_percentage=0.5,
		                                       shuffle=True)
	accessor.saver.JsonSaver.save(train,Values.all_train_labeled_tainted_groups_multiIMG_path)
	accessor.saver.JsonSaver.save(test,Values.all_test_labeled_tainted_groups_multiIMG_path)


if __name__ == '__main__':
	# split_train_test_data()
	# exit()

	parser = argparse.ArgumentParser()
	parser.add_argument("--type",default=None)
	args = parser.parse_args()
	print(args.type)


	logging.config.dictConfig(Values.log_init_config)
	logger = logging.getLogger(__name__)

	
	logger.info('----behaviour model')
	filter_train_groups = modules.data.complete_set(Values.all_filter_train_labeled_tainted_groups_multiIMG_path)
	filter_test_groups = modules.data.complete_set(Values.all_filter_test_labeled_tainted_groups_multiIMG_path)
	from model.test_models_behaviours import MutliFeatureModelsBehaviours
	feature_model = MutliFeatureModelsBehaviours()
	feature_model.evaluate_single_model_with_behaviors(filter_train_groups,filter_test_groups,args.type)
	# feature_model.evaluate_models_with_behaviors(filter_train_groups,filter_test_groups)

	# logger.info('----text model')
	# train_groups = modules.data.complete_set(Values.all_train_labeled_tainted_groups_multiIMG_path)
	# test_groups = modules.data.complete_set(Values.all_test_labeled_tainted_groups_multiIMG_path)
	# from model.test_models import MutliFeatureModels
	# feature_model = MutliFeatureModels()
	# feature_model.evaluate_single_classifier(train_groups,test_groups)
	# feature_model.evaluate_models(train_groups,test_groups)

