Hi everyone,
I am trying to set up a new csv file in the builder view using the code component. Ideally, I would like to have seperate columns for the following: ID, Age, Sex, Block, Condition, TrialNum, Accuracy and RT.
I have the following code in the ‘begin experiment’ tab:
trials_1 = psychoJS.experiment.addData
trials_2 = psychoJS.experiment.addData
trials_3 = psychoJS.experiment.addData
trials_4 = psychoJS.experiment.addData
if trials_1.thisN == 0:
ID = []
Age = []
Sex = []
Block = []
TrialNum = []
Condition = []
Accuracy = []
RT = []
if trials_2.thisN == 0 :
ID = []
Age = []
Sex = []
Block = []
TrialNum = []
Condition = []
Accuracy = []
RT = []
if trials_3.thisN == 0:
ID = []
Age = []
Sex = []
Block = []
TrialNum = []
Condition = []
Accuracy = []
RT = []
if trials_4.thisN == 0:
ID = []
Age = []
Sex = []
Block = []
TrialNum = []
Condition = []
Accuracy = []
RT = []
And the following code in the ‘end experiment’ tab:
file_name = ‘ToneDiscrim’ + str(expInfo[‘participant’]) + str(expInfo[‘date’])
setting up coloumn names from data
ID.append(expInfo(‘participant’))
Age.append(‘age_response.keys’)
Sex.append(‘sex_resp.keys’)
Block.append(1)
TrialNum.append([‘trials_1’, ‘trials_2’, ‘trials_3’, ‘trials_4’])
Condition.append(“same_600”, “different_1”, “same_610”, “different_2”, “different1_B2”, “same600_B2”, “different2_B2”, “same610_B2”)
Accuracy.append([‘key_resp_1.corr’, ‘key_resp_3.corr’, ‘key_resp_2.corr’, ‘key_resp_4.corr’, ‘key_resp_7.corr’, ‘key_resp_8.corr’, ‘key_resp_5.corr’, ‘key_resp_6.corr’])
RT.append([‘key_resp_1.rt’, ‘key_resp_2.rt’, ‘key_resp_3.rt’, ‘key_resp_4.rt’, ‘key_resp_5.rt’, ‘key_resp_6.rt’, ‘key_resp_7.rt’, ‘key_resp_8.rt’])
col_names = (‘ID, Age, Sex, Block, TrialNum, Condition, Accuracy, RT’)
writting the data to new csv file
data_file = []
data_file = open(file_name + ‘.csv’,‘w’)
data_file.writerows(col_names)
The experiment runs fine and upon the last conditions I get an error message that says: unable to reduce empty arrays. I’m not sure what has gone wrong?