From f5a48dd862f00d050c1d75102ade932a792f8101 Mon Sep 17 00:00:00 2001 From: Aritra Date: Tue, 21 May 2024 19:12:35 +0530 Subject: [PATCH] changing the way we end or skip trials in egma math --- task-launcher/src/tasks/math/timeline.js | 66 ++++++++++++++++++- .../src/tasks/math/trials/sliderStimulus.js | 14 +++- .../trials/afcMatch.js | 2 +- .../src/tasks/shared/helpers/index.js | 3 +- .../shared/helpers/setSkipCurrentBlock.js | 16 +++++ .../src/tasks/shared/trials/afcStimulus.js | 7 +- 6 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 task-launcher/src/tasks/shared/helpers/setSkipCurrentBlock.js diff --git a/task-launcher/src/tasks/math/timeline.js b/task-launcher/src/tasks/math/timeline.js index 1ea28798..4e49cdf1 100644 --- a/task-launcher/src/tasks/math/timeline.js +++ b/task-launcher/src/tasks/math/timeline.js @@ -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'; @@ -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); diff --git a/task-launcher/src/tasks/math/trials/sliderStimulus.js b/task-launcher/src/tasks/math/trials/sliderStimulus.js index 29398a96..be028aca 100644 --- a/task-launcher/src/tasks/math/trials/sliderStimulus.js +++ b/task-launcher/src/tasks/math/trials/sliderStimulus.js @@ -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, @@ -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; @@ -233,6 +241,8 @@ export const slider = { // slider_start: stimulus.item[1] === 1 ? sliderStart / 100 : sliderStart, slider_start: sliderStart, }); + + setSkipCurrentBlock(stimulus.trialType, finishExperiment); }, }; diff --git a/task-launcher/src/tasks/same-different-selection/trials/afcMatch.js b/task-launcher/src/tasks/same-different-selection/trials/afcMatch.js index 4b64252b..d389eb69 100644 --- a/task-launcher/src/tasks/same-different-selection/trials/afcMatch.js +++ b/task-launcher/src/tasks/same-different-selection/trials/afcMatch.js @@ -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(); } diff --git a/task-launcher/src/tasks/shared/helpers/index.js b/task-launcher/src/tasks/shared/helpers/index.js index da51d8f2..5ddb078c 100644 --- a/task-launcher/src/tasks/shared/helpers/index.js +++ b/task-launcher/src/tasks/shared/helpers/index.js @@ -23,4 +23,5 @@ export * from './fractionToMathML'; export * from './appTimer'; export * from './components' export * from './replayAudio'; -export * from './loadingScreen'; \ No newline at end of file +export * from './loadingScreen'; +export * from './setSkipCurrentBlock' diff --git a/task-launcher/src/tasks/shared/helpers/setSkipCurrentBlock.js b/task-launcher/src/tasks/shared/helpers/setSkipCurrentBlock.js new file mode 100644 index 00000000..a639413e --- /dev/null +++ b/task-launcher/src/tasks/shared/helpers/setSkipCurrentBlock.js @@ -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(); + } +}; \ No newline at end of file diff --git a/task-launcher/src/tasks/shared/trials/afcStimulus.js b/task-launcher/src/tasks/shared/trials/afcStimulus.js index 1fec6266..f4f6d352 100644 --- a/task-launcher/src/tasks/shared/trials/afcStimulus.js +++ b/task-launcher/src/tasks/shared/trials/afcStimulus.js @@ -10,7 +10,8 @@ import { isMaxTimeoutReached, arrowKeyEmojis, replayButtonDiv, - setupReplayAudio + setupReplayAudio, + setSkipCurrentBlock } from '../../shared/helpers'; import { mediaAssets } from '../../..'; import _toNumber from 'lodash/toNumber'; @@ -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(); } }