| import pandas as pd
|
| import numpy as np
|
| from concurrent.futures import ThreadPoolExecutor
|
| max_timesteps=299
|
| feature_num=16
|
| label_nums=9
|
|
|
| def generate_partial_sequences(row, max_timesteps=max_timesteps, features_per_timestep=feature_num, fill_value=-10):
|
|
|
| actual_length_indices = np.where(row[:-label_nums] != fill_value)[0]
|
| if len(actual_length_indices) > 0:
|
| actual_length = (actual_length_indices[-1] // features_per_timestep) + 1
|
| else:
|
| actual_length = 0
|
| partial_sequences = []
|
|
|
| step_size =5
|
|
|
| for end_length in range(step_size, actual_length + step_size, step_size):
|
|
|
| end_length = min(end_length, actual_length)
|
| partial_sequence_list = row[:end_length * features_per_timestep].tolist()
|
|
|
| selected_features_list = [partial_sequence_list[i:i + 10] for i in
|
| range(0, len(partial_sequence_list), features_per_timestep)]
|
| selected_features_list = [item for sublist in selected_features_list for item in sublist]
|
|
|
| ProgressOfTask= end_length/actual_length
|
|
|
| hand_rotation_axis = partial_sequence_list[-6:-3]
|
| hand_direction = partial_sequence_list[-3:]
|
|
|
| padding_length = (max_timesteps - end_length) * (features_per_timestep-6)
|
| selected_features_list.extend([fill_value] * padding_length)
|
|
|
| selected_features_list.extend(row[-9:])
|
| selected_features_list.extend(hand_rotation_axis)
|
| selected_features_list.extend(hand_direction)
|
| selected_features_list.append(ProgressOfTask)
|
|
|
| partial_sequences.append(selected_features_list)
|
| return partial_sequences
|
|
|
|
|
| def process_row(index, df):
|
| """Wrapper function to handle the DataFrame row."""
|
| row=df.iloc[index]
|
| return generate_partial_sequences(row)
|
|
|
|
|
| def main(df, num_threads=20):
|
| """Process the DataFrame using multiple threads."""
|
| with ThreadPoolExecutor(max_workers=num_threads) as executor:
|
|
|
| futures = [executor.submit(process_row, index, df) for index in range(len(df))]
|
|
|
| results = []
|
| for future in futures:
|
| results.extend(future.result())
|
|
|
|
|
| columns = df.columns
|
|
|
| columns_to_keep = [column for column in columns if
|
| not column.startswith('HandRotationAxis') and not column.startswith('HandDirection')]
|
|
|
|
|
|
|
| columns_to_keep.extend([
|
| 'HandRotationAxis_X', 'HandRotationAxis_Y', 'HandRotationAxis_Z',
|
| 'HandDirection_X', 'HandDirection_Y', 'HandDirection_Z',
|
| 'ProgressOfTask'
|
| ])
|
|
|
| partial_sequences_df = pd.DataFrame(results, columns=columns_to_keep)
|
| return partial_sequences_df
|
|
|
| if __name__ == '__main__':
|
|
|
| for i in range(79, 80):
|
|
|
|
|
| file_path = f'../Data/Study2Evaluation/Supervised/{i}_train_data_preprocessed_evaluation.csv'
|
| df = pd.read_csv(file_path)
|
| partial_sequences_df = main(df)
|
| save_path_csv = f'../Data/Study2Evaluation/Dataset/{i}_traindataset.csv'
|
| partial_sequences_df.to_csv(save_path_csv, index=False)
|
|
|
| file_path = f'../Data/Study2Evaluation/Supervised/{i}_test_data_preprocessed_evaluation.csv'
|
| df = pd.read_csv(file_path)
|
| partial_sequences_df = main(df)
|
| save_path_csv = f'../Data/Study2Evaluation/Dataset/{i}_testdataset.csv'
|
| partial_sequences_df.to_csv(save_path_csv, index=False)
|
|
|
|
|
|
|