chore: split up storing func to one storing func

and one linking func
This commit is contained in:
Skudalen 2021-06-25 10:43:59 +02:00
parent 8a6f8d6329
commit 2a48a0abfd
4 changed files with 37 additions and 32 deletions

View File

@ -33,34 +33,38 @@ class CSV_handler:
filtered_df = tot_data_frame[["timestamp", emg_str]] filtered_df = tot_data_frame[["timestamp", emg_str]]
return filtered_df return filtered_df
def store_df(self, filename:str, emg_nr:int, which_arm:str, data_container:Data_container, round:int): def store_df_in_container(self, filename:str, emg_nr:int, which_arm:str, data_container:Data_container, round:int):
df = self.get_min_max_timestamp(filename, emg_nr) 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 # Links the retrieved data with the subjects data_container
subject_nr = data_container.subject_nr subject_nr = data_container.subject_nr
self.data_container_dict[subject_nr] = data_container self.data_container_dict[subject_nr] = data_container
# Places the data correctly: print(data_container.subject_name)
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')
# Loads the data from the csv files into a storing system in an CSV_handler object # Loads the data from the csv files into a storing system in an CSV_handler object
def load_hard_PP_emg_data(self): def load_hard_PP_emg_data(self):
@ -131,6 +135,7 @@ class CSV_handler:
subject1_data_container = Data_container(1, 'HaluskaMarek') subject1_data_container = Data_container(1, 'HaluskaMarek')
#print(subject1_data_container.data_dict_round1)
subject2_data_container = Data_container(1, 'HaluskaMaros') subject2_data_container = Data_container(1, 'HaluskaMaros')
subject3_data_container = Data_container(1, 'HaluskovaBeata') subject3_data_container = Data_container(1, 'HaluskovaBeata')
subject4_data_container = Data_container(1, 'KelisekDavid') subject4_data_container = Data_container(1, 'KelisekDavid')
@ -142,11 +147,11 @@ class CSV_handler:
# left variant proccessed here # left variant proccessed here
for round in range(4): for round in range(4):
for emg_nr in range(8): 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 # right variant proccessed here
for round in range(4): for round in range(4):
for emg_nr in range(8): 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 return self.data_container_dict

View File

@ -1,6 +1,6 @@
from Handle_emg_data import * from Handle_emg_data import *
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from Signal_prep import * #from Signal_prep import *
def test_df_extraction(emg_nr): def test_df_extraction(emg_nr):
handler = CSV_handler() handler = CSV_handler()
@ -14,8 +14,9 @@ def test_df_extraction(emg_nr):
def test_load_func(): def test_load_func():
handler = CSV_handler() handler = CSV_handler()
test_dict = handler.load_hard_PP_emg_data() test_dict = handler.load_hard_PP_emg_data()
subject2_container = test_dict[2] subject2_container = test_dict.get(2)
print(subject2_container.data_dict['left'][1]) print(subject2_container)
print(subject2_container.data_dict_round1.get('left')[1])
def test_min_max_func(): def test_min_max_func():
handler = CSV_handler() handler = CSV_handler()
@ -30,7 +31,6 @@ def test_fft_prep():
file = "/Exp20201205_2myo_hardTypePP/HaluskaMarek_20201207_1810/myoLeftEmg.csv" file = "/Exp20201205_2myo_hardTypePP/HaluskaMarek_20201207_1810/myoLeftEmg.csv"
df = handler.get_time_emg_table(file, 1) df = handler.get_time_emg_table(file, 1)
def test_plot_wavelet_both_ways(): def test_plot_wavelet_both_ways():
handler = CSV_handler() handler = CSV_handler()
file = "/Exp20201205_2myo_hardTypePP/HaluskaMarek_20201207_1810/myoLeftEmg.csv" file = "/Exp20201205_2myo_hardTypePP/HaluskaMarek_20201207_1810/myoLeftEmg.csv"
@ -49,4 +49,4 @@ def test_plot_wavelet_both_ways():
#print(len(y_new_values)) #print(len(y_new_values))
plot_arrays(N, y_new_values) plot_arrays(N, y_new_values)
test_plot_wavelet_both_ways() test_load_func()