def Recog_Data(filename): # filename: string raw_data = readfile.loadfile(filename) data = Calfoot.Cal_foot(raw_data) p1, p2 = [], [] for i in range(len(data['Position_r'])): p1.append(np.sqrt(np.sum(np.square(data['Position_r'][i, :])))) p2.append(np.sqrt(np.sum(np.square(data['Position_l'][i, :])))) i = 0 while p1[i] == 0 and p2[i] == 0: i = i + 1 j = len(p1) - 1 last_p1, last_p2 = p1[-1], p2[-1] while abs(p1[j] - last_p1) < 0.01 and abs(p2[j] - last_p2) < 0.01: j = j - 1 Angle = Calangle.Cal_angle(1, raw_data)[i:j, :] # Length of the sequence seq_len = 25 data_temp = [] for index in range(len(Angle) - seq_len + 1): data_temp.append(Angle[index:index + seq_len, :]) data_temp = np.array(data_temp) data = {} data['x_action'] = data_temp return data
def Detect_phase(filename): # filename: string raw_data = readfile.loadfile(filename) Angle = Calangle.Cal_angle(1, raw_data) Foot = Calfoot.Cal_foot(raw_data) # Determine when the person is walking p1, p2 = [], [] for i in range(len(Foot['Position_r'])): p1.append(np.sqrt(np.sum(np.square(Foot['Position_r'][i, :])))) p2.append(np.sqrt(np.sum(np.square(Foot['Position_l'][i, :])))) i = 0 while p1[i] == 0 and p2[i] == 0: i = i + 1 j = len(p1) - 1 last_p1, last_p2 = p1[-1], p2[-1] while abs(p1[j] - last_p1) < 0.01 and abs(p2[j] - last_p2) < 0.01: j = j - 1 data = np.zeros([i]).tolist() temp = np.zeros([len(Foot['Position_r']) - j]).tolist() detect_data = phase_detect(Angle[i:j, :]) data = data + detect_data + temp return data
def Process_data(filename): # filename string raw_data = readfile.loadfile(filename) data = Calfoot.Cal_foot(raw_data) p1, p2 = [], [] for i in range(len(data['Position_r'])): p1.append(np.sqrt(np.sum(np.square(data['Position_r'][i, :])))) p2.append(np.sqrt(np.sum(np.square(data['Position_l'][i, :])))) i = 0 while p1[i] == 0 and p2[i] == 0: i = i + 1 j = len(p1) - 1 last_p1, last_p2 = p1[-1], p2[-1] while abs(p1[j] - last_p1) < 0.01 and abs(p2[j] - last_p2) < 0.01: j = j - 1 Angle = Calangle.Cal_angle(1, raw_data)[i:j, :] temp = np.zeros([Angle.shape[0], 1]) if filename[0:3] == 'zou': temp = np.append(temp + 1, np.zeros([Angle.shape[0], 3]), 1) elif filename[0:3] == 'lou': temp = np.append(temp, temp + 1, 1) temp = np.append(temp, np.zeros([Angle.shape[0], 2]), 1) elif filename[0:3] == 'zuo': temp = np.append(np.zeros([Angle.shape[0], 2]), temp + 1, 1) temp = np.append(temp, np.zeros([Angle.shape[0], 1]), 1) elif filename[0:3] == 'you': temp = np.append(np.zeros([Angle.shape[0], 3]), temp + 1, 1) Angle = np.append(Angle, temp, 1) # Length of the sequence seq_len = 25 data_temp = [] for index in range(len(Angle) - seq_len + 1): data_temp.append(Angle[index:index + seq_len, :]) data = np.array(data_temp) return data
import Calangle # Calculate the angle of each joint import Calfoot # Calculate the state and the position of each foot import CorrectData # Pre-process the data for correcting import Correct # Correct the Knee angle import TrainCorrect # Train the model import readfile # Read the raw file and return a list(N * 9) import h5py filename = 'zou4.TXT' raw_data = readfile.loadfile(filename) # raw_data is a list(N * 9) Angle = Calangle.Cal_angle(1, raw_data) # Angle is a list((N/7) * 14) Foot = Calfoot.Cal_foot(raw_data) # Foot is a dictionary, the keys are 'Stationary_r', 'Position_l', 'Position_r', 'Stationary_l' # which mean whether the foot is on the field and what the position of each foot is modelname = '' Data_for_Cor = CorrectData.Correct_Data(raw_data) # Data for Correcting the Knee joint Data_for_Tra = CorrectData.Train_Correct_Data(raw_data) # Data for Training the model TrainCorrect.Train_model(Data_for_Tra, modelname) # Train or update the model and save it # The previous one is saved 'modelname_old' Corrected_Data = Correct.Correct(Data_for_Cor, modelname) # Return the corrected angle data, which has the same size with Angle
thigh_l_len = thigh_r_len = Upper_leg_length crus_l_len = crus_r_len = Lower_leg_length foot_l_len = foot_r_len = foot_size hipjoint_len = width bodydata = { str(thigh_l_len): thigh_l_len, str(thigh_r_len): thigh_r_len, str(crus_l_len): crus_l_len, str(crus_r_len): crus_r_len, str(foot_l_len): foot_l_len, str(foot_r_len): foot_r_len, str(hipjoint_len): hipjoint_len } data = readfile.loadfile('zou41.txt') data = np.array(data) acc = np.delete(data, [4, 5, 6, 7], 1) acc = acc.tolist() qu = np.delete(data, [1, 2, 3], 1) qu = qu.tolist() postdata = { 'name': 'test', 'gather_time': '2018-5-22T21:00', 'device_id': '1', 'exercise_id': '7', 'acceleration': str(acc), 'quaternians': str(qu), 'myoelectricity': '' } re = PostData.postfile(url, header, 'firsthand', postdata)