2021-06-22 13:32:51 +00:00
|
|
|
import pandas as pd
|
2021-06-22 18:31:16 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2021-06-23 09:33:23 +00:00
|
|
|
from pandas.core.frame import DataFrame
|
|
|
|
|
2021-06-23 09:17:59 +00:00
|
|
|
class Data_container:
|
|
|
|
|
2021-06-23 09:33:23 +00:00
|
|
|
def __init__(self, subject_nr:int, subject_name:str):
|
|
|
|
self.subject_nr = subject_nr
|
|
|
|
self.subject_name = subject_name
|
2021-06-23 09:41:06 +00:00
|
|
|
self.data_dict = {'left': [None]*8, 'right': [None]*8}
|
2021-06-23 09:17:59 +00:00
|
|
|
|
2021-06-22 18:31:16 +00:00
|
|
|
class CSV_handler:
|
|
|
|
|
2021-06-22 18:54:42 +00:00
|
|
|
def __init__(self):
|
2021-06-23 09:33:23 +00:00
|
|
|
self.working_dir = str(Path.cwd())
|
|
|
|
self.data_container_dict = {} # Dict with keys equal subject numbers and values equal the relvant datacontainer
|
2021-06-22 18:31:16 +00:00
|
|
|
|
2021-06-22 19:00:51 +00:00
|
|
|
# Makes dataframe from the csv files in the working directory
|
2021-06-22 19:30:55 +00:00
|
|
|
def make_df(self, filename):
|
2021-06-22 18:31:16 +00:00
|
|
|
filepath = self.working_dir + str(filename)
|
|
|
|
df = pd.read_csv(filepath)
|
|
|
|
return df
|
2021-06-22 19:00:51 +00:00
|
|
|
|
2021-06-23 09:33:23 +00:00
|
|
|
# Extracts out the timestamp and the selected emg signal into a new dataframe and stores the data on the subject
|
2021-06-23 11:52:18 +00:00
|
|
|
def get_time_emg_table(self, filename:str, emg_nr:int):
|
2021-06-23 08:32:38 +00:00
|
|
|
tot_data_frame = self.make_df(filename)
|
2021-06-23 09:01:02 +00:00
|
|
|
emg_str = 'emg' + str(emg_nr)
|
2021-06-22 19:00:51 +00:00
|
|
|
filtered_df = tot_data_frame[["timestamp", emg_str]]
|
2021-06-23 11:52:18 +00:00
|
|
|
return filtered_df
|
|
|
|
|
2021-06-23 12:17:12 +00:00
|
|
|
def store_df(self, filename:str, emg_nr:int, which_arm:str, data_container:Data_container):
|
2021-06-23 11:52:18 +00:00
|
|
|
df = self.get_min_max_timestamp(filename, emg_nr)
|
2021-06-23 09:41:06 +00:00
|
|
|
# Links the retrieved data with the subjects data_container
|
2021-06-23 09:33:23 +00:00
|
|
|
subject_nr = data_container.subject_nr
|
|
|
|
self.data_container_dict[subject_nr] = data_container
|
2021-06-23 09:41:06 +00:00
|
|
|
# Places the data correctly:
|
|
|
|
if which_arm is 'left':
|
2021-06-23 11:52:18 +00:00
|
|
|
data_container.data_dict['left'][emg_nr+1] = df
|
2021-06-22 19:00:51 +00:00
|
|
|
|
2021-06-23 13:56:35 +00:00
|
|
|
def get_emg_str(emg_nr):
|
|
|
|
return 'emg' + str(emg_nr)
|
2021-06-22 19:00:51 +00:00
|
|
|
|
2021-06-23 13:56:35 +00:00
|
|
|
def get_min_max_timestamp(df:DataFrame):
|
|
|
|
min = df['timestamp'].argmin
|
|
|
|
max = df['timestamp'].argmax
|
|
|
|
return min, max
|
2021-06-22 18:31:16 +00:00
|
|
|
|
2021-06-22 13:32:51 +00:00
|
|
|
|
|
|
|
|