Skip to content

Commit

Permalink
changing the way we end or skip trials in egma math
Browse files Browse the repository at this point in the history
  • Loading branch information
asengupta3 committed May 21, 2024
1 parent 9ec73ed commit f5a48dd
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 8 deletions.
66 changes: 64 additions & 2 deletions task-launcher/src/tasks/math/timeline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'regenerator-runtime/runtime';
import store from 'store2';
import groupBy from 'lodash/groupBy';
// setup
import { getStimulusBlockCount, initTrialSaving, initTimeline, createPreloadTrials } from '../shared/helpers';
import { jsPsych, initializeCat } from '../taskSetup';
Expand Down Expand Up @@ -91,10 +92,71 @@ export default function buildMathTimeline(config, mediaAssets) {
}
};

initializeCat();
const createSubTaskTimeline = (fixationAndSetupBlock, groupedTimeline) => {
const tasks = groupedTimeline.keys();
tasks.forEach(task => {
const stimuli = groupedTimeline.get(task);
// This is one block of subtask trials. ex. number-identification
const subTaskBlock = {
timeline: [],
conditional_function: () => {
if (store.session.get('skipCurrentBlock')) {
store.session.set('skipCurrentBlock', false);
return false;
} else {
return true;
}
},
};
stimuli.forEach(f => {
let timelineBlock = afcStimulus({
trialType: 'audio', // or 'html'
responseAllowed: true,
promptAboveButtons: true,
task: config.task,
});
if (task.includes('Number Line')) {
timelineBlock = slider;
}
// add trials to the block (this is the core procedure for each stimulus)
const stimulusBlock = {
timeline: [timelineBlock, ifRealTrialResponse],
conditional_function: () => {
const stim = store.session.get('nextStimulus');
const skipBlockTrialType = store.page.get('skipCurrentBlock');
console.log('mark://', 'conditional Function', {trialType: stim.trialType, skipBlockTrialType});
if (stim.trialType === skipBlockTrialType) {
return false;
} else {
return true;
}
},
};
// Pushing in setup seperate so we can conditionally skip the stimulus block
subTaskBlock.timeline.push(fixationAndSetupBlock);
subTaskBlock.timeline.push(stimulusBlock);

});
timeline.push(subTaskBlock);
});
};

pushSubTaskToTimeline(setupStimulus, getStimulusBlockCount()); // Stimulus Trials
const groupedSubTimeLines = new Map();
store.session.get('corpora').stimulus.forEach(s => {
if (groupedSubTimeLines.has(s.trialType)) {
const currentValues = groupedSubTimeLines.get(s.trialType);
currentValues.push(s);
groupedSubTimeLines.set(s.trialType, currentValues);
} else {
groupedSubTimeLines.set(s.trialType, [s]);
}

});

initializeCat();

// pushSubTaskToTimeline(setupStimulus, getStimulusBlockCount()); // Stimulus Trials
createSubTaskTimeline(setupStimulus, groupedSubTimeLines);
timeline.push(taskFinished);
timeline.push(exitFullscreen);

Expand Down
14 changes: 12 additions & 2 deletions task-launcher/src/tasks/math/trials/sliderStimulus.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import _toNumber from 'lodash/toNumber';
import { jsPsych, isTouchScreen } from '../../taskSetup';
import { camelize } from '@bdelab/roar-utils';
import store from 'store2';
import { arrowKeyEmojis } from '../../shared/helpers';
import { arrowKeyEmojis, isPractice, setSkipCurrentBlock } from '../../shared/helpers';
import { finishExperiment } from '../../shared/trials';

let chosenAnswer,
sliderStart,
Expand Down Expand Up @@ -210,9 +211,16 @@ export const slider = {
document.removeEventListener('keydown', captureBtnValue);

const stimulus = store.session.get('nextStimulus');

console.log('mark://', 'Slider Stimulus', stimulus);
if (stimulus.trialType === 'Number Line 4afc') {
data.correct = chosenAnswer === store.session.get('target');
if (!isPractice(stimulus.notes)) {
if (data.correct) {
store.session.set('incorrectTrials', 0);
} else {
store.session.transact('incorrectTrials', (oldVal) => oldVal + 1);
}
}
} else {
// slider version is an approximation so we can't mark it as true/false
data.correct = null;
Expand All @@ -233,6 +241,8 @@ export const slider = {
// slider_start: stimulus.item[1] === 1 ? sliderStart / 100 : sliderStart,
slider_start: sliderStart,
});

setSkipCurrentBlock(stimulus.trialType, finishExperiment);

},
};
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const afcMatch = {

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

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

Expand Down
3 changes: 2 additions & 1 deletion task-launcher/src/tasks/shared/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export * from './fractionToMathML';
export * from './appTimer';
export * from './components'
export * from './replayAudio';
export * from './loadingScreen';
export * from './loadingScreen';
export * from './setSkipCurrentBlock'
16 changes: 16 additions & 0 deletions task-launcher/src/tasks/shared/helpers/setSkipCurrentBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import store from 'store2';

export const setSkipCurrentBlock = (skipTrialType, finishExperiment) => {
if (!!store.page.get('failedPrimaryTrials') && store.session.get('incorrectTrials') >= 1) {
store.session.set('incorrectTrials', 0);
store.page.set('skipCurrentBlock', skipTrialType);
console.log('mark://', 'Skipping after 1 failure due to failing primary task');
} else if ((store.session.get('incorrectTrials') >= store.session.get('config').maxIncorrect)) {
store.session.set('incorrectTrials', 0);
store.page.set('skipCurrentBlock', skipTrialType);
store.page.set('failedPrimaryTrials', true);
console.log('mark://', 'Skipping after 3 failure and setting failedPrimaryTrials to true');
} else if (store.session.get('maxTimeReached') && finishExperiment) {
finishExperiment();
}
};
7 changes: 5 additions & 2 deletions task-launcher/src/tasks/shared/trials/afcStimulus.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
isMaxTimeoutReached,
arrowKeyEmojis,
replayButtonDiv,
setupReplayAudio
setupReplayAudio,
setSkipCurrentBlock
} from '../../shared/helpers';
import { mediaAssets } from '../../..';
import _toNumber from 'lodash/toNumber';
Expand Down Expand Up @@ -572,7 +573,9 @@ function doOnFinish(data, task) {
});
}

if ((store.session.get('incorrectTrials') >= store.session.get('config').maxIncorrect) || store.session.get('maxTimeReached')) {
if (task === 'egma-math') {
setSkipCurrentBlock(stimulus.trialType, finishExperiment);
} else if ((store.session.get('incorrectTrials') >= store.session.get('config').maxIncorrect) || store.session.get('maxTimeReached')) {
finishExperiment();
}
}
Expand Down

0 comments on commit f5a48dd

Please sign in to comment.