def writeErrorForEveryTrial(pid, datas, pathFordata): androidfile = pathFordata + 'PID_' + str( pid) + '_TwoDFittsData_External.csv' leapTimeStamp_list = loadLeapTimeStampData(pathFordata, pid) with open(androidfile) as f: f_csv = csv.reader(f) for i in range(0, 9): # skip the beginning next(f_csv) oldheaders = next(f_csv) # get the old headers # since first TRE and TRE are from Mackenzie,we need to move them behind headers = oldheaders # store the original header headers = headers[0:len(headers) - 2] # remove the 'firstTRE' and 'TRE' headers.extend([ 'leapStartTimestamp', 'leapFirstLiftUpTimeStamp', 'leapFinalLiftUpTimeStamp' ]) errorheaders = [ 'Error', 'SlipError', 'NarrowSlipError', 'ModerateSlipError', 'LargeSlipError', 'VeryLargeSlipError', 'MissError', 'NearMissError', 'NotSoNearMissError', 'OtherError', 'AccidentalTap', 'AccidentalHit' ] # the headers for the error data headers.extend(errorheaders) # append the error header to the headers i = 0 for row in f_csv: # restore the firstTRE and average TRE firstTRE.append(row[len(row) - 2]) TRE.append(row[len(row) - 1]) row = row[0:len(row) - 2] # omit the firstTRE and average TRE row.extend([ leapTimeStamp_list[i].leapStartTimeStamp, leapTimeStamp_list[i].leapFirstLiftUpTimeStamp, leapTimeStamp_list[i].leapFinalLiftUpTime ]) targetX = float(row[colNumAndroidTargetX]) targetY = float(row[colNumAndroidTargetY]) firstTouchDownX = float(row[colNumAndroidFirstTouchDownX]) firstTouchDownY = float(row[colNumAndroidFirstTouchDownY]) firstLiftUpX = float(row[colNumAndroidFirstLiftUpX]) firstLiftUpY = float(row[colNumAndroidFirstLiftUpY]) targetWidthInPixel = float(row[colNumAndroidWidthInPixel]) errorUtils = ErrorUtils(firstLiftUpX, firstLiftUpY, firstTouchDownX, firstTouchDownY, targetWidthInPixel, targetX, targetY) errorUtils.calculateErrors( ) # this function is used to calculate all kinds of errors,the results are the variables of ErrorUntils # restore the result in an array errordata = [ errorUtils.error, errorUtils.SlipError, errorUtils.NarrowSlipError, errorUtils.ModerateSlipError, errorUtils.LargeSlipError, errorUtils.VeryLargeSlipError, errorUtils.MissError, errorUtils.NearMissError, errorUtils.NotSoNearMissError, errorUtils.OtherError, errorUtils.AccidentalTap, errorUtils.AccidentalHit ] row.extend( errordata) # append the error data after the android data datas.append(row) # restore the data in a two-dimensional array return datas, headers