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

Unexpected behaviour when saving user data. #57

Closed
JuneOh710 opened this issue Mar 14, 2022 · 4 comments
Closed

Unexpected behaviour when saving user data. #57

JuneOh710 opened this issue Mar 14, 2022 · 4 comments

Comments

@JuneOh710
Copy link
Contributor

I'm having some trouble saving the experiment data where (1) the data would fail to save and (2) the program will not automatically advance to the next experiment in the container. This occurs for both JsPsych and custom experiments. Here is the code that I'm using to save the data:

For JsPsych:

const settings = {
    fullscreen: true,
    on_finish: function (data) {
        // Serialize the data
        var promise = new Promise(function (resolve, reject) {
            var data = jsPsych.data.get().json();
            resolve(data);
        })

        promise.then(function (data) {
            sendResults(data);
        })
    }

}

const jsPsych = initJsPsych(settings);
async function sendResults(results) {
    function handleErrors(response) {
        if (!response.ok) {
            throw Error(response.statusText);
        }
        return response;
    }

    fetch("/save", {
        method: "POST",
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ data: results })
    })
        .then(handleErrors)
        .then(response => console.log("Request complete! response: ", response))
        .catch(error =>
            jsPsych.data.get().localSave('csv', 'cognitive_estimation_task_result.csv')
        );
}

For custom:

async function sendResults(results) {
    function handleErrors(response) {
          if (!response.ok) {
              throw Error(response.statusText);
          }
          return response;
      }

      fetch("/save", {
          method: "POST",
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ data: results })
      })
          .then(handleErrors)
          .then(response => console.log("Request complete! response: ", response))
          .catch(error => console.log("We got an error: ", error));
}
@vsoch
Copy link
Member

vsoch commented Mar 14, 2022

What is the error in the console?

@JuneOh710
Copy link
Contributor Author

JuneOh710 commented Mar 14, 2022

I checked the console and there isn't an error message.
We would see the success logs when we run an existing experiment but we don't see any messages when we run one of our new experiments.

@vsoch
Copy link
Member

vsoch commented Mar 14, 2022

I need something to be able to help you - either the container pushed to a public registry with instructions to pull and run (and show me how to reproduce) or to see the error verbatim.

@JuneOh710
Copy link
Contributor Author

I will get back to you with one of those by tomorrow (I need to get access to the containers).

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

2 participants