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

Adding early stopping to H&F #109

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions task-launcher/src/tasks/hearts-and-flowers/trials/stimulus.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import {
} from '../helpers/utils';
import store from 'store2';
import shuffle from 'lodash/shuffle';
import { finishExperiment } from '../../shared/trials';

/**
*TODO: we should perhaps allow {@link https://www.jspsych.org/7.2/overview/media-preloading/#automatic-preloading automatic preload}
of the stimulus image and modify the DOM nodes that jsPsych creates in on_load?
*/
const numIncorrect = store.page.namespace('numIncorrect', 0);

export function stimulus(isPractice, stage, stimulusDuration, onTrialFinishTimelineCallback = undefined ) {
return {
type: jsPsychHTMLMultiResponse,
Expand Down Expand Up @@ -74,6 +77,23 @@ export function stimulus(isPractice, stage, stimulusDuration, onTrialFinishTimel
// record whether answer was correct or not
const validAnswer = getCorrectInputSide(stimulusType, stimuluSide)
data.correct = validAnswer === response;

if (!isPractice) {
if (!data.correct) {
numIncorrect.transact('numIncorrect', (oldVal) => oldVal + 1);

console.log('numIncorrect: ', numIncorrect('numIncorrect'));
} else {
numIncorrect('numIncorrect', 0);
}
}

const maxIncorrect = store.session.get('config').maxIncorrect;

if ((numIncorrect('numIncorrect') == maxIncorrect) || store.session.get('maxTimeReached')) {
finishExperiment();
}

//TODO: move these to timeline-level callback/variables
store.session.set('correct', data.correct);
store.session.set('stimulus', stimulusType);
Expand Down
4 changes: 4 additions & 0 deletions task-launcher/src/tasks/shared/helpers/createPreloadTrials.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ function createJsPsychPreloadObject() {
images: [],
audio: [],
video: [],
// TODO: Make LEVANTE loading screen disappear when preload is done
// on_finish: () => {
// hideLevanteLogoLoading();
// },
};
}
Loading