import numpy as np
from typing import Any, Dict, List, Tuple, NoReturn


import argparse
import os

def parse_arguments() -> Any:
	"""Parse command line arguments."""

	parser = argparse.ArgumentParser()
	
	parser.add_argument(
		"--data_dir",
		default="",
		type=str,
		help="Directory where the features (npy files) are saved",
	)

	parser.add_argument("--mode",
						required=True,
						type=str,
						help="train/val/test/sample",
						choices=['train', 'test', 'val','sample'])

	parser.add_argument("--obs_len",
						default=2,
						type=int,
						help="Observed length of the trajectory in seconds",
						choices=[1,2,3,4,5])

	parser.add_argument("--filter",
						default='ekf',
						type=str,
						help="Filter to process the data noise. (ekf/none/ekf-savgol/savgol",
						choices=['ekf', 'none', 'ekf-savgol', 'savgol'])

	return parser.parse_args()

def stats(traj:np.ndarray) -> NoReturn:

	#central tendency : mean
	#dispersion       : std
	#bounds           : min max
	#quantile         : 0.25, 0.5, 0.75

	labels = ['mean_v', 'mean_acc', 'mean_deac', 'std_jy']

	for i, l in zip(range(0, traj.shape[1]), labels):
		t = traj[:, i]
		_mean = round(np.mean(t),2)
		_std  = round(np.std(t),2)
		_min  = round(np.min(t),2)
		_max  = round(np.max(t),2)
		_q25  = round(np.quantile(t, 0.25),2)
		_q50  = round(np.quantile(t, 0.5),2)
		_q75  = round(np.quantile(t, 0.75),2)

		print (f'Feature: {l}')
		print ('\tmean:{} | std:{} | min:{} | max:{} | q25:{} | q50:{} | q75:{}'.format(_mean,
				_std, _min, _max, _q25, _q50, _q75))



if __name__== '__main__':

	#_filters = ['none', 'ekf', 'savgol', 'ekf-savgol']
	#_modes = ['train', 'val', 'test', 'sample']
	#_obs_len = [2,5]

	#seg = _obs_len[0]
	#mode = _modes[3]
	#filter_name = _filters[0]
	
	args = parse_arguments()

	if args.mode == 'test':
		args.obs_len = 2
		
	assert os.path.exists(args.data_dir),\
		f'[Analysis][main][ERROR] data_dir not found!({args.data_dir})'

	data_file = 'features_{}_{}s_{}.npy'.format(args.mode,
				 								args.obs_len,
				 								args.filter)

	assert os.path.exists(os.path.join(args.data_dir, data_file)),\
		f'[Analysis][main][ERROR] data_file not found!({data_file})'

	print ('[Analysis] loading dataset....')
	# (m, 4)
	# [mean_v, mean_acc, mean_deac, std_jy]
	data = np.load(os.path.join(args.data_dir,data_file))


	print ('[Analysis] mode:{} | filter:{} | obs_len:{}'.format(args.mode, 
															    args.filter, 
															    args.obs_len))
	print ('[Analysis] data shape:{}'.format(data.shape))

	print ('[Analysis] stats:')
	stats(data)






[((11, 10, 11, 35), 'argparse.ArgumentParser', 'argparse.ArgumentParser', ({}, {}), '()', False, 'import argparse\n'), ((80, 8, 80, 37), 'os.path.exists', 'os.path.exists', ({(80, 23, 80, 36): 'args.data_dir'}, {}), '(args.data_dir)', False, 'import os\n'), ((87, 23, 87, 61), 'os.path.join', 'os.path.join', ({(87, 36, 87, 49): 'args.data_dir', (87, 51, 87, 60): 'data_file'}, {}), '(args.data_dir, data_file)', False, 'import os\n'), ((93, 16, 93, 53), 'os.path.join', 'os.path.join', ({(93, 29, 93, 42): 'args.data_dir', (93, 43, 93, 52): 'data_file'}, {}), '(args.data_dir, data_file)', False, 'import os\n'), ((51, 16, 51, 26), 'numpy.mean', 'np.mean', ({(51, 24, 51, 25): 't'}, {}), '(t)', True, 'import numpy as np\n'), ((52, 16, 52, 25), 'numpy.std', 'np.std', ({(52, 23, 52, 24): 't'}, {}), '(t)', True, 'import numpy as np\n'), ((53, 16, 53, 25), 'numpy.min', 'np.min', ({(53, 23, 53, 24): 't'}, {}), '(t)', True, 'import numpy as np\n'), ((54, 16, 54, 25), 'numpy.max', 'np.max', ({(54, 23, 54, 24): 't'}, {}), '(t)', True, 'import numpy as np\n'), ((55, 16, 55, 36), 'numpy.quantile', 'np.quantile', ({(55, 28, 55, 29): 't', (55, 31, 55, 35): '0.25'}, {}), '(t, 0.25)', True, 'import numpy as np\n'), ((56, 16, 56, 35), 'numpy.quantile', 'np.quantile', ({(56, 28, 56, 29): 't', (56, 31, 56, 34): '0.5'}, {}), '(t, 0.5)', True, 'import numpy as np\n'), ((57, 16, 57, 36), 'numpy.quantile', 'np.quantile', ({(57, 28, 57, 29): 't', (57, 31, 57, 35): '0.75'}, {}), '(t, 0.75)', True, 'import numpy as np\n')]