Skip to content

Commit

Permalink
fix recording of alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-tsvilodub committed Jun 26, 2024
1 parent 00100ad commit 4cab037
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
42 changes: 40 additions & 2 deletions experiments/04-priorSensitivity_free_production/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<template v-for="(trial, i) in trials">
<template v-if="!trial.type">
<FreetypingScreen :key=i :trial=trial[0] :trial_type="'main'" :index=i :progress="i / trials.length" :condition=trial[1] />
<FreetypingScreen :key=i :trial=trial[0] :trial_type="'main'" :index=i :progress="i / trials.length" :condition=trial[1] :trialAlternatives=trial[2] />
</template>
<template v-else>
<FreetypingScreen :key=i :trial=trial :trial_type="'filler'" :index=i :progress="i / trials.length" :condition="'filler'" />
Expand All @@ -59,14 +59,52 @@ import FreetypingScreen from './FreetypingScreen';
var group = _.sample(['odd', 'even']);
const powerSetRecursive = (arr, prefix=[], set=[[]]) => {
if(arr.length === 0) return// Base case, end recursion
for (let i = 0; i < arr.length; i++) {
set.push(prefix.concat(arr[i]))// If a prefix comes through, concatenate value
powerSetRecursive(arr.slice(i + 1), prefix.concat(arr[i]), set)
// Call function recursively removing values at or before i and adding
// value at i to prefix
}
return set
};
const createAlternatives = (condition) => {
// split the condition to get the question and the applicable context
var questionKey = condition.split("|")[0]
var contextKey = condition.split("|")[1]
console.log(condition)
console.log(questionKey)
console.log(contextKey)
if (contextKey == "yes") {
var alternativesPowerset = [['optionA', 'optionB', 'optionC'], ['optionA'], ['optionA', 'optionB'], ['optionA', 'optionC']];
} else {
var alternativesPowerset = powerSetRecursive( _.shuffle(['optionB', 'optionC']));
}
// remove the empty set
alternativesPowerset.shift();
console.log(alternativesPowerset);
// select a random alternative set
var alternativeOrder = _.sample(alternativesPowerset);
return alternativeOrder
};
var allOptions = ['optionA', 'optionB', 'optionC'];
const n_vignettes = 6;
const n_fillers = 1;
// trials types to be used in expt (equal number of high and low prior trials)
const trial_types = _.shuffle(['question_any', 'question_any', 'question_optionA|yes', 'question_optionA|no', 'question_optionA|yes', 'question_optionA|no']);
const trial_alternatives = trial_types.map(createAlternatives);
console.log("trial_alternatives")
console.log(trial_alternatives);
// sample main trials
const selected_trials =_.sampleSize(trials, n_vignettes);
// combine trials and their types at random
const trials_w_types = _.zip(selected_trials, trial_types);
const trials_w_types = _.zip(selected_trials, trial_types, trial_alternatives);
const fillers =
group == 'odd'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
itemName: trial.itemName,
trial_type: trial_type,
correct_response: trial.correct_response,
condition: condition
condition: condition,
alternatives: trialAlternatives
}"
/>

Expand Down Expand Up @@ -40,7 +41,7 @@
import _ from 'lodash';


function createText(trial, condition, trial_type){
function createText(trial, condition, trial_type, trialAlternatives){
if (trial_type == 'filler'){
// shuffle the order of the alternatives
var itemOrder = _.shuffle(['competitor', 'sameCategory', 'otherCategory'])
Expand All @@ -56,50 +57,26 @@ function createText(trial, condition, trial_type){
return slide_text
} else {

const powerSetRecursive = (arr, prefix=[], set=[[]]) => {
if(arr.length === 0) return// Base case, end recursion

for (let i = 0; i < arr.length; i++) {
set.push(prefix.concat(arr[i]))// If a prefix comes through, concatenate value
powerSetRecursive(arr.slice(i + 1), prefix.concat(arr[i]), set)
// Call function recursively removing values at or before i and adding
// value at i to prefix
}
return set
}
var allOptions = ['optionA', 'optionB', 'optionC'];

// retrieve question corresponding to condition
var continuation = trial['continuation']
console.log(continuation)
var vignette_start = trial.context_begin
var vignette_continuation = trial.context_cont
// split the condition to get the question and the applicable context

// console.log(alternativeOrder)
// $magpie.measurements["alternatives"] = alternativeOrder;
var questionKey = condition.split("|")[0]
var contextKey = condition.split("|")[1]
var question = trial[questionKey]
console.log(condition)
console.log(questionKey)
console.log(contextKey)
if (contextKey == "yes") {
var alternativesPowerset = [['optionA', 'optionB', 'optionC'], ['optionA'], ['optionA', 'optionB'], ['optionA', 'optionC']];
} else {
var alternativesPowerset = powerSetRecursive( _.shuffle(['optionB', 'optionC']));
}
// remove the empty set
alternativesPowerset.shift();
console.log(alternativesPowerset);
// select a random alternative set
var alternativeOrder = _.sample(alternativesPowerset)
console.log(alternativeOrder)

// retrieve the alternatives in the randomized order
var context = allOptions.map(x => trial[x])
// add and before the last alternative
context.splice(-1, 1, "and ".concat(context.at(-1))).concat(".");
var context = context.join(", ").concat(".");

var available_alternatives = alternativeOrder.map(x => trial[x])
var available_alternatives = trialAlternatives.map(x => trial[x])
if (available_alternatives.length > 1) {
available_alternatives.splice(-1, 1, "and ".concat(available_alternatives.at(-1)));
}
Expand Down Expand Up @@ -137,14 +114,18 @@ export default {
condition: {
type: String,
default: undefined
},
trialAlternatives: {
type: Array,
default: undefined
}
},
methods: {
createText
},
computed: {
createScreen(){
return createText(this.trial, this.condition, this.trial_type)
return createText(this.trial, this.condition, this.trial_type, this.trialAlternatives)
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
experimentId: '23',
experimentId: '24',
serverUrl: 'https://magpie-cogsciprag.fly.dev//',
socketUrl: 'wss://magpie-cogsciprag.fly.dev//socket',
// this will be used in prolific mode
Expand Down

0 comments on commit 4cab037

Please sign in to comment.