Skip to content

Commit

Permalink
prolific-issue-#105 (#106)
Browse files Browse the repository at this point in the history
- to address issue #105
- move nivturk plugins to experiment.html
- delete nivturk-plugins.js
  • Loading branch information
szorowi1 committed Dec 6, 2022
1 parent b959fd2 commit e9ce8bc
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ data/**
metadata/**
incomplete/**
reject/**
.placeholder
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from app import consent, alert, experiment, complete, error
from .io import write_metadata
from .utils import gen_code
__version__ = '1.2'
__version__ = '1.2.1'

## Define root directory.
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
Expand Down
Empty file added app/static/js/.placeholder
Empty file.
87 changes: 0 additions & 87 deletions app/static/js/nivturk-plugins.js

This file was deleted.

94 changes: 91 additions & 3 deletions app/templates/experiment.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<script src="../static/lib/jquery-3.3.1/jquery.min.js"></script>
<script src="../static/lib/jspsych-7.2.1/jspsych.js"></script>

<!-- Load NivTurk plug-ins -->
<script src="../static/js/nivturk-plugins.js" type="text/javascript"></script>

<!-- Load jsPsych plug-ins -->
<script src="../static/lib/jspsych-7.2.1/plugins/plugin-survey-likert.js"></script>

Expand Down Expand Up @@ -77,5 +74,96 @@
// Execute timeline.
jsPsych.run(timeline);

</script>
<script>

// Pass message from jsPsych to NivTurk
function pass_message(msg) {

$.ajax({
url: "/experiment",
method: 'POST',
data: JSON.stringify(msg),
contentType: "application/json; charset=utf-8",
}).done(function(data, textStatus, jqXHR) {
// do nothing on success
}).fail(function(error) {
console.log(error);
});

}

// Save an incomplete dataset.
function incomplete_save() {

$.ajax({
url: "/incomplete_save",
method: 'POST',
data: JSON.stringify(jsPsych.data.get().json()),
contentType: "application/json; charset=utf-8",
}).done(function(data, textStatus, jqXHR) {
// do nothing
}).fail(function(error) {
// do nothing
});

}

// Successful completion of experiment: redirect with completion code.
function redirect_success(workerId, assignmentId, hitId, code_success) {

// Concatenate metadata into complete URL (returned on success).
var url = "https://app.prolific.co/submissions/complete?cc=" + code_success;

$.ajax({
url: "/redirect_success",
method: 'POST',
data: JSON.stringify(jsPsych.data.get().json()),
contentType: "application/json; charset=utf-8",
}).done(function(data, textStatus, jqXHR) {
window.location.replace(url);
}).fail(function(error) {
window.location.replace(url);
});

}

// Unsuccessful completion of experiment: redirect with decoy code.
function redirect_reject(workerId, assignmentId, hitId, code_reject) {

// Concatenate metadata into complete URL (returned on reject).
var url = "https://app.prolific.co/submissions/complete?cc=" + code_reject;

$.ajax({
url: "/redirect_reject",
method: 'POST',
data: JSON.stringify(jsPsych.data.get().json()),
contentType: "application/json; charset=utf-8",
}).done(function(data, textStatus, jqXHR) {
window.location.replace(url);
}).fail(function(error) {
window.location.replace(url);
});
}

// Unsuccessful completion of experiment: redirect to error page.
function redirect_error(error) {

// error is the error number to redirect to.
var url = "/error/" + error;

$.ajax({
url: "/redirect_error",
method: 'POST',
data: JSON.stringify(jsPsych.data.get().json()),
contentType: "application/json; charset=utf-8",
}).done(function(data, textStatus, jqXHR) {
window.location.replace(url);
}).fail(function(error) {
window.location.replace(url);
});

}

</script>
</html>

0 comments on commit e9ce8bc

Please sign in to comment.