Dear all,
I’m planing a study which will probably include hundreds of participants, so I’d need to program an output file (or output files) very carefully thought and with the exact data I need organized in rows and columns.
In order to do that, I inserted a code component in the builder which I named “Data_collector”. In the “begin routine” tab:
output = [["Response", "Time", "Position"]]
in the “each frame tab”:
keys = event.getKeys(timeStamped=trialClock)
for key in keys:
if key[0] == 'right':
key_out = "right"
Press_pos = str(copy.deepcopy(Subject_position))
elif key[0] == 'left':
key_out = "left"
Press_pos = str(copy.deepcopy(Subject_position))
elif key[0] == 'up':
key_out = "up"
Press_pos = str(copy.deepcopy(Subject_position))
elif key[0] =='down':
key_out = "down"
elif key[0] == 'b' and Subject_position != [-475, -225] and Subject_position != [475, 225]:
key_out = "b"
Press_pos = str(copy.deepcopy(Subject_position))
elif key[0] == 'r' and Subject_position == [475, 225]:
key_out = "r"
Press_pos = str(copy.deepcopy(Subject_position))
else:
key_out = "wrong key"
Press_pos = str(copy.deepcopy(Subject_position))
output.append([key_out, key[1], Press_pos])
and in the “end routine”:
np.savetxt(filename, output, fmt="%s", delimiter="\t")
This is still a trial with three of the variables I’ll need to collect and this worked to save files which I can import to excel. However, after inserting these commands, the experiment is running much slower, sometimes some seems to occur some lagging and frame drops (not sure) and, for sure, not all key presses are being recorded. I’m guessing this might have to do with “for loop” I inserted, which might be causing some frames dropping, but also not sure. I’m new in programming…
Would you know whether I’m going to a good direction in order to create my output files? How could I do this without the “slowness / lagging / dropping” issue? Is there another, maybe better way to achieve what I need?
Thanks in advance.
Best,
Felipe
Obs - this is related to the same experiment about which I had already created a topic before - “Creating barriers in a grid” -, regarding a problem which was very efficiently and nicely solved by @jderrfuss (Thanks)