diff --git a/task-launcher/src/tasks/math/timeline.ts b/task-launcher/src/tasks/math/timeline.ts index f23925d5..e7622758 100644 --- a/task-launcher/src/tasks/math/timeline.ts +++ b/task-launcher/src/tasks/math/timeline.ts @@ -87,13 +87,15 @@ export default function buildMathTimeline(config: Record, mediaAsse throw new Error('Something went wrong. Please look in the console for error details'); } + const shouldTerminateCat = runCat; + const trialConfig = { trialType: 'audio', responseAllowed: true, promptAboveButtons: true, task: config.task, layoutConfigMap, - terminateCat: false, + terminateCat: shouldTerminateCat, }; const feedbackBlock = (trial?: StimulusType) => { @@ -150,7 +152,7 @@ export default function buildMathTimeline(config: Record, mediaAsse const sliderBlock = (trial?: StimulusType) => { return { - timeline: [slider(layoutConfigMap, trial), feedbackBlock(trial)], + timeline: [slider(layoutConfigMap, shouldTerminateCat, trial), feedbackBlock(trial)], conditional_function: () => { const trialsSkipped = taskStore().trialsSkipped; @@ -171,7 +173,7 @@ export default function buildMathTimeline(config: Record, mediaAsse const repeatSliderPracticeBlock = () => { let trials: any[] = []; sliderPractice.forEach((trial, index) => { - trials.push(slider(layoutConfigMap, trial)); + trials.push(slider(layoutConfigMap, shouldTerminateCat, trial)); if (index < sliderPractice.length - 1) { trials.push({ ...feedback(true, 'feedbackCorrect', 'feedbackNotQuiteRight'), diff --git a/task-launcher/src/tasks/math/trials/sliderStimulus.ts b/task-launcher/src/tasks/math/trials/sliderStimulus.ts index 37c57b35..e4338a57 100644 --- a/task-launcher/src/tasks/math/trials/sliderStimulus.ts +++ b/task-launcher/src/tasks/math/trials/sliderStimulus.ts @@ -14,6 +14,7 @@ import { setSentryContext, updateTheta, addPracticeButtonListeners, + shouldTerminateCat, } from '../../shared/helpers'; import { mediaAssets } from '../../..'; import { taskStore } from '../../../taskStore'; @@ -70,7 +71,7 @@ function getRandomValue(max: number, avoid: number, tolerance: number = 0.1) { return result * max; } -export const slider = (layoutConfigMap: Record, trial?: StimulusType) => { +export const slider = (layoutConfigMap: Record, terminateCat: boolean, trial?: StimulusType) => { return { type: HTMLSliderResponse, data: () => { @@ -359,6 +360,10 @@ export const slider = (layoutConfigMap: Record, trial? if (!runCat) { setSkipCurrentBlock(stimulus.trialType); } + + if (terminateCat) { + shouldTerminateCat(); + } }, }; }; diff --git a/task-launcher/src/tasks/same-different-selection/trials/afcMatch.ts b/task-launcher/src/tasks/same-different-selection/trials/afcMatch.ts index 57188d80..03a3b07d 100644 --- a/task-launcher/src/tasks/same-different-selection/trials/afcMatch.ts +++ b/task-launcher/src/tasks/same-different-selection/trials/afcMatch.ts @@ -10,6 +10,7 @@ import { camelize, enableOkButton, disableOkButton, + shouldTerminateCat, } from '../../shared/helpers'; import { finishExperiment } from '../../shared/trials'; import { taskStore } from '../../../taskStore'; @@ -321,6 +322,7 @@ export const afcMatch = (trial?: StimulusType) => { } if (cat) { + shouldTerminateCat(); updateTheta(stim, isCorrect); const allSequentialTrials = taskStore().sequentialTrials; diff --git a/task-launcher/src/tasks/same-different-selection/trials/legacyStimulus.ts b/task-launcher/src/tasks/same-different-selection/trials/legacyStimulus.ts index c9121f2d..c31c1147 100644 --- a/task-launcher/src/tasks/same-different-selection/trials/legacyStimulus.ts +++ b/task-launcher/src/tasks/same-different-selection/trials/legacyStimulus.ts @@ -7,6 +7,7 @@ import { setupReplayAudio, PageAudioHandler, camelize, + shouldTerminateCat, } from '../../shared/helpers'; import { finishExperiment } from '../../shared/trials'; import { isTouchScreen, jsPsych } from '../../taskSetup'; @@ -308,7 +309,7 @@ export const legacyStimulus = (trial?: StimulusType) => { taskStore.transact('testTrialCount', (oldVal: number) => oldVal + 1); } // if heavy instructions is true, show data quality screen before ending - if (taskStore().numIncorrect >= taskStore().maxIncorrect && !taskStore().heavyInstructions) { + if (taskStore().numIncorrect >= taskStore().maxIncorrect && !taskStore().heavyInstructions && !cat) { finishExperiment(); } @@ -317,6 +318,7 @@ export const legacyStimulus = (trial?: StimulusType) => { } if (cat && !(stim.assessmentStage === 'practice_response')) { + shouldTerminateCat(); setNextCatTrial(stim); } } diff --git a/task-launcher/src/tasks/same-different-selection/trials/stimulus.ts b/task-launcher/src/tasks/same-different-selection/trials/stimulus.ts index e115c7a1..6ac44299 100644 --- a/task-launcher/src/tasks/same-different-selection/trials/stimulus.ts +++ b/task-launcher/src/tasks/same-different-selection/trials/stimulus.ts @@ -15,6 +15,7 @@ import { isTouchScreen, jsPsych } from '../../taskSetup'; import { taskStore } from '../../../taskStore'; import { updateTheta } from '../../shared/helpers'; import { setNextCatTrial } from '../helpers/setNextCatTrial'; +import { shouldTerminateCat } from '../../shared/helpers/shouldTerminateCat'; const replayButtonHtmlId = 'replay-btn-revisited'; let incorrectPracticeResponses: string[] = []; @@ -420,6 +421,7 @@ export const stimulus = (trial?: StimulusType) => { } if (stim.trialType !== 'something-same-1' && stim.trialType !== 'instructions') { + shouldTerminateCat(); updateTheta(stim, isCorrect); } diff --git a/task-launcher/src/tasks/shared/helpers/getCorpus.ts b/task-launcher/src/tasks/shared/helpers/getCorpus.ts index 43d3513d..4f35e40c 100644 --- a/task-launcher/src/tasks/shared/helpers/getCorpus.ts +++ b/task-launcher/src/tasks/shared/helpers/getCorpus.ts @@ -177,7 +177,7 @@ export const getCorpus = async (config: Record, isDev: boolean) => const bucketName = getBucketName(task, isDev, 'corpus'); - const corpusUrl = `https://storage.googleapis.com/${bucketName}/${corpus}.csv?alt=media?v=2`; + const corpusUrl = `https://storage.googleapis.com/${bucketName}/${corpus}.csv?alt=media`; function downloadCSV(url: string) { return new Promise((resolve, reject) => { diff --git a/task-launcher/src/tasks/shared/helpers/shouldTerminateCat.ts b/task-launcher/src/tasks/shared/helpers/shouldTerminateCat.ts index 3a4f8fa4..425b6653 100644 --- a/task-launcher/src/tasks/shared/helpers/shouldTerminateCat.ts +++ b/task-launcher/src/tasks/shared/helpers/shouldTerminateCat.ts @@ -1,12 +1,22 @@ import { jsPsych } from "../../taskSetup"; import { finishExperiment } from "../trials/finishExperiment"; +const exemptTrialTypes = ['something-same-1']; +const eligibleAssessmentStages = ['test_response', 'first_response', 'second_response', 'third_response', 'fourth_response']; + // ends the task if 4 of the last 10 trials have been incorrect export function shouldTerminateCat() { - const data = jsPsych.data.get().filter({assessment_stage: 'test_response'}).last(10); + const data = jsPsych.data.get().filterCustom((trial: any) => { + return ( + !exemptTrialTypes.includes(trial.corpusTrialType) && + eligibleAssessmentStages.includes(trial.assessment_stage) + ); + }); + const lastTenTrials = data.last(10); + const incorrectTrials = lastTenTrials.filter({correct: false}); + const terminate = incorrectTrials.count() > 6; - const incorrectTrials = data.filter({correct: false}).count(); - if (incorrectTrials >= 4) { + if (terminate) { finishExperiment(); } }