Skip to content

Commit

Permalink
Successfully implelented rt and keystroke tracking in costBenefits.
Browse files Browse the repository at this point in the history
  • Loading branch information
moblim committed Aug 2, 2021
1 parent 1ef8d51 commit ba6280a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ psiturkit/*_turk
.vs/VSWorkspaceState.json
.vs/slnx.sqlite
.vs/Effort-Task-3/v16/.suo
.vs/Effort-Task-3/v16/.suo
*.sqlite
.vs/Effort-Task-3/v16/.suo
*.json
*.sqlite
3 changes: 1 addition & 2 deletions src/timelines/taskTrial.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import frameSpike from "../trials/frameSpike";
import choice from "../trials/choice";
import costBenefits from "../trials/costBenefits";
import { ONLINE } from "../config/main";
import { addData } from "../lib/taskUtils";
import pressBalloon from "../trials/pressBalloon";
import rewardFeedback from "../trials/rewardFeedback";
import cumulativeReward from "../trials/cumulativeReward";
Expand Down Expand Up @@ -47,7 +46,7 @@ const taskTrial = (blockSettings, blockDetails, opts) => {
rewardProbability(1000, blockSettings, opts, trialDetails),
frameSpike(700, blockSettings, opts, trialDetails),
costBenefits(1500, blockSettings, opts, trialDetails),
choice(5000, blockSettings, opts, trialDetails),
choice(6000, blockSettings, opts, trialDetails),
pressBalloon(25000, blockSettings, opts),
fixation(500),
rewardFeedback(1000, blockSettings, opts, trialDetails),
Expand Down
2 changes: 1 addition & 1 deletion src/trials/choice.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const choice = (duration, blockSettings, opts, trialDetails) => {
};
done(returnObj);
}
}, 50);
}, 20);
function after_response(info) {
clearInterval(timer);
jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
Expand Down
54 changes: 34 additions & 20 deletions src/trials/costBenefits.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { jsPsych } from "jspsych-react";
import { eventCodes, keys, canvasSize, canvasSettings } from "../config/main";
import { photodiodeGhostBox, pdSpotEncode } from "../lib/markup/photodiode";
import { removeCursor } from "../lib/utils";
import { addData } from "../lib/taskUtils";
import { drawEffort, drawSpike, drawText } from "../lib/drawUtils";

const CANVAS_SIZE = canvasSize;
Expand Down Expand Up @@ -41,7 +40,7 @@ const costBenefits = (duration, blockSettings, opts, trialDetails) => {
trialDetails.high_effort = high_effort;
trialDetails.value = value;
trialDetails.subtrial_type = "costBenefits";
addData(trialDetails, blockSettings, opts);
//addData(trialDetails, blockSettings, opts);
// add stimulus to the DOM
document.getElementById("jspsych-content").innerHTML = stimulus;
// $('#jspsych-content').addClass('task-container')
Expand Down Expand Up @@ -142,7 +141,7 @@ const costBenefits = (duration, blockSettings, opts, trialDetails) => {
};
done(returnObj);
}
}, 50);
}, 20);
function after_response(info) {
clearInterval(timer);
jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
Expand All @@ -151,32 +150,47 @@ const costBenefits = (duration, blockSettings, opts, trialDetails) => {
var timeWhenPressed = new Date().getTime();
var rt = timeWhenPressed - timeWhenStarted;
var returnObj = {
rt:rt,
rt: rt,
key: info.key,
effort: effort[0],
value: value[0],
high_effort: high_effort[0],
get_reward: get_reward[0],
subtrial_type: "costBenefits",
};
done(returnObj);
} else if (info.key === keys["P"]) {
// 0 key
timeWhenPressed = new Date().getTime();
rt = timeWhenPressed - timeWhenStarted;
returnObj = {
rt: rt,
key: info.key,
effort: effort[1],
value: value[1],
high_effort: high_effort[1],
get_reward: get_reward[1],
subtrial_type: "costBenefits"
};
done(returnObj);
var timer1 = setInterval(function () {
var now = new Date().getTime();
var percTimePassed = (now - timeWhenStarted) / 1000 / (duration / 1000);

if (percTimePassed >= 1) {
clearInterval(timer1);
done(returnObj);
}
}, 20);
}
else if (info.key === keys["P"]) {
// 0 key
timeWhenPressed = new Date().getTime();
rt = timeWhenPressed - timeWhenStarted;
returnObj = {
rt: rt,
key: info.key,
effort: effort[1],
value: value[1],
high_effort: high_effort[1],
get_reward: get_reward[1],
subtrial_type: "costBenefits",
};
var timer2 = setInterval(function () {
var now = new Date().getTime();
var percTimePassed = (now - timeWhenStarted) / 1000 / (duration / 1000);
if (percTimePassed >= 1) {
clearInterval(timer2);
done(returnObj);
}
}, 50);
}
}

var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
valid_responses: valid_keys,
Expand Down

0 comments on commit ba6280a

Please sign in to comment.