Skip to content

Commit

Permalink
Merge branch 'main' into automate-readme-update
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriechang authored Aug 20, 2024
2 parents 8d9b3b5 + 2da485d commit 9620b56
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ However we would encourage contributors to respond to issues/questions and to ma

Contributions to `jspsych-contrib` that are broadly useful, well-documented, and well-tested may be added to the main `jsPsych` repository, with the contributor's permission.

## List of available plugins/extensions
## List of available plugins

The jsPsych plugins/extensions that have been contributed by community members can be found in the `/packages` directory.
The jsPsych plugins that have been contributed by community members can be found in the `/packages` directory.
The `/packages` directory also contains four template sub-folders that can be used as a starting point for contributing a plugin/extension (see the [Guidelines for contributions](#guidelines-for-contributions) section).






### Plugins

Expand Down Expand Up @@ -66,6 +62,7 @@ The `/packages` directory also contains four template sub-folders that can be us
[device-motion](https://github.com/jspsych/jspsych-contrib/blob/main/packages/@jspsych-contrib/extension-device-motion/README.md) | [Pedro Neto](https://github.com/pasoneto) | jsPsych extension for tracking device motion
[mediapipe-face-mesh](https://github.com/jspsych/jspsych-contrib/blob/main/packages/@jspsych-contrib/extension-mediapipe-face-mesh/README.md) | [C. Martin Grewe](https://github.com/mgrewe) | This extension provides online tracking of facial posture during trials using the [MediaPipe Face Mesh](https://google.github.io/mediapipe/solutions/face_mesh) library.
[touchscreen-buttons](https://github.com/jspsych/jspsych-contrib/blob/main/packages/@jspsych-contrib/extension-touchscreen-buttons/README.md) | [Younes Strittmatter](https://github.com/younesStrittmatter) | foo

## Guidelines for contributions


Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/plugin-video-several-keyboard-responses/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @jspsych-contrib/plugin-video-several-keyboard-responses

## 2.0.0

### Major Changes

- [#130](https://github.com/jspsych/jspsych-contrib/pull/130) [`3462071a8162dcf5e348f59c7bb8d06c222f0d08`](https://github.com/jspsych/jspsych-contrib/commit/3462071a8162dcf5e348f59c7bb8d06c222f0d08) Thanks [@jodeleeuw](https://github.com/jodeleeuw)! - Make data `rt` `key` and `video_time` fields always be an array, even when multiple responses are not allowed. Improve compatibility of simulation mode, though there are still some likely inconsistencies.

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-video-several-keyboard-responses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This plugin plays a video and records responses generated by the keyboard, based
### In browser

```js
<script src="https://unpkg.com/@jspsych-contrib/plugin-video-several-keyboard-responses@1.0.0"></script>
<script src="https://unpkg.com/@jspsych-contrib/plugin-video-several-keyboard-responses@2.0.0"></script>
```

### Via NPM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jspsych-contrib/plugin-video-several-keyboard-responses",
"version": "1.0.0",
"version": "2.0.0",
"description": "jsPsych plugin for playing a video file and getting several keyboard responses",
"type": "module",
"main": "dist/index.cjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,24 @@ describe("video-several-keyboard-responses simulation", () => {

await expectFinished();

expect(getData().values()[0].rt).toBeGreaterThan(0);
expect(typeof getData().values()[0].response).toBe("string");
const data = getData().values()[0];

expect(data.rt.every((value) => value > 0)).toBe(true);
expect(data.response.length).toEqual(data.rt.length);
expect(data.video_time.length).toEqual(data.rt.length);
});

// can't run this until we mock video elements.
test("visual mode works", async () => {
test.skip("visual mode works", async () => {
const jsPsych = initJsPsych();

const timeline = [
{
type: videoSeveralKeyboardResponses,
stimulus: ["foo.mp4"],
prompt: "foo",
trial_duration: 1000,
trial_ends_after_video: true,
response_ends_trial: false,
},
];

Expand All @@ -78,5 +82,6 @@ describe("video-several-keyboard-responses simulation", () => {
expect(rt.every((value) => value > 0)).toBe(true);
expect(response.every((value) => typeof value === "string")).toBe(true);
expect(video_time.every((value) => typeof value === "number")).toBe(true);
expect(response.length).toEqual(rt.length);
});
});
35 changes: 23 additions & 12 deletions packages/plugin-video-several-keyboard-responses/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,8 @@ class VideoSeveralKeyboardResponsesPlugin implements JsPsychPlugin<Info> {
"#jspsych-video-several-keyboard-responses-stimulus"
).className += " responded";

// by default only record the first response
if (response.key == null) {
if (!trial.multiple_responses_allowed) {
// Would make sense to add it to a list, but then it would not be backwards compatible?
response = { rt: info.rt, key: info.key, video_time: video_element.currentTime };
} else {
response = { rt: [info.rt], key: [info.key], video_time: [video_element.currentTime] };
}
response = { rt: [info.rt], key: [info.key], video_time: [video_element.currentTime] };
} else if (trial.multiple_responses_allowed) {
response.rt.push(info.rt);
response.key.push(info.key);
Expand Down Expand Up @@ -366,7 +360,9 @@ class VideoSeveralKeyboardResponsesPlugin implements JsPsychPlugin<Info> {

const respond = () => {
if (data.rt !== null) {
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
for (let i = 0; i < data.rt.length; i++) {
this.jsPsych.pluginAPI.pressKey(data.response[i], data.rt[i]);
}
}
};

Expand All @@ -378,16 +374,31 @@ class VideoSeveralKeyboardResponsesPlugin implements JsPsychPlugin<Info> {
}

private create_simulation_data(trial: TrialType<Info>, simulation_options) {
let n_responses = this.jsPsych.randomization.randomInt(1, 5);
if (!trial.multiple_responses_allowed) {
n_responses = 1;
}

const rts = [];
const responses = [];
let last_rt = 0;
for (let i = 0; i < n_responses; i++) {
const rt = Math.round(this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true));
rts.push(rt + last_rt);
last_rt = rt;
responses.push(this.jsPsych.pluginAPI.getValidKey(trial.choices));
}

const default_data = {
stimulus: trial.stimulus,
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
video_time: 0,
response: responses,
rt: rts,
video_time: rts,
};

const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);

this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
//this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);

return data;
}
Expand Down

0 comments on commit 9620b56

Please sign in to comment.