#Encode laban
import json
import os.path as osp
import pandas as pd
from sklearn.preprocessing import OneHotEncoder
import numpy as np
import copy


def laban_encoder(annotation_laban):
    laban_list = []
    laban_onehot = {}
    laban = []
    laban_onehot['Place, High'] = 0
    laban_onehot['Place, Low'] = 1
    laban_onehot['Forward, Low'] = 2
    laban_onehot['Left Forward, Low'] = 3
    laban_onehot['Left, Low'] = 4
    laban_onehot['Left Backward, Low'] = 5
    laban_onehot['Backward, Low'] = 6
    laban_onehot['Right Backward, Low'] = 7
    laban_onehot['Right, Low'] = 8
    laban_onehot['Right Forward, Low'] = 9
    laban_onehot['Forward, High'] = 10
    laban_onehot['Left Forward, High'] = 11
    laban_onehot['Left, High'] = 12
    laban_onehot['Left Backward, High'] = 13
    laban_onehot['Backward, High'] = 14
    laban_onehot['Right Backward, High'] = 15
    laban_onehot['Right, High'] = 16
    laban_onehot['Right Forward, High'] = 17
    laban_onehot['Forward, Normal'] = 18
    laban_onehot['Left Forward, Normal'] = 19
    laban_onehot['Left, Normal'] = 20
    laban_onehot['Left Backward, Normal'] = 21
    laban_onehot['Backward, Normal'] = 22
    laban_onehot['Right Backward, Normal'] = 23
    laban_onehot['Right, Normal'] = 24
    laban_onehot['Right Forward, Normal'] = 25
    # laban_list = laban_onehot.keys()
    # features = np.array(range(26)).reshape(-1,1)
    # enc = OneHotEncoder(sparse= False)
    # onehot = enc.fit_transform(features)
    onehot = np.eye(26)
    # print(onehot)
    laban_onehot['Place, High'] = onehot[0]
    laban_onehot['Place, Low'] = onehot[1]
    laban_onehot['Forward, Low'] = onehot[2]
    laban_onehot['Left Forward, Low'] = onehot[3]
    laban_onehot['Left, Low'] = onehot[4]
    laban_onehot['Left Backward, Low'] = onehot[5]
    laban_onehot['Backward, Low'] = onehot[6]
    laban_onehot['Right Backward, Low'] = onehot[7]
    laban_onehot['Right, Low'] = onehot[8]
    laban_onehot['Right Forward, Low'] = onehot[9]
    laban_onehot['Forward, High'] = onehot[10]
    laban_onehot['Left Forward, High'] = onehot[11]
    laban_onehot['Left, High'] = onehot[12]
    laban_onehot['Left Backward, High'] = onehot[13]
    laban_onehot['Backward, High'] = onehot[14]
    laban_onehot['Right Backward, High'] = onehot[15]
    laban_onehot['Right, High'] = onehot[16]
    laban_onehot['Right Forward, High'] = onehot[17]
    laban_onehot['Forward, Normal'] = onehot[18]
    laban_onehot['Left Forward, Normal'] = onehot[19]
    laban_onehot['Left, Normal'] = onehot[20]
    laban_onehot['Left Backward, Normal'] = onehot[21]
    laban_onehot['Backward, Normal'] = onehot[22]
    laban_onehot['Right Backward, Normal'] = onehot[23]
    laban_onehot['Right, Normal'] = onehot[24]
    laban_onehot['Right Forward, Normal'] = onehot[25]
    # split = 'train'
    # root_dir_path = osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__))))
    # data_dir = osp.join(root_dir_path, 'data')
    # annotation_dir = osp.join(data_dir, 'annotations')
    # split_annotation_dir = osp.join(annotation_dir, split)
    # laban_file_name = 'InterHand2.6M_' + split + '_laban.json'
    # laban_path = osp.join(split_annotation_dir, laban_file_name)
    # f = open(laban_path, 'r')
    # laban_data = json.load(f)
    # laban_encode_ans = {}
    annotation_laban_encode = copy.deepcopy(annotation_laban)
    for key in annotation_laban['right_hand_laban']:
        laban_string = annotation_laban['right_hand_laban'][key]
        laban_string = laban_string[0] + ', ' + laban_string[1]
        annotation_laban_encode['right_hand_laban'][key] = laban_onehot[laban_string]
    for key in annotation_laban['left_hand_laban']:
        laban_string = annotation_laban['left_hand_laban'][key]
        laban_string = laban_string[0] + ', ' + laban_string[1]
        annotation_laban_encode['left_hand_laban'][key] = laban_onehot[laban_string]
    laban_righthand = list(annotation_laban_encode['right_hand_laban'].values())
    laban_lefthand = list(annotation_laban_encode['left_hand_laban'].values())
    laban = laban_righthand + laban_lefthand
    laban_matrix = np.array(laban) 
    
    return laban_matrix

if __name__ == '__main__':
    features = np.array(range(26)).reshape(-1,1)
    enc = OneHotEncoder(sparse= False)
    onehot1 = enc.fit_transform(features)
    onehot = np.eye(26)
    print('test')
    

    
