How to append a row to an existing csv file in resources - pavlovia

Description of the problem: hello. I have a csv file in the resources folder in gitlab where I keep the number of participants that completed the experiment. I want to update that csv file in a way that gives me the new number of participants each time a participant completes the experiment. Either of the following would work for me if you have any suggestions how to do it:

1- Updating the content of the csv file: I can start the value from (say) 0 at the very beginning of the experiment (like, before any participant completes the task). After a participant completes the task, I can update the content with like 0+1 = 1, then for the second participant I can do 1+1 = 2. This would be a solution for me to count the number of participants (yet, I couldn’t figure out how to make it work in js).

2- Appending a new row of the existing csv file and counting the number of rows: I can start the first line with (say) 9999 for the 0th participant. I can append a new line to the csv file every time a participant complete the task. The total number of rows in the csv file would thus, give me the total number of participants (yet, I couldn’t figure out how to make this one work in js either).

Once I get the number of participants, I will use it to index and draw data from another csv file in the resources folder (for now, I am able to do it with some dummy numbers).

I know the solution but I cant implement in js :confused: Does anybody have any idea about how to either update the content of an existing csv file or append a new row in pavlovia/js?

any help would be much appreciated! thanks in advance, tutku

I don’t think this is possible in PsychoPy online, which is why I wrote an external tool for people to use. https://moryscarter.com/vespr/pavlovia.php

However, I use Qualtrics for allocation to conditions for my own experiments.

hello wakecarter,

thank you for your reply. I think the link you inserted aims to assign random ID numbers to the participants. But what i need instead is the number of participants to be updated every time the experiment is completed so that I can index another csv file and draw the nth data and use it in the experiment. is it even possible to do that with the link that you sent?

thanks, tutku

or maybe it can count the number of files in ‘data’ folder where the participant data is saved as csv files? i think that would work for me too.

My app assigns consecutive numbers based on the number of times the link is used. I don’t know a way of counting the data files online.

oh okay, sounds like that would work for me as well :slight_smile: where does it save the ID number of the last participant that completed the experiment?

In a MySQL database. Why don’t you give it a go and see how it works. If you click the link multiple times with the same experiment then the participant number will go up. However, it can’t be reset remotely, so you might want to test with a fake experiment name.

thank you wakecarter. I gave it a shot with a dummy experiment, it works quite well and I think I will use the link that you sent.
But i couldnt get how to reach the number of the last participant (although you said its being saved in a mysql database), probably because im not very familiar with these kinds of stuff. like, does it save the participant ids to an external file that i can reach with my psychojs code?

thank you so much again and sorry for bothering with too many questions :stuck_out_tongue:
tutku

It sends the current participant number to your experiment in the URL which you can access in your code using expInfo[‘participant’]

thank you so much :slight_smile: works pretty well :slight_smile:

Unfortunately it can’t cope with participants who fail to complete. To do that I’d need to rewrite the tool such that participant numbers could be validated by returning to the tool at the end of the experiment and then participant numbers that don’t get validated within a few hours get recycled…

isnt it possible to assign like 9999 at first to a participant until he/she completes the experiment and at the end of the experiment, replace 9999 with the real incremented ID number? I cant say that im really familiar with javascript coding style - what it is capable and what it is not capable of - but if its possible to do such a thing, maybe that would be a solution.

but still, this is just enough to solve my problem as it is for now. I’ll have to take care of participants who do not complete the task myself which is fine, because they will be incrementing “n” unpurposely and thereby change the order of the data that i want to retrieve from another external csv file.

At the moment the number is assigned by counting rows. The number has to be assigned at the start so that it gets used in the experiment, and also needs to be able to cope with multiple participants overlapping (one starts before the previous one finishes).