Skip to content

Commit

Permalink
Merge pull request #65 from lnccbrown/develop-countPumps-rt
Browse files Browse the repository at this point in the history
Develop count pumps rt
  • Loading branch information
wasita authored Dec 17, 2019
2 parents 1f6cc18 + 74ba7da commit ff4eaf3
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 69 deletions.
1 change: 1 addition & 0 deletions public/config/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const eventCodes = {
rewardFeedbackEnd: 71,
showPaymentStart: 80,
showPaymendEnd: 81,
trialFinish: 3,
test_connect: 4,
open_task: 5
}
Expand Down
46 changes: 23 additions & 23 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,30 @@ const setUpPort = async () => {
}

const handleEventSend = (code) => {
if (!portAvailable && !SKIP_SENDING_DEV) {
let message = "Event Marker not connected"
log.warn(message)

let buttons = ["Quit", "Retry"]
if (process.env.ELECTRON_START_URL) {
buttons.push("Continue Anyway")
}
dialog.showMessageBox(mainWindow, {type: "error", message: message, title: "Task Error", buttons: buttons, defaultId: 0})
.then((resp) => {
let opt = resp.response
if (opt == 0) { // quit
app.exit()
} else if (opt == 1) { // retry
setUpPort()
.then(() => handleEventSend(code))
} else if (opt == 2) {
// if (!portAvailable && !SKIP_SENDING_DEV) {
// let message = "Event Marker not connected"
// log.warn(message)
//
// let buttons = ["Quit", "Retry"]
// if (process.env.ELECTRON_START_URL) {
// buttons.push("Continue Anyway")
// }
// dialog.showMessageBox(mainWindow, {type: "error", message: message, title: "Task Error", buttons: buttons, defaultId: 0})
// .then((resp) => {
// let opt = resp.response
// if (opt == 0) { // quit
// app.exit()
// } else if (opt == 1) { // retry
// setUpPort()
// .then(() => handleEventSend(code))
// } else if (opt == 2) {
SKIP_SENDING_DEV = true
}
})

} else if (!SKIP_SENDING_DEV) {
sendToPort(triggerPort, code)
}
// }
// })
//
// } else if (!SKIP_SENDING_DEV) {
// sendToPort(triggerPort, code)
// }
}

// EVENT TRIGGER
Expand Down
6 changes: 3 additions & 3 deletions src/config/experiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ exptBlock1.probs = ["100%", "100%", "50%", "50%"]
exptBlock1.counterbalance = true
exptBlock1.value = [3, 5, 7]
exptBlock1.effort = [100, 120, 150]
exptBlock1.keys = ['q', 'p']
exptBlock1.keys = ['q', 'p', 'm']
exptBlock1.get_reward = [true, true, true, false]

// debug settings where there are only 2 trials in main task block
// exptBlock1.probs = ["100%"]
// exptBlock1.counterbalance = true
// exptBlock1.value = [3]
// exptBlock1.effort = [20]
// exptBlock1.keys = ['q', 'p']
// exptBlock1.effort = [5]
// exptBlock1.keys = ['q', 'p', 'm']
// exptBlock1.get_reward = [true]


Expand Down
3 changes: 2 additions & 1 deletion src/config/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const canvasSettings = {
const keys = {
"P": 80,
"Q": 81,
"space": 32
"space": 32,
"experimenter": 'm' // key experimenter presses to quit payment screen
}

// is this mechanical turk?
Expand Down
4 changes: 3 additions & 1 deletion src/config/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const eventCodes = {
rewardFeedbackStart: 70,
rewardFeedbackEnd: 71,
showPaymentStart: 80,
showPaymendEnd: 81,
showPaymentEnd: 81,
trialFinishStart: 90,
trialFinishEnd: 91,
test_connect: 4,
open_task: 5
}
Expand Down
2 changes: 1 addition & 1 deletion src/language/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"total": "Total:<br>"
},
"payment": {
"earned": "You you have earned",
"earned": "You have earned",
"experimenter": "Please inform the experimenter."
}
}
18 changes: 7 additions & 11 deletions src/lib/taskUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ import _ from 'lodash'

// initialize starting conditions for each trial within a block
const generateStartingOpts = (blockSettings) => {
if(blockSettings.is_practice)
{
if (blockSettings.is_practice) {
let startingOptions = blockSettings.probs.map( (c) => {
// Repeat each starting condition the same number of times
return _.range(blockSettings.repeats_per_condition).map( () => c )
})

return _.shuffle(_.flatten(startingOptions))
}
else
{
} else {
let opts = []
for (let i = 0; i < blockSettings.probs.length; i++){
for (let val in blockSettings.value){
for (let eff in blockSettings.effort){
opts.push({prob: blockSettings.probs[i], effort: [blockSettings.effort[eff],20], value: [blockSettings.value[val], 1], high_effort: [true, false], get_reward: [blockSettings.get_reward[i], blockSettings.get_reward[i]]})
if (blockSettings.counterbalance){
for (let i = 0; i < blockSettings.probs.length; i++) {
for (let val in blockSettings.value) {
for (let eff in blockSettings.effort) {
opts.push({prob : blockSettings.probs[i], effort: [blockSettings.effort[eff],20], value: [blockSettings.value[val], 1], high_effort: [true, false], get_reward: [blockSettings.get_reward[i], blockSettings.get_reward[i]]})
if (blockSettings.counterbalance) {
opts.push({prob: blockSettings.probs[i], effort: [20, blockSettings.effort[eff]], value: [1, blockSettings.value[val]], high_effort: [false, true], get_reward: [blockSettings.get_reward[i], blockSettings.get_reward[i]]});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/timelines/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const primaryTimeline = [
postPracticeInstructions(),
buildCountdown(lang.countdown.expt1, 3),
taskBlock(exptBlock1),
showPayment(5000),
showPayment(5000, exptBlock1),
experimentEnd(5000)
]

Expand Down
42 changes: 25 additions & 17 deletions src/trials/pressBalloon.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,26 @@ const pressBalloon = (duration, blockSettings) => {

return points;
}

function pop() {
clearInterval(timer);
// pop balloon
popped = true;
// this.deleteCircle();

reward = computeReward()
data ={
data = {
"reward": reward,
"is_practice": is_practice,
"subtrial_type": 'inflate_balloon',
"rt": rts,
"pumps": countPumps,
"timeWhenPopped": (new Date()).getTime(),
"firstPress": rts[0],
"lastPress": rts[rts.length - 1],
}
};

function popTimeout() {
clearInterval(timer);
// pop balloon
Expand All @@ -117,6 +124,10 @@ const pressBalloon = (duration, blockSettings) => {
"reward": reward,
"is_practice": is_practice,
"subtrial_type": 'inflate_balloon',
"rt": rts,
"pumps": countPumps,
"firstPress": rts[0],
"lastPress": rts[rts.length - 1],
}
};
function hitSpike() {
Expand All @@ -129,12 +140,14 @@ const pressBalloon = (duration, blockSettings) => {
}
return crash;
}

let rts = []

function inflate(choice) {
// if (popped){
// return
// }

let rts = []
// Record RT relative to when trial started
var timeWhenPressed = (new Date()).getTime();
var rt = timeWhenPressed - timeWhenStarted
Expand All @@ -149,39 +162,34 @@ const pressBalloon = (duration, blockSettings) => {
balloonYpos -= inflateBy;

// redraw
if (choice.key === keys['Q']){
if (choice.key === keys['Q']) {
drawBalloon(ctx, choice.effort, choice.high_effort, canvasSettings.balloonXpos[0], balloonYpos, radius)
}
if (choice.key === keys['P']){
if (choice.key === keys['P']) {
drawBalloon(ctx, choice.effort, choice.high_effort, canvasSettings.balloonXpos[1], balloonYpos, radius)
}
if (hitSpike() && !choice.high_effort){
if (hitSpike() && !choice.high_effort) {
pop()
}
if (hitSpike() && choice.high_effort)
{
if (choice.key === keys['Q'])
{
if (hitSpike() && choice.high_effort) {
if (choice.key === keys['Q']) {
drawSpike(ctx, canvasSettings.spikeWidth, spikeHeight, canvasSettings.spikeXpos[0], canvasSettings.spikeYpos, canvasSettings.frameLinecolor, canvasSettings.frameLinecolor, true)
drawBalloon(ctx, choice.effort, choice.high_effort, canvasSettings.balloonXpos[0], balloonYpos, radius)
}
if (choice.key === keys['P'])
{
if (choice.key === keys['P']) {
drawSpike(ctx, canvasSettings.spikeWidth, spikeHeight, canvasSettings.spikeXpos[1], canvasSettings.spikeYpos, canvasSettings.frameLinecolor, canvasSettings.frameLinecolor, true)
drawBalloon(ctx, choice.effort, choice.high_effort, canvasSettings.balloonXpos[1], balloonYpos, radius)
}
var balloonBase = canvasSettings.balloonBaseHeight
var balloonHeight = (balloonBase + (2* radius));
var balloonHeight = (balloonBase + (2 * radius));
spikeHeight = canvasSettings.frameDimensions[1] - balloonHeight - canvasSettings.spiketopHeight
if (choice.key === keys['Q'])
{
if (choice.key === keys['Q']) {
drawSpike(ctx, canvasSettings.spikeWidth, spikeHeight, canvasSettings.spikeXpos[0], canvasSettings.spikeYpos, canvasSettings.frameLinecolor, canvasSettings.frameLinecolor, false)
}
if (choice.key === keys['P'])
{
if (choice.key === keys['P']) {
drawSpike(ctx, canvasSettings.spikeWidth, spikeHeight, canvasSettings.spikeXpos[1], canvasSettings.spikeYpos, canvasSettings.frameLinecolor, canvasSettings.frameLinecolor, false)
}
if (countPumps > choice.effort+10){
if (countPumps > choice.effort + 10) {
pop()
return
}
Expand Down
17 changes: 10 additions & 7 deletions src/trials/showPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import { baseStimulus } from '../lib/markup/stimuli'
import { formatDollars, addCursor } from '../lib/utils'


const showPayment = (duration) => {
const showPayment = (duration, blockSettings) => {
const startCode = eventCodes.showPaymentStart
const endCode = eventCodes.showPaymentEnd

const total_earnings = 0 // initialize idk
let total_earnings = 0 // initialize idk
let experimenterKey = blockSettings.keys[2] // 0 is q, 1 is p, 2 is m

if (!AT_HOME || MTURK) {
return {
type: 'html_keyboard_response',
stimulus: '',
response_ends_trial: false,
trial_duration: duration,
choices: experimenterKey,
response_ends_trial: true,
// trial_duration: duration,
on_load: () => {
pdSpotEncode(startCode)
addCursor('experiment')
Expand All @@ -25,22 +27,23 @@ const showPayment = (duration) => {
const value = jsPsych.data.get().select('value').values
const last = value[value.length - 1]
const total_cumulative = last.trial_cumulative_earnings
const total_earnings = total_cumulative / 20 // $1 for every 20 pts
total_earnings += (total_cumulative / 20) // $1 for every 20 pts

trial.stimulus = baseStimulus(`<h1>${lang.payment.earned}<br>${formatDollars(total_earnings)}</h1>`, true) +
trial.stimulus = baseStimulus(`<h1>${lang.payment.earned}<br>${formatDollars(total_earnings)}<br></br>${lang.payment.experimenter}</h1>`, true) +
photodiodeGhostBox()
},
on_finish: (data) => {
pdSpotEncode(endCode)
data.code = [startCode, endCode]
data.total_earnings = total_earnings
data.subtrial_type = "show_payment"
}
}
}
else {
return {
type: 'html_keyboard_response',
trial_duration: 1,
// trial_duration: 1,
on_load: () => addCursor('experiment')
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/trials/trialEnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ import { eventCodes, MTURK } from '../config/main'
import { photodiodeGhostBox, pdSpotEncode } from '../lib/markup/photodiode'

const trialEnd = (trialDetails, duration) => {
const startCode = eventCodes.trialFinishStart
const endCode = eventCodes.trialFinishEnd
const endCode = eventCodes.trialFinish

return {
type: 'html_keyboard_response',
stimulus: '',
response_ends_trial: false,
trial_duration: duration,
on_load: () => {
pdSpotEncode(startCode)
},
on_start: (trial) => {
if (!MTURK) trial.stimulus += photodiodeGhostBox()
},
on_finish: (data) => {
pdSpotEncode(endCode)
data.code = [startCode, endCode]
data.code = endCode
}
}
}
Expand Down

0 comments on commit ff4eaf3

Please sign in to comment.