Saving multi-value data entries (e.g. list of coords)

URL of experiment:
Run: https://pavlovia.org/run/rockNroll/test_saving_csv/html/
Code: Michele Svanera / test_saving_csv · GitLab

Description of the problem:
Dear all,
I’m trying to code an experiment in which participants draw lines with the mouse and for every image (i.e., trail) save a csv file with drawing coordinates, like this:

example

My problem is the saving phase: with python is very simple, but I’m struggling to understand how to do in JS. Using the default csv creates problem, since I have to record a lot of data (mouse movements).
Is it possible? Any suggestion?

Thanks in advance!
Best,
Michele

Yes, sadly there’s always going to be a problem with saving complex data structures (with variable dimensions) in tabulated data formats (e.g. csv).

It should be possible to set a cell to have a multidimensional value, like a list of 2d coordinates:
experiment.addData(linepath’, listOfXYvals)`
It’s just that these will be encoded as text so that they can be written in the csv file and then, when you read the file in, you’ll need to convert that text back into a list of floats, or whatever it was.

For the better ultimate solution:

  • @apitiot has already implemented the option to save the data as a mongoDB database and it might be that this stores values with more flexibility (but right now it gets converted to a csv file for download, which then has the same problem)
  • we could potentially save data as a json file with a structure instead. That would not be easily read by spreadsheets of course, but would be nicer for people like you that presumably aren’t using a spreadsheet for analysis anyway

@jon, thanks for your reply!

You are right, I don’t need a csv: any format is fine (txt file, json, csv). It’s pretty easy to read any of them and extract the data needed. Of course, if we are able to create a separate file per trail with a regular structure and header is much easier for next analyses.
What do you suggest me?

Thanks!

Unlike in Python we can’t just write to arbitrary files using JS - that would mean the browser being able to write arbitrary files to the server - so we have to think of a more general solution (1-file-per trial doesn’t sound like a general solution)