Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/lnccbrown/task-effort into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
moblim committed Aug 2, 2021
2 parents dcd2198 + 21213bb commit e92003f
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/timelines/taskTrial.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import fixation from "../trials/fixation";
import rewardProbability from "../trials/rewardProbability";
import frameSpike from "../trials/frameSpike";
//import frameSpike from "../trials/frameSpike";
import choice from "../trials/choice";
import costBenefits from "../trials/costBenefits";
import { ONLINE } from "../config/main";
Expand Down
200 changes: 100 additions & 100 deletions src/trials/choice.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,93 +18,93 @@ const choice = (duration, blockSettings, opts, trialDetails) => {
photodiodeGhostBox() +
`</div>`;

const startCode = eventCodes.choiceStart;
const startCode = eventCodes.choiceStart;

duration = blockSettings.is_practice ? 5000000 : duration; // make practice choices have no timeout
let probability = blockSettings.is_practice ? opts : opts.prob;
let value = blockSettings.is_practice ? blockSettings.value : opts.value;
let effort = blockSettings.is_practice ? blockSettings.effort : opts.effort;
let high_effort = blockSettings.is_practice
? blockSettings.high_effort
: opts.high_effort;
let valid_keys = blockSettings.keys;
let get_reward = blockSettings.is_practice
? blockSettings.get_reward
: opts.get_reward;
duration = blockSettings.is_practice ? 5000000 : duration; // make practice choices have no timeout
let probability = blockSettings.is_practice ? opts : opts.prob;
let value = blockSettings.is_practice ? blockSettings.value : opts.value;
let effort = blockSettings.is_practice ? blockSettings.effort : opts.effort;
let high_effort = blockSettings.is_practice
? blockSettings.high_effort
: opts.high_effort;
let valid_keys = blockSettings.keys;
let get_reward = blockSettings.is_practice
? blockSettings.get_reward
: opts.get_reward;

return {
type: "call_function",
async: true,
func: (done) => {
// add stimulus to the DOM
document.getElementById("jspsych-content").innerHTML = stimulus;
// $('#jspsych-content').addClass('task-container')
return {
type: "call_function",
async: true,
func: (done) => {
// add stimulus to the DOM
document.getElementById("jspsych-content").innerHTML = stimulus;
// $('#jspsych-content').addClass('task-container')

// set up canvas
let canvas = document.querySelector("#jspsych-canvas");
let ctx = canvas.getContext("2d");
let timeWhenStarted = new Date().getTime();
// set up canvas
let canvas = document.querySelector("#jspsych-canvas");
let ctx = canvas.getContext("2d");
let timeWhenStarted = new Date().getTime();

const canvasDraw = () => {
// transparent background
ctx.clearRect(0, 0, canvas.width, canvas.height);
var inflateBy;
var spikeHeight = [0, 0];
for (let i = 0; i < 2; i++) {
if (high_effort[i]) {
inflateBy = canvasSettings.inflateByHE;
} else {
inflateBy = canvasSettings.inflateByNHE;
}
const canvasDraw = () => {
// transparent background
ctx.clearRect(0, 0, canvas.width, canvas.height);
var inflateBy;
var spikeHeight = [0, 0];
for (let i = 0; i < 2; i++) {
if (high_effort[i]) {
inflateBy = canvasSettings.inflateByHE;
} else {
inflateBy = canvasSettings.inflateByNHE;
}

// how far should the spike be
var targetDist = 2 * inflateBy * (effort[i] - 1);
var balloonBaseHeight =
canvasSettings.balloonBaseHeight + 2 * canvasSettings.balloonRadius;
// distance of the spike from the top
spikeHeight[i] = effort[i]
? canvasSettings.frameDimensions[1] -
balloonBaseHeight -
targetDist -
canvasSettings.spiketopHeight
: 0;
}
// how far should the spike be
var targetDist = 2 * inflateBy * (effort[i] - 1);
var balloonBaseHeight =
canvasSettings.balloonBaseHeight + 2 * canvasSettings.balloonRadius;
// distance of the spike from the top
spikeHeight[i] = effort[i]
? canvasSettings.frameDimensions[1] -
balloonBaseHeight -
targetDist -
canvasSettings.spiketopHeight
: 0;
}

drawText(
ctx,
`${probability}`,
canvasSettings.rewProbXpos,
canvasSettings.rewProbYpos,
"undefined"
);
drawText(
ctx,
`${probability}`,
canvasSettings.rewProbXpos,
canvasSettings.rewProbYpos,
"undefined"
);

// drawFrame(ctx, canvasSettings.frameDimensions[0], canvasSettings.frameDimensions[1], canvasSettings.frameXpos[0], canvasSettings.frameYpos, canvasSettings.frameLinecolor, false)
drawSpike(
ctx,
canvasSettings.spikeWidth,
spikeHeight[0],
canvasSettings.spikeXpos[0],
canvasSettings.spikeYpos,
canvasSettings.frameLinecolor,
canvasSettings.frameLinecolor,
false
);
drawEffort(
ctx,
value[0],
effort[0],
canvasSettings.textXpos[0],
canvasSettings.textYpos,
high_effort[0]
);
drawBalloon(
ctx,
effort[0],
high_effort[0],
canvasSettings.balloonXpos[0],
canvasSettings.balloonYpos,
canvasSettings.balloonRadius
);
// drawFrame(ctx, canvasSettings.frameDimensions[0], canvasSettings.frameDimensions[1], canvasSettings.frameXpos[0], canvasSettings.frameYpos, canvasSettings.frameLinecolor, false)
drawSpike(
ctx,
canvasSettings.spikeWidth,
spikeHeight[0],
canvasSettings.spikeXpos[0],
canvasSettings.spikeYpos,
canvasSettings.frameLinecolor,
canvasSettings.frameLinecolor,
false
);
drawEffort(
ctx,
value[0],
effort[0],
canvasSettings.textXpos[0],
canvasSettings.textYpos,
high_effort[0]
);
drawBalloon(
ctx,
effort[0],
high_effort[0],
canvasSettings.balloonXpos[0],
canvasSettings.balloonYpos,
canvasSettings.balloonRadius
);

// drawFrame(ctx, canvasSettings.frameDimensions[0], canvasSettings.frameDimensions[1], canvasSettings.frameXpos[1], canvasSettings.frameYpos, canvasSettings.frameLinecolor, false)
drawSpike(
Expand Down Expand Up @@ -135,10 +135,10 @@ const choice = (duration, blockSettings, opts, trialDetails) => {
);
};

canvasDraw();
var timer = setInterval(function () {
var now = new Date().getTime();
var percTimePassed = (now - timeWhenStarted) / 1000 / (duration / 1000);
canvasDraw();
var timer = setInterval(function () {
var now = new Date().getTime();
var percTimePassed = (now - timeWhenStarted) / 1000 / (duration / 1000);

if (percTimePassed >= 1) {
jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
Expand Down Expand Up @@ -193,22 +193,22 @@ const choice = (duration, blockSettings, opts, trialDetails) => {
trialDetails.value = value;
trialDetails.subtrial_type = "choice";

var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
valid_responses: valid_keys,
rt_method: "date",
persist: true,
allow_held_key: false,
});
},
on_load: () => {
removeCursor("experiment");
pdSpotEncode(startCode);
},
on_finish: (data) => {
data.code = startCode;
},
};
var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
valid_responses: valid_keys,
rt_method: "date",
persist: true,
allow_held_key: false,
});
},
on_load: () => {
removeCursor("experiment");
pdSpotEncode(startCode);
},
on_finish: (data) => {
data.code = startCode;
},
};
};

export default choice;

1 comment on commit e92003f

@moblim
Copy link
Collaborator Author

@moblim moblim commented on e92003f Aug 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally figured out how to stop merge conflicts. These changes were already tested by Michael and I but the pull request kept showing conflicts with temp files like workspace files and other .json files. manual merging wasn't working as my origin was my forked repo and not this one. Merging from that repo to main caused the same problem, so I changed that in github desktop and it allowed me to merge conflicts between my local repo and main, so I could directly merge changes. I'll stick to pull requests, as this was a last ditch effort to fix a stubborn error!

Please sign in to comment.