diff --git a/Handle_emg_data.py b/Handle_emg_data.py index ee45e72..ee03c45 100644 --- a/Handle_emg_data.py +++ b/Handle_emg_data.py @@ -33,34 +33,38 @@ class CSV_handler: filtered_df = tot_data_frame[["timestamp", emg_str]] return filtered_df - def store_df(self, filename:str, emg_nr:int, which_arm:str, data_container:Data_container, round:int): - df = self.get_min_max_timestamp(filename, emg_nr) + def store_df_in_container(self, filename:str, emg_nr:int, which_arm:str, data_container:Data_container, round:int): + df = self.get_time_emg_table(filename, emg_nr+1) + + # Places the data correctly: + if round == 1: + if which_arm == 'left': + data_container.data_dict_round1['left'][emg_nr] = df # Zero indexed emg_nr in the dict + else: + data_container.data_dict_round1['right'][emg_nr] = df + elif round == 2: + if which_arm == 'left': + data_container.data_dict_round2['left'][emg_nr] = df + else: + data_container.data_dict_round2['right'][emg_nr] = df + elif round == 3: + if which_arm == 'left': + data_container.data_dict_round3['left'][emg_nr] = df + else: + data_container.data_dict_round3['right'][emg_nr] = df + elif round == 4: + if which_arm == 'left': + data_container.data_dict_round4['left'][emg_nr] = df + else: + data_container.data_dict_round4['right'][emg_nr] = df + else: + raise IndexError('Not a valid index') + + def link_container_to_handler(self, data_container:Data_container): # Links the retrieved data with the subjects data_container subject_nr = data_container.subject_nr self.data_container_dict[subject_nr] = data_container - # Places the data correctly: - if round == 0: - if which_arm == 'left': - data_container.data_dict_round1['left'][emg_nr+1] = df - else: - data_container.data_dict_round1['right'][emg_nr+1] = df - elif round == 1: - if which_arm == 'left': - data_container.data_dict_round2['left'][emg_nr+1] = df - else: - data_container.data_dict_round2['right'][emg_nr+1] = df - elif round == 2: - if which_arm == 'left': - data_container.data_dict_round3['left'][emg_nr+1] = df - else: - data_container.data_dict_round3['right'][emg_nr+1] = df - elif round == 3: - if which_arm == 'left': - data_container.data_dict_round4['left'][emg_nr+1] = df - else: - data_container.data_dict_round4['right'][emg_nr+1] = df - else: - raise IndexError('Not a valid index') + print(data_container.subject_name) # Loads the data from the csv files into a storing system in an CSV_handler object def load_hard_PP_emg_data(self): @@ -131,6 +135,7 @@ class CSV_handler: subject1_data_container = Data_container(1, 'HaluskaMarek') + #print(subject1_data_container.data_dict_round1) subject2_data_container = Data_container(1, 'HaluskaMaros') subject3_data_container = Data_container(1, 'HaluskovaBeata') subject4_data_container = Data_container(1, 'KelisekDavid') @@ -142,11 +147,11 @@ class CSV_handler: # left variant proccessed here for round in range(4): for emg_nr in range(8): - self.store_df(left_list[subject_nr][round], emg_nr+1, 'left', subject_data_container_list[subject_nr]) + self.store_df(left_list[subject_nr][round], emg_nr, 'left', subject_data_container_list[subject_nr], round+1) # right variant proccessed here for round in range(4): for emg_nr in range(8): - self.store_df(right_list[subject_nr][round], emg_nr+1, 'right', subject_data_container_list[subject_nr]) + self.store_df(right_list[subject_nr][round], emg_nr, 'right', subject_data_container_list[subject_nr], round+1) return self.data_container_dict diff --git a/Test_functions.py b/Test_functions.py index f552a39..6321cdf 100644 --- a/Test_functions.py +++ b/Test_functions.py @@ -1,6 +1,6 @@ from Handle_emg_data import * import matplotlib.pyplot as plt -from Signal_prep import * +#from Signal_prep import * def test_df_extraction(emg_nr): handler = CSV_handler() @@ -14,8 +14,9 @@ def test_df_extraction(emg_nr): def test_load_func(): handler = CSV_handler() test_dict = handler.load_hard_PP_emg_data() - subject2_container = test_dict[2] - print(subject2_container.data_dict['left'][1]) + subject2_container = test_dict.get(2) + print(subject2_container) + print(subject2_container.data_dict_round1.get('left')[1]) def test_min_max_func(): handler = CSV_handler() @@ -30,7 +31,6 @@ def test_fft_prep(): file = "/Exp20201205_2myo_hardTypePP/HaluskaMarek_20201207_1810/myoLeftEmg.csv" df = handler.get_time_emg_table(file, 1) - def test_plot_wavelet_both_ways(): handler = CSV_handler() file = "/Exp20201205_2myo_hardTypePP/HaluskaMarek_20201207_1810/myoLeftEmg.csv" @@ -49,4 +49,4 @@ def test_plot_wavelet_both_ways(): #print(len(y_new_values)) plot_arrays(N, y_new_values) -test_plot_wavelet_both_ways() \ No newline at end of file +test_load_func() \ No newline at end of file diff --git a/__pycache__/Handle_emg_data.cpython-38.pyc b/__pycache__/Handle_emg_data.cpython-38.pyc index b4802c0..1f33070 100644 Binary files a/__pycache__/Handle_emg_data.cpython-38.pyc and b/__pycache__/Handle_emg_data.cpython-38.pyc differ diff --git a/__pycache__/Signal_prep.cpython-38.pyc b/__pycache__/Signal_prep.cpython-38.pyc index 0df3168..a1d5822 100644 Binary files a/__pycache__/Signal_prep.cpython-38.pyc and b/__pycache__/Signal_prep.cpython-38.pyc differ