def makePrediction(dTemplate, toTest, avgDev): disregard, testDev = dtw.getDTW(dTemplate, toTest) avgSlope = linRegress.getSlopeForDifference( [i for i in range(len(avgDev))], avgDev) testSlope = linRegress.getSlopeForDifference( [i for i in range(len(testDev))], testDev) return 1 if testSlope <= avgSlope * THRESHOLD_PERCENT else 0
def authenticate(deviceID, questionTemplateFile, thresholdPercent): deviceTemplate = getTemplateFromFile(getFilePath(deviceID, DEV_TEMP_FOR_HALF_PATH)) questionTemplate = getTemplateFromFile(questionTemplateFile) avgDevelopmentScore = getTemplateFromFile(getFilePath(deviceID, DEV_DEV_FOR_HALF_PATH)) dtwScore, seqDev = dtw.getDTW(deviceTemplate, questionTemplate) avgDev = getLineForDev(avgDevelopmentScore) seqDev = getLineForDev(seqDev) avgSlope = linRegress.getSlopeForDifference([i for i in range(len(avgDev))], avgDev) seqSlope = linRegress.getSlopeForDifference([i for i in range(len(seqDev))], seqDev) return 1 if seqSlope <= avgSlope*thresholdPercent else 0
def authenticate(sID, dID): deviceTemplate = getTemplate(getFileNamePath(dID, DEV_TEMP_PATH, "d_")) sequenceTemplate = getTemplate(getFileNamePath(sID, SEQ_TEMP_PATH, "s_")) avgDevelopmentScore = getTemplate(getFileNamePath(dID, DEV_DEV_PATH, "d_")) dtwScore, seqDev = dtw.getDTW(deviceTemplate, sequenceTemplate) avgDev = getLineForDev(avgDevelopmentScore) seqDev = getLineForDev(seqDev) # plt.plot([i for i in range(len(deviceTemplate))], deviceTemplate, color='blue') # plt.plot([i for i in range(len(sequenceTemplate))], sequenceTemplate, color='red') # plt.plot([i for i in range(len(avgDev))], avgDev, color='blue') # plt.plot([i for i in range(len(seqDev))], seqDev, color='red') # plt.show() avgSlope = linRegress.getSlopeForDifference([i for i in range(len(avgDev))], avgDev) seqSlope = linRegress.getSlopeForDifference([i for i in range(len(seqDev))], seqDev) return 1 if seqSlope <= avgSlope*THRESHOLD_PERCENT else 0
def authenticate(sID, dID): deviceTemplate = getTemplate(getFileNamePath(dID, DEV_TEMP_PATH, "d_")) sequenceTemplate = getTemplate(getFileNamePath(sID, SEQ_TEMP_PATH, "s_")) avgDevelopmentScore = getTemplate(getFileNamePath(dID, DEV_DEV_PATH, "d_")) dtwScore, seqDev = dtw.getDTW(deviceTemplate, sequenceTemplate) avgDev = getLineForDev(avgDevelopmentScore) seqDev = getLineForDev(seqDev) # plt.plot([i for i in range(len(deviceTemplate))], deviceTemplate, color='blue') # plt.plot([i for i in range(len(sequenceTemplate))], sequenceTemplate, color='red') # plt.plot([i for i in range(len(avgDev))], avgDev, color='blue') # plt.plot([i for i in range(len(seqDev))], seqDev, color='red') # plt.show() avgSlope = linRegress.getSlopeForDifference( [i for i in range(len(avgDev))], avgDev) seqSlope = linRegress.getSlopeForDifference( [i for i in range(len(seqDev))], seqDev) return 1 if seqSlope <= avgSlope * THRESHOLD_PERCENT else 0
test_data_set_az, log_test_data_set_az[count][0]) test_data_set_gx = remake_test_data_set( test_data_set_gx, log_test_data_set_gx[count][0]) test_data_set_gy = remake_test_data_set( test_data_set_gy, log_test_data_set_gy[count][0]) test_data_set_gz = remake_test_data_set( test_data_set_gz, log_test_data_set_gz[count][0]) if 0.75 < log_test_data_set_az[ count - 50][0] and log_test_data_set_ay[count][0] < -0.05: print( "=============================================pick and drop and hand down===============================================" ) pick_dtw_gz_result = dtw.getDTW(train_data_set_gz, test_data_set_gz) drop_dtw_gz_result = dtw.getDTW(drop_train_data_set_gz, test_data_set_gz) hand_down_dtw_az_result = dtw.getDTW(hand_down_data_set_az, test_data_set_az) if operation_identification( pick_dtw_gz_result - drop_dtw_gz_result ) == "pick" or operation_identification( pick_dtw_gz_result - drop_dtw_gz_result) == "drop": test_data_set_ax = np.zeros_like(test_data_set_ax) test_data_set_ay = np.zeros_like(test_data_set_ay) test_data_set_az = np.zeros_like(test_data_set_az) test_data_set_gx = np.zeros_like(test_data_set_gx) test_data_set_gy = np.zeros_like(test_data_set_gy) test_data_set_gz = np.zeros_like(test_data_set_gz) if operation_identification(pick_dtw_gz_result -
# 加速度を取得 accel_x, accel_y, accel_z = get_accel_data_g() # 角加速度を取得 gyro_x, gyro_y, gyro_z = get_gyro_data_deg() # 枠内にデータを作成する test_data_set_ax = remake_test_data_set(test_data_set_ax, accel_x) test_data_set_ay = remake_test_data_set(test_data_set_ay, accel_y) test_data_set_az = remake_test_data_set(test_data_set_az, accel_z) test_data_set_gx = remake_test_data_set(test_data_set_gx, gyro_x) test_data_set_gy = remake_test_data_set(test_data_set_gy, gyro_y) # print (len(test_data_set)) # pickのDTWの値を取得する pick_dtw_ax_result = dtw.getDTW(train_data_set_ax, test_data_set_ax) pick_dtw_ay_result = dtw.getDTW(train_data_set_ay, test_data_set_ay) pick_dtw_az_result = dtw.getDTW(train_data_set_az, test_data_set_az) pick_dtw_gx_result = dtw.getDTW(train_data_set_gx, test_data_set_gx) pick_dtw_gy_result = dtw.getDTW(train_data_set_gy, test_data_set_gy) drop_dtw_ax_result = dtw.getDTW(drop_train_data_set_ax, test_data_set_ax) drop_dtw_ay_result = dtw.getDTW(drop_train_data_set_ay, test_data_set_ay) drop_dtw_az_result = dtw.getDTW(drop_train_data_set_az, test_data_set_az) drop_dtw_gx_result = dtw.getDTW(drop_train_data_set_gx, test_data_set_gx) drop_dtw_gy_result = dtw.getDTW(drop_train_data_set_gy, test_data_set_gy) print(pick_dtw_ax_result, pick_dtw_ay_result, pick_dtw_az_result, pick_dtw_gx_result, pick_dtw_gy_result) print(drop_dtw_ax_result, drop_dtw_ay_result, drop_dtw_az_result, drop_dtw_gx_result, drop_dtw_gy_result) print(drop_dtw_ax_result - pick_dtw_ax_result, drop_dtw_ay_result - pick_dtw_ay_result, drop_dtw_az_result - pick_dtw_az_result, drop_dtw_gx_result - pick_dtw_gx_result, drop_dtw_gy_result - pick_dtw_gy_result) if tt > 80 and operation_identification(drop_dtw_ax_result - pick_dtw_ax_result, drop_dtw_gx_result - pick_dtw_gx_result, drop_dtw_gy_result - pick_dtw_gy_result, accel_y, accel_z) == 'pick': count += 1
# 加速度を取得 accel_x, accel_y, accel_z = get_accel_data_g() # 角加速度を取得 gyro_x, gyro_y, gyro_z = get_gyro_data_deg() # 枠内にデータを作成する test_data_set_ax = remake_test_data_set(test_data_set_ax, accel_x) test_data_set_ay = remake_test_data_set(test_data_set_ay, accel_y) test_data_set_az = remake_test_data_set(test_data_set_az, accel_z) test_data_set_gx = remake_test_data_set(test_data_set_gx, gyro_x) test_data_set_gy = remake_test_data_set(test_data_set_gy, gyro_y) # print (len(test_data_set)) # pickのDTWの値を取得する pick_dtw_ax_result = dtw.getDTW(train_data_set_ax, test_data_set_ax) pick_dtw_ay_result = dtw.getDTW(train_data_set_ay, test_data_set_ay) pick_dtw_az_result = dtw.getDTW(train_data_set_az, test_data_set_az) pick_dtw_gx_result = dtw.getDTW(train_data_set_gx, test_data_set_gx) pick_dtw_gy_result = dtw.getDTW(train_data_set_gy, test_data_set_gy) pick_dtw_gx_result_1 = dtw.getDTW(train_data_set_gx_2, test_data_set_gx) pick_dtw_gy_result_1 = dtw.getDTW(train_data_set_gy_2, test_data_set_gy) pick_dtw_gx_result_2 = dtw.getDTW(train_data_set_gx_3, test_data_set_gx) pick_dtw_gy_result_2 = dtw.getDTW(train_data_set_gy_3, test_data_set_gy) pick_dtw_gx_result_3 = dtw.getDTW(train_data_set_gx_4, test_data_set_gx) pick_dtw_gy_result_3 = dtw.getDTW(train_data_set_gy_4, test_data_set_gy) pick_dtw_gx_result_4 = dtw.getDTW(train_data_set_gx_5, test_data_set_gx) pick_dtw_gy_result_4 = dtw.getDTW(train_data_set_gy_5, test_data_set_gy) pick_dtw_gx_list.extend([pick_dtw_gx_result, pick_dtw_gx_result_1, pick_dtw_gx_result_2, pick_dtw_gx_result_3, pick_dtw_gx_result_4]) pick_dtw_gy_list.extend([pick_dtw_gy_result, pick_dtw_gy_result_1, pick_dtw_gy_result_2, pick_dtw_gy_result_3, pick_dtw_gy_result_4])
def makePrediction(dTemplate, toTest, avgDev): disregard, testDev = dtw.getDTW(dTemplate, toTest) avgSlope = linRegress.getSlopeForDifference([i for i in range(len(avgDev))], avgDev) testSlope = linRegress.getSlopeForDifference([i for i in range(len(testDev))], testDev) return 1 if testSlope <= avgSlope*THRESHOLD_PERCENT else 0
train_data_set_az = pd.read_csv('pick_train_data_2/pick_accel_z.csv', usecols=[2]).values.reshape(-1, 1) train_data_set_gx = pd.read_csv('pick_train_data_2/pick_gyro_x.csv', usecols=[0]).values.reshape(-1, 1) train_data_set_gy = pd.read_csv('pick_train_data_2/pick_gyro_y.csv', usecols=[0]).values.reshape(-1, 1) drop_train_data_set_ax = pd.read_csv('drop_train_data/drop_accel_x.csv', usecols=[0]).values.reshape(-1, 1) drop_train_data_set_ay = pd.read_csv('drop_train_data/drop_accel_y.csv', usecols=[0]).values.reshape(-1, 1) drop_train_data_set_az = pd.read_csv('drop_train_data/drop_accel_z.csv', usecols=[0]).values.reshape(-1, 1) drop_train_data_set_gx = pd.read_csv('drop_train_data/drop_gyro_x.csv', usecols=[0]).values.reshape(-1, 1) drop_train_data_set_gy = pd.read_csv('drop_train_data/drop_gyro_y.csv', usecols=[0]).values.reshape(-1, 1) # gx_result = dtw.getDTW(train_data_set_gx, drop_train_data_set_gx) ax_result = dtw.getDTW(train_data_set_ax, drop_train_data_set_ax) ay_result = dtw.getDTW(train_data_set_ay, drop_train_data_set_ay) az_result = dtw.getDTW(train_data_set_az, drop_train_data_set_az) gx_result = dtw.getDTW(drop_train_data_set_gx, train_data_set_gx) gy_result = dtw.getDTW(train_data_set_gy, drop_train_data_set_gy) print(ax_result) print(ay_result) print(az_result) print(gx_result) print(gy_result) dtw.getDTWPath(train_data_set_gx, drop_train_data_set_gx)
log_test_data_set_gx = pd.read_csv('sencing_test_result/' + name_list[member_count] + '/log_' + log_num[log_count] + '.csv', usecols=[3]).values.reshape(-1, 1) log_test_data_set_gy = pd.read_csv('sencing_test_result/' + name_list[member_count] + '/log_' + log_num[log_count] + '.csv', usecols=[4]).values.reshape(-1, 1) log_test_data_set_gz = pd.read_csv('sencing_test_result/' + name_list[member_count] + '/log_' + log_num[log_count] + '.csv', usecols=[5]).values.reshape(-1, 1) hash = 0 while len(log_test_data_set_ax) > count: sec = time.time() # 枠内にデータを作成する test_data_set_ax = remake_test_data_set(test_data_set_ax, log_test_data_set_ax[count][0]) test_data_set_ay = remake_test_data_set(test_data_set_ay, log_test_data_set_ay[count][0]) test_data_set_az = remake_test_data_set(test_data_set_az, log_test_data_set_az[count][0]) test_data_set_gx = remake_test_data_set(test_data_set_gx, log_test_data_set_gx[count][0]) test_data_set_gy = remake_test_data_set(test_data_set_gy, log_test_data_set_gy[count][0]) test_data_set_gz = remake_test_data_set(test_data_set_gz, log_test_data_set_gz[count][0]) pick_dtw_gz_result = dtw.getDTW(train_data_set_gz, test_data_set_gz) drop_dtw_ax_result = dtw.getDTW(drop_train_data_set_ax, test_data_set_ax) drop_dtw_ay_result = dtw.getDTW(drop_train_data_set_ay, test_data_set_ay) drop_dtw_gz_result = dtw.getDTW(drop_train_data_set_gz, test_data_set_gz) flag = "test" if operation_identification(pick_dtw_gz_result - drop_dtw_gz_result) == "drop" and drop_dtw_ax_result < 14: flag = "drop" drop_count += 1 insert_log_data(name_list[member_count], log_num[log_count], log_test_data_set_ax[count][0], log_test_data_set_ay[count][0], log_test_data_set_az[count][0], log_test_data_set_gx[count][0], log_test_data_set_gy[count][0], log_test_data_set_gz[count][0], 0, 0, 0, 0, drop_dtw_ax_result, drop_dtw_gz_result, pick_dtw_gz_result - drop_dtw_gz_result, flag) test_data_set_ax = np.zeros_like(test_data_set_ax) test_data_set_ay = np.zeros_like(test_data_set_ay) test_data_set_az = np.zeros_like(test_data_set_az) test_data_set_gx = np.zeros_like(test_data_set_gx) test_data_set_gy = np.zeros_like(test_data_set_gy)
#2秒以上状態を維持する if elapsed_time > 2: # 200個のセンシングデータを作成する while sencing_count <= 200: #sencing_start_time = time.time() gyro_x, gyro_y, gyro_z = get_gyro_data_deg() #print(gyro_x) # pickのDTWの値を取得する test_data_set_gx = remake_test_data_set( test_data_set_gx, gyro_x) test_data_set_gy = remake_test_data_set( test_data_set_gy, gyro_y) pick_dtw_gx_result.append( dtw.getDTW(train_data_set_gx, test_data_set_gx)) pick_dtw_gy_result.append( dtw.getDTW(train_data_set_gy, test_data_set_gy)) print( '==============================================================' ) print(dtw.getDTW(train_data_set_gx, test_data_set_gx)) #print(gyro_y) print(dtw.getDTW(drop_train_data_set_gx, test_data_set_gx)) print( '===============================================================' ) # DropのDTW値を算出 drop_dtw_gx_result.append( dtw.getDTW(drop_train_data_set_gx, test_data_set_gx))