-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Using DataPipe with PsychoPy | ||
|
||
*This guide assumes that you are already familiar with PsychoPy and that you have already followed the [getting started guide](https://pipe.jspsych.org/getting-started) on DataPipe to setup an experiment.* | ||
|
||
### Use the scripts editor to call DataPipe | ||
|
||
To call DataPipe in an online PsychoPy experiment we can use `fetch()` inside a code component. This call needs to happen after the last trial that collects meaningful data. | ||
One simple place to put it is on any debrief/final screen, inside the Begin Routine event. | ||
|
||
We need to do three things in this script: | ||
|
||
First, generate a random filename: | ||
|
||
```js | ||
function randomID(){ | ||
const length = 10; | ||
let result = ""; | ||
const chars = "0123456789abcdefghjklmnopqrstuvwxyz"; | ||
for (let i = 0; i < length; i++) { | ||
result += chars[Math.floor(Math.random() * chars.length)]; | ||
} | ||
return result; | ||
} | ||
|
||
const filename = `${randomID()}-data.json` | ||
``` | ||
|
||
Second, extract the JSON data from the internal storage of PsychoPy | ||
|
||
```js | ||
const dataJSON = JSON.stringify(psychoJS.experiment._trialsData); | ||
``` | ||
|
||
Third, make a `fetch` request to DataPipe | ||
|
||
```js | ||
fetch("https://pipe.jspsych.org/api/data/", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Accept: "*/*", | ||
}, | ||
body: JSON.stringify({ | ||
experimentID: "ABCDEF123456", | ||
filename: filename, | ||
data: dataJSON, | ||
}), | ||
}); | ||
``` |