<commit_before>/*
 * Requires:
 *     psiturk.js
 *     utils.js
 */

// Initalize psiturk object
var psiTurk = PsiTurk();

// All pages to be loaded
var pages = [
	"instruct.html",
	"test.html",
	"postquestionnaire.html"
];

psiTurk.preloadPages(pages);



// Stimuli for a basic Stroop experiment
var stims = [
	["SHIP", "red", "unrelated"],
	["MONKEY", "green", "unrelated"],
	["ZAMBONI", "blue", "unrelated"],
	["RED", "red", "congruent"],
	["GREEN", "green", "congruent"],
	["BLUE", "blue", "congruent"],
	["GREEN", "red", "incongruent"],
	["BLUE", "green", "incongruent"],
	["RED", "blue", "incongruent"]
	];
_.shuffle(stims);

// Task object to keep track of the current phase
var currentview;


/********************
* HTML manipulation
*
* All HTML files in the templates directory are requested 
* from the server when the PsiTurk object is created above. We
* need code to get those pages from the PsiTurk object and 
* insert them into the document.
*
********************/


/*************************
* INSTRUCTIONS         
*************************/

var Instructions = function(pages) {
	var currentscreen = 0,
	    timestamp;
	    instruction_pages = pages; 
	
	var next = function() {
		psiTurk.showPage(instruction_pages[currentscreen]);
		$('.continue').click(function() {
			buttonPress();
		});
		
		currentscreen = currentscreen + 1;

		// Record the time that an instructions page is presented
		timestamp = new Date().getTime();
	};

	var buttonPress = function() {

		// Record the response time
		var rt = (new Date().getTime()) - timestamp;
		psiTurk.recordTrialData(["INSTRUCTIONS", currentscreen, rt]);

		if (currentscreen == instruction_pages.length) {
			finish();
		} else {
			next();
		}

	};

	var finish = function() {
		// Record that the user has finished the instructions and 
		// moved on to the experiment. This changes their status code
		// in the database.
		//psiTurk.finishInstructions();

		// Move on to the experiment 
		currentview = new TestPhase();
	};

	next();
};



/********************
* STROOP TEST       *
********************/

var TestPhase = function() {

	var wordon, // time word is presented
	    listening = false,
	    resp_prompt = '<p id="prompt">Type<br> "R" for Red<br>"B" for blue<br>"G" for green.';
	
	var next = function() {
		if (stims.length===0) {
			finish();
		}
		else {
			stim = stims.shift();
			show_word( stim[0], stim[1] );
			wordon = new Date().getTime();
			listening = true;
			$('#query').html(resp_prompt).show();
		}
	};
	
	var response_handler = function(e) {
		if (!listening) return;

		var keyCode = e.keyCode,
			response;

		switch (keyCode) {
			case 82:
				// "R"
				response="red";
				break;
			case 71:
				// "G"
				response="green";
				break;
			case 66:
				// "B"
				response="blue";
				break;
			default:
				response = "";
				break;
		}
		if (response.length>0) {
			listening = false;
			var hit = response == stim[1];
			var rt = new Date().getTime() - wordon;

			psiTurk.recordTrialData(["TEST", stim[0], stim[1], stim[2], response, hit, rt]);
			
			remove_word();
			next();
		}
	};

	var finish = function() {
		$("body").keydown(function() {}); // Unbind keys
		currentview = new Questionnaire();
	};
	
	
	// Load the test.html snippet into the body of the page
	psiTurk.showPage('test.html');
	
	// This uses the Raphael library to create the stimulus. Note that when
	// this is created the first argument is the id of an element in the<commit_msg>Fix keydown unbinding in example<commit_after>/*
 * Requires:
 *     psiturk.js
 *     utils.js
 */

// Initalize psiturk object
var psiTurk = PsiTurk();

// All pages to be loaded
var pages = [
	"instruct.html",
	"test.html",
	"postquestionnaire.html"
];

psiTurk.preloadPages(pages);



// Stimuli for a basic Stroop experiment
var stims = [
	["SHIP", "red", "unrelated"],
	["MONKEY", "green", "unrelated"],
	["ZAMBONI", "blue", "unrelated"],
	["RED", "red", "congruent"],
	["GREEN", "green", "congruent"],
	["BLUE", "blue", "congruent"],
	["GREEN", "red", "incongruent"],
	["BLUE", "green", "incongruent"],
	["RED", "blue", "incongruent"]
	];
_.shuffle(stims);

// Task object to keep track of the current phase
var currentview;


/********************
* HTML manipulation
*
* All HTML files in the templates directory are requested 
* from the server when the PsiTurk object is created above. We
* need code to get those pages from the PsiTurk object and 
* insert them into the document.
*
********************/


/*************************
* INSTRUCTIONS         
*************************/

var Instructions = function(pages) {
	var currentscreen = 0,
	    timestamp;
	    instruction_pages = pages; 
	
	var next = function() {
		psiTurk.showPage(instruction_pages[currentscreen]);
		$('.continue').click(function() {
			buttonPress();
		});
		
		currentscreen = currentscreen + 1;

		// Record the time that an instructions page is presented
		timestamp = new Date().getTime();
	};

	var buttonPress = function() {

		// Record the response time
		var rt = (new Date().getTime()) - timestamp;
		psiTurk.recordTrialData(["INSTRUCTIONS", currentscreen, rt]);

		if (currentscreen == instruction_pages.length) {
			finish();
		} else {
			next();
		}

	};

	var finish = function() {
		// Record that the user has finished the instructions and 
		// moved on to the experiment. This changes their status code
		// in the database.
		//psiTurk.finishInstructions();

		// Move on to the experiment 
		currentview = new TestPhase();
	};

	next();
};



/********************
* STROOP TEST       *
********************/

var TestPhase = function() {

	var wordon, // time word is presented
	    listening = false,
	    resp_prompt = '<p id="prompt">Type<br> "R" for Red<br>"B" for blue<br>"G" for green.';
	
	var next = function() {
		if (stims.length===0) {
			finish();
		}
		else {
			stim = stims.shift();
			show_word( stim[0], stim[1] );
			wordon = new Date().getTime();
			listening = true;
			$('#query').html(resp_prompt).show();
		}
	};
	
	var response_handler = function(e) {
		if (!listening) return;

		var keyCode = e.keyCode,
			response;

		switch (keyCode) {
			case 82:
				// "R"
				response="red";
				break;
			case 71:
				// "G"
				response="green";
				break;
			case 66:
				// "B"
				response="blue";
				break;
			default:
				response = "";
				break;
		}
		if (response.length>0) {
			listening = false;
			var hit = response == stim[1];
			var rt = new Date().getTime() - wordon;

			psiTurk.recordTrialData(["TEST", stim[0], stim[1], stim[2], response, hit, rt]);
			
			remove_word();
			next();
		}
	};

	var finish = function() {
		$("body").unbind("keydown", response_handler); // Unbind keys
		currentview = new Questionnaire();
	};
	
	
	// Load the test.html snippet into the body of the page
	psiTurk.showPage('test.html');
	
	// This uses the Raphael library to create the stimulus. Note that when
	// this is created the first argument is the id of an element in the
{'fraction_non_alphanumeric': 0.1857837528604119, 'fraction_numerical': 0.004576659038901602, 'mean_word_length': 3.271838729383018, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1190810', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2233, 'n_words': 668}