Skip to content

Commit

Permalink
basic adaptive implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jodeleeuw committed Jul 31, 2023
1 parent 92dd4ff commit 2d7e9e8
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 81 deletions.
152 changes: 87 additions & 65 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/digit-span-adaptive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"jspsych": "^7.3.3"
},
"dependencies": {
"@jspsych/plugin-html-keyboard-response": "^1.1.2"
},
"devDependencies": {
"tsup": "^6.7.0",
Expand Down
34 changes: 27 additions & 7 deletions packages/digit-span-adaptive/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@ export function createTimeline(
jsPsych: JsPsych,
{
starting_span = 3,
min_span = 2,
digit_duration = 1000,
gap_duration = 0,
}: { starting_span: number; digit_duration: number; gap_duration: number }
max_attempts = 10,
}: {
starting_span: number;
min_span: number;
digit_duration: number;
gap_duration: number;
max_attempts: number;
}
) {
let current_span = starting_span;

let current_sequence = jsPsych.randomization.sampleWithReplacement(
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
current_span
);
let current_sequence = pickDigits(jsPsych, current_span);

let current_index = 0;

let attempts = 0;

const display_sequence_timeline = {
timeline: [
{
Expand All @@ -37,7 +44,13 @@ export function createTimeline(
};

const response = {
type: "TBD",
type: jsPsychHtmlKeyboardResponse,
stimulus: `<p>Y for yes, N for no</p>`,
choices: ["y", "n"],
on_finish: (data) => {
const correct = jsPsych.pluginAPI.compareKeys(data.response, "y");
data.correct = correct;
},
data: {
task: "response",
},
Expand All @@ -51,11 +64,18 @@ export function createTimeline(
current_span++;
} else {
current_span--;
if (current_span < min_span) {
current_span = min_span;
}
}
current_index = 0;
current_sequence = pickDigits(jsPsych, current_span);
attempts++;
return attempts < max_attempts;
},
};

return adaptive_loop_timeline;
}

function createDigitSpanSequence(
Expand All @@ -70,7 +90,7 @@ function createDigitSpanSequence(
gap_duration: number;
}
) {
const digits = jsPsych.randomization.sampleWithReplacement([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], n);
const digits = pickDigits(jsPsych, n);

const sequence = {
timeline: [],
Expand Down
15 changes: 6 additions & 9 deletions packages/digit-span-adaptive/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"extends": "@jspsych/config/tsconfig.contrib.json",
"compilerOptions": {
"baseUrl": "."
},
"include": [
"src",
"../cli/src/build.js"
]
}
"extends": "@jspsych/config/tsconfig.contrib.json",
"compilerOptions": {
"baseUrl": "."
},
"include": ["src", "../cli/src/build.js"]
}

0 comments on commit 2d7e9e8

Please sign in to comment.