-
Notifications
You must be signed in to change notification settings - Fork 80
Maze plugin #176
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
Open
LoicGrobol
wants to merge
41
commits into
jspsych:main
Choose a base branch
from
LoicGrobol:maze
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Maze plugin #176
Changes from 20 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
788dcd3
initial plugin skeleton
LoicGrobol 6e679a5
This is now a light spr plugin
LoicGrobol fe77c2d
we have maze, captain
LoicGrobol 119da04
fix alignment, add waiting time
LoicGrobol b23313f
bump readme
LoicGrobol 7d72fa7
fix test
LoicGrobol c0c6c28
add question
LoicGrobol 8be19bd
the tests! they run!
LoicGrobol 5cb4ae2
make canvas style completely configurable
LoicGrobol 9b7ded0
log question rt
LoicGrobol 10ae309
add option to halt on error
LoicGrobol 3128056
split instruction display and answer loggin logics
LoicGrobol a45de9b
fix first word, add spaghetti code
LoicGrobol 99bec06
fix step_display
LoicGrobol aeb4adc
typing
LoicGrobol 45d6115
consolidate the font style in a single parameter
LoicGrobol 39f96ba
start documenting
LoicGrobol cdb8203
More doc
LoicGrobol 28a1bd8
improve doc types
LoicGrobol 8bb1592
typo
LoicGrobol 6247000
typo
LoicGrobol baccad5
stop logging word_number
LoicGrobol dde0c18
fix types in doc
LoicGrobol 56c6eaf
doc typing
LoicGrobol fc8381e
refactor (more typescript-y) to prepare moving from canvas to DOM
LoicGrobol ebc47e2
restore font align
LoicGrobol baa1aeb
fix rt for the first word
LoicGrobol 14e3554
add test for waiting time
LoicGrobol d463ea1
add inter-word and before-question interval
LoicGrobol 09a23ab
start working on dom port
LoicGrobol 69e5424
pure dom display
LoicGrobol 34e49ce
split off style and remove obsolete params
LoicGrobol 168c4e3
cleanup
LoicGrobol 5d3753c
move all style to example
LoicGrobol 8a17207
move the questions to html
LoicGrobol a49d204
remove refs to end_interval
LoicGrobol a36af8d
Merge pull request #1 from LoicGrobol/maze-dom
LoicGrobol ea8ea3a
fix question eval in the example
LoicGrobol fe50cdf
fix question data
LoicGrobol e2aaeb1
use compareKeys to compare keys
LoicGrobol a44d89b
remove obsolete param
LoicGrobol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,35 @@ | ||
# Maze | ||
|
||
## Overview | ||
|
||
A jsPsych plugin for running Maze experiments | ||
|
||
## Loading | ||
|
||
### In browser | ||
|
||
```js | ||
<script src="https://unpkg.com/@jspsych-contrib/[email protected]"></script> | ||
``` | ||
|
||
### Via NPM | ||
|
||
``` | ||
npm install @jspsych-contrib/plugin-maze | ||
``` | ||
|
||
```js | ||
import jsPsychMaze from '@jspsych-contrib/plugin-maze'; | ||
``` | ||
|
||
## Compatibility | ||
|
||
jsPsych 8.0.0 | ||
|
||
## Documentation | ||
|
||
See [documentation](https://github.com/jspsych/jspsych-contrib/blob/main/packages/plugin-maze/docs/jspsych-maze.md) | ||
|
||
## Author / Citation | ||
|
||
[Morgan Grobol](https://lgrobol.bzh) |
This file contains hidden or 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,90 @@ | ||
Maze | ||
==== | ||
|
||
A jsPsych plugin for running Maze (Forster et al., 2009) experiments, a version of self-paced | ||
reading that asks to chose between the correct next word and a distractor. | ||
|
||
## Parameters | ||
|
||
In addition to the [parameters available in all plugins](https://www.jspsych.org/latest/overview/plugins/#parameters-available-in-all-plugins), this plugin accepts the following parameters. Parameters with a default value of undefined must be specified. Other parameters can be left unspecified if the default value is acceptable. | ||
|
||
| Parameter | Type | Default Value | Description | | ||
|-------------------|---------------------------------------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------| | ||
| `sentence` | `Array<[string, string]>` | `undefined` | The sentence to use in the Maze, as `[word, foil]` pairs. | | ||
| `question` | `{text: string, correct: str, wrong: str}?` | `null` | An optional question to ask at the end of the mazz to make sure the subject has read the sentence. | | ||
| `canvas_style` | `string` | `"border: 0px solid black;"` | Extra style to inject in the canvas element. | | ||
| `canvas_colour` | `string` | `"white"` | The canvas' background colour. | | ||
| `canvas_size` | `[number, number]` | `[1280, 960]` | The dimensions of the canvas. | | ||
| `font_colour` | `str` | `"black"` | The font colour for the text. | | ||
| `font_style` | `str` | `"normal 24px monospace"` | The font style for the text. | | ||
| `halt_on_error` | `bool` | `false` | If true, any error ends the trial and sends the subject directly to the question (if any), then exit. | | ||
| `keys` | `{left: string, right: string}` | `{left: "f", right: "j"}` | The choice/navigation keys. | | ||
| `position_left` | `{x: number?, y: number?}` | `{x: null, y: null}` | The position of the left word. A null `x` is set to 1/3 of the canvas' width and null `y` is set to half of the canvas' height. | | ||
| `position_right` | `{x: number?, y: number?}` | `{x: null, y: null}` | The position of the right word. A null `x` is set to 2/3 of the canvas' width and null `y` is set to half of the canvas' height. | | ||
| `tranlate_origin` | `bool` | `true` | If true, the coordinates are transposed to have `(0, 0)` be the center of the canvas. | | ||
| `waiting_time` | `number` | `0` | The minimum time (in ms) before the subject is allowed to chose a word. | | ||
|
||
## Data Generated | ||
|
||
In addition to the [default data collected by all plugins](https://www.jspsych.org/latest/overview/plugins/#data-collected-by-all-plugins), this plugin collects the following data for each trial. | ||
|
||
| Name | Type | Value | | ||
|------------|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------| | ||
| `sentence` | `string` | The sentence used in the trial (joined with spaces) | | ||
| `events` | `Array<{correct: bool, foil: string, rt: number, word: string, word_number: number}>` | The parameters, choice and interaction time for each word of the sentence | | ||
| `question` | `{question: {text: string, correct: str, wrong: str}, correct: bool, rt: number}>` | The parameters, choice and interaction time for the final question (if any) | | ||
|
||
## Install | ||
|
||
Using the CDN-hosted JavaScript file: | ||
|
||
```js | ||
<script src="https://unpkg.com/@jspsych-contrib/plugin-maze"></script> | ||
``` | ||
|
||
Using the JavaScript file downloaded from a GitHub release dist archive: | ||
|
||
```js | ||
<script src="jspsych/plugin-maze.js"></script> | ||
``` | ||
|
||
Using NPM: | ||
|
||
```bash | ||
npm install @jspsych-contrib/plugin-maze | ||
``` | ||
|
||
```js | ||
import Maze from '@jspsych-contrib/plugin-maze'; | ||
``` | ||
|
||
## Examples | ||
|
||
```javascript | ||
|
||
const trial = { | ||
type: jsPsychMaze, | ||
sentence: [ | ||
["After", "x-x-x"], | ||
["a", "so"], | ||
["bit", "pot"], | ||
["of", "if"], | ||
["success", "singing"], | ||
["the", "ate"], | ||
["stocks", "winter"], | ||
["took", "walk"], | ||
["a", "we"], | ||
["dive", "toad"], | ||
], | ||
question: { | ||
text: "Did the stocks take a dive?", | ||
correct: "yes", | ||
wrong: "no", | ||
}, | ||
waiting_time: 200, | ||
} | ||
``` | ||
|
||
## Bibliography | ||
|
||
- Forster, Kenneth I., Christine Guerrera, and Lisa Elliot. 2009. ‘The Maze Task: Measuring Forced Incremental Sentence Processing Time’. Behavior Research Methods 41 (1): 163–71. <https://doi.org/10.3758/BRM.41.1.163>. |
This file contains hidden or 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,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="https://unpkg.com/jspsych"></script> | ||
<!-- The plugin is loaded here --> | ||
<script src="https://unpkg.com/@jspsych/plugin-maze"></script> | ||
<script src="../dist/index.browser.js"></script> | ||
|
||
<!-- Ugly trick to keep the data separate while not having to think of how to fetch it --> | ||
<script src="stimuli.js"></script> | ||
|
||
<link rel="stylesheet" href="https://unpkg.com/jspsych/css/jspsych.css" /> | ||
</head> | ||
|
||
<body></body> | ||
<script> | ||
const jsPsych = initJsPsych(); | ||
|
||
const procedure = { | ||
timeline : [ | ||
{ | ||
type: jsPsychMaze, | ||
sentence: jsPsych.timelineVariable('sentence'), | ||
question: jsPsych.timelineVariable('question'), | ||
waiting_time: 200, | ||
on_finish: () => { | ||
jsPsych.data.displayData('json'); | ||
}, | ||
} | ||
], | ||
timeline_variables: data, | ||
}; | ||
|
||
jsPsych.run(procedure) | ||
</script> | ||
</html> |
This file contains hidden or 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,39 @@ | ||
const data = [ | ||
{ | ||
sentence: [ | ||
["After", "x-x-x"], | ||
["a", "so"], | ||
["bit", "pot"], | ||
["of", "if"], | ||
["success", "singing"], | ||
["the", "ate"], | ||
["stocks", "winter"], | ||
["took", "walk"], | ||
["a", "we"], | ||
["dive", "toad"], | ||
], | ||
question: { | ||
text: "Did the stocks take a dive?", | ||
correct: "yes", | ||
wrong: "no", | ||
}, | ||
}, | ||
{ | ||
sentence: [ | ||
["The", "x-x-x"], | ||
["fashion", "realize"], | ||
["model", "shirt"], | ||
["was", "see"], | ||
["very", "into"], | ||
["self-conscious", "professionally"], | ||
["of", "do"], | ||
["her", "why"], | ||
["appearance", "sandwiches"], | ||
], | ||
question: { | ||
text: "Who was self-conscious?", | ||
correct: "The model", | ||
wrong: "The designer", | ||
}, | ||
}, | ||
]; |
This file contains hidden or 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 @@ | ||
module.exports = require("@jspsych/config/jest").makePackageConfig(__dirname); |
This file contains hidden or 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,50 @@ | ||
{ | ||
"name": "@jspsych-contrib/plugin-maze", | ||
"version": "0.0.1", | ||
"description": "A jsPsych plugin for running Maze experiments", | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"exports": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"typings": "dist/index.d.ts", | ||
"unpkg": "dist/index.browser.min.js", | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"source": "src/index.ts", | ||
"scripts": { | ||
"test": "jest", | ||
"test:watch": "npm test -- --watch", | ||
"tsc": "tsc", | ||
"build": "rollup --config", | ||
"build:watch": "npm run build -- --watch", | ||
"dev-serve": "concurrently \"npm run build -- --watch\" \"serve\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jspsych/jspsych-contrib.git", | ||
"directory": "packages/plugin-maze" | ||
}, | ||
"author": { | ||
"name": "Morgan Grobol", | ||
"url": "https://lgrobol.bzh" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/jspsych/jspsych-contrib/issues" | ||
}, | ||
"homepage": "https://github.com/jspsych/jspsych-contrib/tree/main/packages/plugin-maze", | ||
"peerDependencies": { | ||
"jspsych": ">=8.0.0" | ||
}, | ||
"devDependencies": { | ||
"@jspsych/config": "^3.2.2", | ||
"@jspsych/test-utils": "^1.0.0", | ||
"concurrently": "^9.1.2", | ||
"jspsych": "^8.0.0", | ||
"serve": "^14.2.4" | ||
} | ||
} |
This file contains hidden or 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,3 @@ | ||
import { makeRollupConfig } from "@jspsych/config/rollup"; | ||
|
||
export default makeRollupConfig("jsPsychMaze"); |
This file contains hidden or 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,77 @@ | ||
import { pressKey, startTimeline } from "@jspsych/test-utils"; | ||
|
||
import jsPsychMaze from "."; | ||
|
||
jest.useFakeTimers(); | ||
|
||
describe("The maze jspsych plugin", () => { | ||
it("Runs maze", async () => { | ||
const sentence = [ | ||
["The", "x-x-x"], | ||
["fashion", "realize"], | ||
["model", "shirt"], | ||
["was", "see"], | ||
["very", "into"], | ||
["self-conscious", "professionally"], | ||
["of", "do"], | ||
["her", "why"], | ||
["appearance", "sandwiches"], | ||
]; | ||
const { expectFinished, getHTML, getData, displayElement, jsPsych } = await startTimeline([ | ||
{ | ||
type: jsPsychMaze, | ||
sentence: sentence, | ||
}, | ||
]); | ||
|
||
// Start | ||
jest.advanceTimersByTime(100); | ||
pressKey("f"); | ||
|
||
for (const [_word, _foil] of sentence) { | ||
jest.advanceTimersByTime(100); | ||
pressKey("f"); | ||
} | ||
|
||
await expectFinished(); | ||
}); | ||
it("Asks questions", async () => { | ||
const sentence = [ | ||
["The", "x-x-x"], | ||
["fashion", "realize"], | ||
["model", "shirt"], | ||
["was", "see"], | ||
["very", "into"], | ||
["self-conscious", "professionally"], | ||
["of", "do"], | ||
["her", "why"], | ||
["appearance", "sandwiches"], | ||
]; | ||
const { expectFinished, getHTML, getData, displayElement, jsPsych } = await startTimeline([ | ||
{ | ||
type: jsPsychMaze, | ||
sentence: sentence, | ||
question: { | ||
text: "Who was self-conscious?", | ||
correct: "The model", | ||
wrong: "The designer", | ||
}, | ||
}, | ||
]); | ||
|
||
// Start | ||
jest.advanceTimersByTime(100); | ||
pressKey("f"); | ||
|
||
for (const [_word, _foil] of sentence) { | ||
jest.advanceTimersByTime(100); | ||
pressKey("f"); | ||
} | ||
|
||
// Question | ||
jest.advanceTimersByTime(100); | ||
pressKey("f"); | ||
|
||
await expectFinished(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.