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

from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

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

from config.constant import Values
import components.data
import components.train
import components.predict
import components.evaluate
import components.group_filter



if __name__ == '__main__':
	logging.config.dictConfig(Values.log_init_config)
	logger = logging.getLogger(__name__)
	parser = argparse.ArgumentParser()
	parser.add_argument("mode", help="train, evaluate, filter")
	parser.add_argument("--model_dir", help=(
	    "directory to save/load trained models"), default=Values.prediction_model_directory)

	args = parser.parse_args()
	

	if args.mode == "filter":
		data = components.data.complete_set(Values.all_labeled_tainted_groups_multiIMG_path)
		group_filter = components.group_filter.GroupFilter()
		group_filter.filter(data,Values.all_filtered_labeled_tainted_groups_path)

		# data = components.data.complete_set(Values.all_train_labeled_tainted_groups_multiIMG_path)
		# group_filter = components.group_filter.GroupFilter()
		# group_filter.filter(data,Values.all_filter_train_labeled_tainted_groups_multiIMG_path)

		# data = components.data.complete_set(Values.all_test_labeled_tainted_groups_multiIMG_path)
		# group_filter = components.group_filter.GroupFilter()
		# group_filter.filter(data,Values.all_filter_test_labeled_tainted_groups_multiIMG_path)
		

	elif args.mode == "train":
		train = components.data.complete_set(Values.all_filter_train_labeled_tainted_groups_multiIMG_path)

		print(len(train))
		components.train.train(train, args.model_dir)
	elif args.mode == "evaluate":
		test = components.data.complete_set(Values.all_filter_test_labeled_tainted_groups_multiIMG_path)

		predicted = components.predict.predict(test, args.model_dir)
		components.evaluate.evaluate(predicted)
