scripts/experiment-properties/data/custom_subcondition_generator.js
import {EXPERIMENT_BASES, EXPERIMENT_CONDITIONS, create_condition_dataset} from "/scripts/experiment-properties/data/data_controller.js";
import {initialize_random_order} from "/scripts/experiment-properties/balancing/generators/random_generator.js";
export {CUSTOM_TRIAL_STRUCTURE_CONDITIONS, get_subconditions};
// Add condition here if it uses a non-custom trial-structure
// (e.g. foundational, design), but programatically generates
// subconditions.
var CUSTOM_TRIAL_STRUCTURE_CONDITIONS = {
foundational : [
"stable_line_length_strip",
"line_length_strip",
"strip_ring_size"
],
design : [
"distractor_diamond_square_red_hue",
"distractor_diamond_square_red_lum",
"distractor_diamond_square_red_chrom",
"distractor_diamond_square_yellow_hue",
"distractor_diamond_square_yellow_lum",
"distractor_diamond_square_yellow_chrom",
"distractor_diamond_square_blue_hue",
"distractor_diamond_square_blue_lum",
"distractor_diamond_square_blue_chrom",
"distractor_diamond_square_green_hue",
"distractor_diamond_square_green_lum",
"distractor_diamond_square_green_chrom"
]
}
/**
* Controls which helper method to access depending on condition name.
*
* @param {object} experiment
*/
function get_subconditions(experiment) {
if (is_distractor_diamond_square(experiment.condition_name)){
return generate_distractor_diamond_square_subconditions(experiment);
}
else if (experiment.condition_name === "distractor_multi"){
return generate_distractor_multi_subconditions(experiment);
}
else if (experiment.condition_name === "distractor_blue_shades" ||
experiment.condition_name === "distractor_red_shades" ||
experiment.condition_name === "distractor_yellow_shades" ||
experiment.condition_name === "distractor_control_shades"){
return generate_distractor_shades_subconditions(experiment);
}
else if (experiment.condition_name.split("_").includes("num")
&& experiment.condition_name.split("_").includes("corr")){
return generate_num_corr_subconditions(experiment);
}
else if (experiment.condition_name.split("_").includes("strip") || experiment.graph_type === "strip") {
return generate_strip_subconditions(experiment);
}
}
/**
* Checks if the condition name is a "distractor_diamond_square" one.
*
* @param {object} experiment
* @return {boolean}
*/
function is_distractor_diamond_square(condition_name) {
let array = condition_name.split("_");
if (array[0] === "distractor" && array[1] === "diamond" && array[2] === "square") {
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////////////
// GENERATORS HERE
////////////////////////////////////////////////////////////////////////////////////////
/**
* Generates subconditions for distractor_diamond_square conditions
*
* @param {object} experiment
*/
function generate_distractor_diamond_square_subconditions(experiment) {
let array = experiment.condition_name.split("_");
if (array.length !== 5) throw new Error(experiment.condition_name + " is not a valid distractor_diamond_square condition.");
let square_name = array[0] + "_" + array[2] + "_" + array[3] + "_" + array[4];
let experiment_name = experiment.constructor.name;
let trial_structure = experiment.trial_structure;
let subconditions = create_condition_dataset(EXPERIMENT_BASES[experiment_name][trial_structure], EXPERIMENT_CONDITIONS[experiment_name][square_name]);
for (let c of subconditions) {
c["dist_shape"] = "diamond";
// Overwrite to opposing colors when dist_color = white
if (c["dist_color"] === "WHITE"){
// If RED
if (c["target_color"] === "#cd4c32"){
c["dist_color"] = "#007ebc";
}
// If BLUE
else if (c["target_color"] === "#007ebc"){
c["dist_color"] = "#cd4c32";
}
// If YELLOW
else if (c["target_color"] === "#dbc667"){
c["dist_color"] = "#20874a";
}
// If GREEN
else {
c["dist_color"] = "#dbc667";
}
}
}
return subconditions;
}
/**
* Generates subconditions for distractor_multi condition.
*
* @param {object} experiment
*/
function generate_distractor_multi_subconditions(experiment) {
let condition_name = experiment.condition_name;
let experiment_name = experiment.constructor.name;
let subconditions = EXPERIMENT_CONDITIONS[experiment_name][condition_name];
// Using the first 12 subconditions from the JND design:
let jnd_base_subconditions = EXPERIMENT_BASES[experiment_name]["design"].slice(1,13);
let dataset = create_condition_dataset(jnd_base_subconditions, subconditions);
let result = []
// Doing each set 4 times
for (let i = 0; i < 4; i++) {
result = result.concat(dataset);
}
return result;
}
/**
* Generates subconditions for distractor_shade conditions.
*
* @param {object} experiment
*/
function generate_distractor_shades_subconditions(experiment) {
let condition_name = experiment.condition_name;
let experiment_name = experiment.constructor.name;
let subconditions = EXPERIMENT_CONDITIONS[experiment_name][condition_name];
// Using the first 12 subconditions from the JND design:
if (experiment_name === "JND"){
let jnd_base_subconditions = EXPERIMENT_BASES["JND"]["design"].slice(1,13);
let dataset = create_condition_dataset(jnd_base_subconditions, subconditions);
return dataset;
} else {
let stevens_base_subconditions = EXPERIMENT_BASES["Stevens"]["design"].slice(1,5);
let dataset = create_condition_dataset(stevens_base_subconditions, subconditions);
return dataset;
}
}
/**
* Generates subconditions for numerosity-correlation conditions.
*
* @param {object} experiment
*/
function generate_num_corr_subconditions(experiment) {
// Get the distractor_ratio_pilot subconditions
let jnd_design_base = EXPERIMENT_BASES[experiment.constructor.name]["design"];
let dist_ratio_pilot_subcond = EXPERIMENT_CONDITIONS[experiment.constructor.name]["distractor_ratio_pilot"];
let subconditions = create_condition_dataset(jnd_design_base, dist_ratio_pilot_subcond);
let base_set = subconditions.slice(0,3); // Getting the 0.3, 0.6, 0.9 assoc arrays
let BASE_NUMBER = [50, 100, 150];
let CORR_REF_START = [0.2, 0.5, 0.8];
let NUMERO_REF_START = [40, 90, 140];
let TASKS = ["correlation", "numerosity"];
let INITIAL_DIFFERENCE = {"correlation": 0.1, "numerosity": 10};
let NUM_INSTRUCTIONS = `<div align = 'center'>
<font size = 10>
Which has <b>more points</b>?
<br>
<br>
The <font color = 'RED'>target</font> population on your right or left?
</font>
</div>`;
let CORR_INSTRUCTIONS = `<div align = 'center'>
<font size = 10>
Which is <b>more correlated</b>?
<br>
<br>
The <font color = 'RED'>target</font> population on your right or left?
</font>
</div>`;
let result = [];
for (let task of TASKS) {
for (let base_num of BASE_NUMBER) {
for (let i = 0; i < base_set.length; i++) {
let subcondition = Object.assign({}, base_set[i]);
subcondition.num_points = base_num;
subcondition.task = task;
subcondition.target_color = '#cd4c32'; // RED
subcondition.point_color = '#cd4c32';
if (subcondition.task === "correlation") {
subcondition.reference_start = CORR_REF_START[i];
subcondition.initial_difference = INITIAL_DIFFERENCE["correlation"];
subcondition.subcondition_instructions = CORR_INSTRUCTIONS;
} else {
subcondition.reference_start = NUMERO_REF_START[i];
subcondition.initial_difference = INITIAL_DIFFERENCE["numerosity"];
subcondition.subcondition_instructions = NUM_INSTRUCTIONS;
}
if (experiment.condition_name.split("_").includes("distractor")){
subcondition.dist_num_points = 100;
subcondition.dist_color = '#20874a'; // GREEN
}
result.push(subcondition);
}
}
}
return result;
}
/**
* Removes unnecessary graphical attributes point_color and point_size from strip conditions.
*
* @param {object} experiment
*/
function generate_strip_subconditions(experiment) {
let subconditions = [];
if (experiment.condition_name === "base") {
subconditions = EXPERIMENT_BASES[experiment.constructor.name][experiment.trial_structure];
} else {
subconditions = EXPERIMENT_CONDITIONS[experiment.constructor.name][experiment.condition_name];
subconditions = create_condition_dataset(EXPERIMENT_BASES[experiment.constructor.name][experiment.trial_structure], subconditions);
}
for (let s of subconditions) {
delete s.point_color;
delete s.point_size;
}
return subconditions;
}