Saving large amounts of data generated in custom code component

I am creating a continuous rating study wherein a custom code component constantly saves the participant’s mouse position via the X and Y coordinates of their cursor. A timestamp is also recorded for each frame.

In each frame, the coordinates are appended to a list (there are three separate lists for X coordinates, Y coordinates and timestamps). Later, each list is added as a column to the final CSV containing the participant’s data. E.g.,

Begin Routine: timestamp = []
Each frame: timestamp.append(t)
End routine: thisExp.addData('timestamp', timestamp).

This all works well, however the final list of values is contained within a single cell of the CSV. CSVs only support so many characters in a single cell, so after that character limit is reached, the values begin to spill over to individual cells in the following row.

You can see in the following example that the bottom of the formula bar for the “timestamp” column in Excel prematurely finishes at the 28 seconds, and subsequent values fill the cells beneath.

I am wondering if there is a better way to save large amounts of data generated in the each frame argument. This issue arises when participants are responding to a 30s stimulus, and ideally I’d like to support stimuli up to at least 10 minutes. Is there a way to save the individual values in the array to separate rows in the CSV?

A temporary solution I’ve found is to round the values to fewer decimal places, but I would like to find one that is more robust. Another potential solution is to only save frames where the participant’s mouse moved, but unfortunately this won’t work for the current project as other researchers involved would like as much time information as possible.

Thank you very much in advance for any advice!

I also can’t take credit for the code for continuously recording the mouse. It came from this thread:

Hi @andersoc, as far as I can see, the character limit and spillover only concern Excel and not the CSV file itself. So if you are not intending on using Excel to analyze your data this should not matter. Have you tried reading the data into a different program?

2 Likes

You are right–thank you very much! My problem was due to my own lack of understanding. When I open the same CSV in R, the data display correctly. :slight_smile: