Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use spatial-span to download response data online #113

Open
OscarKjell opened this issue Aug 7, 2018 · 7 comments
Open

Use spatial-span to download response data online #113

OscarKjell opened this issue Aug 7, 2018 · 7 comments

Comments

@OscarKjell
Copy link

Version of Experiment Factory:

I want to use the spaital-span task online.
https://expfactory.github.io/experiments/e/spatial-span/

Expected behavior

I want the data to be downloaded to my online server using php-patch NOT locally to the user's computer as a file. That is, how do I change the saving function in the index file to not save a file locally but to an online server.

Actual behavior

The data is downloaded locally to the user's computer

Steps to reproduce behavior

I have an online experiment with several different tasks and then I use a php-patch to download the data responses to my online server using. I use these two different scripts that work for version 5 and version 6 of jspsych:

// Patch to save Participant data to website
function saveData(filename, filedata){
$.ajax({
type:'post',
cache: false,
url: 'save_data.php', // this is the path to the PHP script in the website folder
data: {filename: filename, filedata: filedata}
// complete: callback // https://groups.google.com/forum/#!searchin/jspsych/data$20not$20written$20/jspsych/JPocDlXtks0/s66dgjbsFQAJ
});
}

/* start the experiment */
jsPsych.init({
spatial_span_experiment,
display_element: "getDisplayElement",
fullscreen: true,
on_finish: function() {
//jsPsych.data.displayData();
},
});

OR THIS PATCH FOR VERSION
// Patch to save Participant data to website version 6
function saveData(name, data){
var xhr = new XMLHttpRequest();
xhr.open('POST', 'write_data.php'); // 'write_data.php' is the path to the php file described above.
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({filename: name, filedata: data}));
}

//start the experiment
jsPsych.init({
timeline: timeline,
on_interaction_data_update: function(data) {
console.log(JSON.stringify(data))
},
// on_finish: function(){ jsPsych.data.displayData();},
show_progress_bar: true,
});

@earcanal
Copy link
Contributor

earcanal commented Aug 7, 2018

The recommended approach for saving data server-side is to build your tasks into a Docker container. There's a bit of a learning curve if you haven't used Docker before, but once you're over that it's relatively quick to combine tasks into an online study.

@vsoch
Copy link
Member

vsoch commented Aug 7, 2018

hey @KlokGorp ! Yes, +1 to what @earcanal said, if you deploy your experiment(s) via a Docker container you will generate a reproducible thing so others can replicate them exactly, and from the Docker container you can run any database that you wish (postgres, mysql, sqlite, and filesystem are your bread and butter).

We did have one user that used the old version of expfactory to run a php+mysql+concerto setup, you can see the files here --> https://github.com/expfactory/expfactory-python/tree/master/server/mysql if that might be helpful, and if you have issues you should open them there. I'd be glad to help here, and I'm less help with the other version as I think the container-based reproducible way is the way to go :) Let me know if you have any questions!

@OscarKjell
Copy link
Author

Thank you ever so much for your help @vsoch & @earcanal!!!
I've had a look at the documentation at Experiment Factory; I've set up a Docker with https using Digital Ocean :) But to be honest I'm unsure if I'm on the right track. I'm certainly not an expert, so I'm not sure from the documentation why I am doing all these things :) whilst wondering if there might be a much easier way...

That is, I have already constructed a long jspsych study comprising survey questions, presentation of videos and music as well as behavioural tasks etc. Using this jspsych study I collect the data online using my own website/server, in which according to jspsych the data for each participant is saved as a json file to my online server.
Now I would like to in an easy way just add the spatial-span task from Experiment Factory in the same way. I could ask participants to add an ID number to the spatial-span task and then in the end of it link to my already constructed jspsych study. However, when I add the spatial-span task to my server and run it the response data is saved as an automatically downloaded file to my machine and not to my online server. So how do I get the response data to be saved to my online server where it is run from?

Thanks a lot for your patience,

@vsoch
Copy link
Member

vsoch commented Aug 8, 2018

I think you would want to do it the other way around - to package your experiment into one (or more than one) experiment factory experiment, and then build a container with all of them. You could equally just run the expfactory container with the spatial span task and then save to another database and combine based on a unique id. What you can't do is arbitrarily shove the two together, especially in terms of databases - I don't know what format / how (even in the file structure) your custom experiment is saving in, but it's unlikely to use the same table structure as expfactory.

So! If you want help converting your experiments to expfactory (likely fairly easy) I'm happy to do this! If you want to keep them as is and just run the experiment isolated, that works too.

@OscarKjell
Copy link
Author

Thank you @vsoch for you help.
I have several rather big problems.

  1. I want participants to get straight in to the experiment, not having to select in the Experiment Factory menu; and I'm not sure how to do this? (That is, I do not want participants to be able to select from different experiment, but when pressing my link they should get straight in to my experiment that holds the consent form etc.)

  2. When I've completed the tower-of-london test experiment I can see that the data file has saved in to the "container"(?); but I do not know how to get hold of these files; that is where I can find the files saved to my computer?

  3. I reckon when these points are solved I can get on with trying to make my current study compatible with the Experiment Factory... but where should I start reading about this?

  4. Also, I can upload and run the spatial-span experiment on my own server; and this saves a csv/json file to my computer. But how do I make it so that this file is saved to my webserver instead of the computer running the experiment?

(In terms of: "What you can't do is arbitrarily shove the two together, especially in terms of databases - I don't know what format / how (even in the file structure) your custom experiment is saving in, but it's unlikely to use the same table structure as expfactory"
As I'm thinking participant could give their ID number when completing the sptial-span task and then give their ID when completing my jspsych experiment; then these separate data files can be combined according according to the ID.)

Thanks a lot for your help and patience!

@earcanal
Copy link
Contributor

earcanal commented Aug 9, 2018

  1. You can specify the task order for you participants using --headless and --experiments (see Start a Headless Experiment Container. Regarding your later question about participant numbers, I think you'll want to start using tokens. These are unique IDs that give participants access to the study (once per token). All participant data (flat files or databases) is identified with a token, so you can easily use aggregate the data. Here's an example R script which randomises users to groups and maps a participant number to a token. I use this file as my participant "master file", for issuing tokens, keeping notes about completion, anything weird that happened with a participant that might mean they need to be excluded etc.
  2. Have a look at those -v arguments. These map folders from your container back to your host. They're like (Unix) mounts.
  3. I think you're reading the right things. Keep asking questions when you're stuck as it probably indicates the docs need a bit more work.
  4. This is identical to what you've been doing locally. You just need as server with Docker. I've been using Digital Ocean as it's quick and cheap to spin up and tear down virtual machines for the duration of a study. However, if you have a real/virtual host then is should just be a case of installing the latest version of Docker. FYI, Ubuntu 16.04.4 LTS and Docker version 18.03.1-ce, build 9ee9f40 work for me.

@vsoch
Copy link
Member

vsoch commented Aug 9, 2018

Thanks @earcanal this is so good! A few additional notes:

  • the v arguments mean "volumes" and it means that data in the container is mapped to your host so that it persists on the host. Importantly, if you don't map volumes, the data might be generated in the container, but then you would lose it when you stop the container.
  • so much +3 for the third point!! We are here to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants