working prototype

This commit is contained in:
2026-02-20 00:49:20 +01:00
parent 39ddf07973
commit 9b226d60da
5 changed files with 810 additions and 35 deletions

View File

@@ -8,13 +8,17 @@ import '@jspsych/plugin-survey/css/survey.css';
import './styles.css';
import { getStimulusMap } from './scripts/text-stimuli.js';
import { textStimuli } from './scripts/text-stimuli.js';
import JsPsychDieRoll from './plugins/jspsych-die-roll.js';
import JsPsychCaptcha from './plugins/jspsych-captcha.js';
import html from './utils/html.js';
const experiment_name = import.meta.env.VITE_EXPERIMENT_NAME;
let prolific_id;
let probe_condition; // will be set to ai or human based on the condition.
let debug = false;
let debug;
let probe_order; // will be set to ai_first or human_first based on the condition
const CAPTCHA_TRIAL_COUNT = debug ? 2 : 12; // set to 10 for main experiment
function delayed_redirect(url) {
setTimeout(() => {
@@ -34,9 +38,14 @@ const jsPsych = initJsPsych({
console.log(jsPsych.data.get().json());
}
},
show_progress_bar: true,
});
debug = jsPsych.data.getURLVariable('debug') === 'true';
debug =
jsPsych.data.getURLVariable('debug') === 'true' ||
import.meta.env.VITE_DEBUG === 'true';
console.log('debug:', debug);
prolific_id = jsPsych.data.getURLVariable('PROLIFIC_PID');
@@ -54,22 +63,28 @@ const probe_text_difficulty =
'while the die roll was random, the difficulty of the captcha task was pre-determined and unrelated to the die roll. ' +
probe_closing_text;
let die_result = 3;
switch (COND) {
case 0:
probe_condition = 'die';
probe_order = 'die_first';
die_result = 4;
break;
case 1:
probe_condition = 'die';
probe_order = 'die_first';
die_result = 4;
break;
case 2:
probe_condition = 'difficulty';
probe_order = 'die_first';
die_result = 4;
break;
case 3:
probe_condition = 'difficulty';
probe_order = 'die_first';
die_result = 4;
break;
case 4:
probe_condition = 'die';
@@ -135,6 +150,18 @@ const instructions_1 = {
stimulus: stimulusMap.get('instructions_1'),
};
const instructions_2 = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('instructions_2'),
};
const instructions_3 = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('instructions_3'),
};
const debrief = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
@@ -147,6 +174,40 @@ const pre_survey_info = {
stimulus: stimulusMap.get('pre_survey_info'),
};
const die_roll_trial = {
type: JsPsychDieRoll,
prompt: html`
<p class="mt-2">
Click the die once to start it rolling, then click it again to stop.
</p>
`,
rigged_value: die_result,
roll_duration: 2200,
result_template: `You rolled a {{value}} (moderate difficulty). Click 'continue' to proceed.`,
};
const create_captcha_trial = trial_index => {
return {
type: JsPsychCaptcha,
prompt:
'<p class="leading-relaxed text-center">Enter the characters you see into the textbox below.</p>',
difficulty: die_result,
button_label: 'Continue',
error_text: '',
allow_refresh: false,
require_correct: false,
data: {
trial_id: 'captcha_entry',
captcha_index: trial_index + 1,
captcha_total: CAPTCHA_TRIAL_COUNT,
},
};
};
const captcha_trials = Array.from({ length: CAPTCHA_TRIAL_COUNT }, (_, index) =>
create_captcha_trial(index)
);
const die_probe_row = {
text:
'I suspected that the die roll was not random, or the number I received was pre-determined.',
@@ -209,6 +270,14 @@ const survey = {
text: `I found the captcha task difficult.`,
value: 'Difficulty',
},
{
text: `I felt lucky during the die roll.`,
value: 'Luck',
},
{
text: `I felt unlucky during the die roll.`,
value: 'Bad_luck',
},
{
text: `I think I solved all the captchas correctly.`,
value: 'Accuracy',
@@ -331,18 +400,25 @@ const survey = {
},
};
const main_experiment_timeline = [
instructions_1,
instructions_2,
die_roll_trial,
instructions_3,
...captcha_trials,
pre_survey_info,
survey,
debrief,
];
if (debug) {
timeline.push(survey);
timeline.push(debrief);
timeline.push(...main_experiment_timeline);
}
if (!debug) {
timeline.push(pre_consent_info);
timeline.push(consent_form);
timeline.push(enter_fullscreen);
timeline.push(instructions_1);
timeline.push(pre_survey_info);
timeline.push(survey);
timeline.push(debrief);
timeline.push(...main_experiment_timeline);
}
jsPsych.run(timeline);