function end_trial()

in datawig-js/static/jspsych-6.1.0/plugins/jspsych-rdk.js [496:573]


		function end_trial() {
			
			//Stop the dot motion animation
			stopDotMotion = true;
			
			//Store the number of frames
			numberOfFrames = frameRate.length;
			
			//Variable to store the frame rate array
			var frameRateArray = frameRate;
			
			//Calculate the average frame rate
			if(frameRate.length > 0){//Check to make sure that the array is not empty
				frameRate = frameRate.reduce((total,current) => total + current)/frameRate.length; //Sum up all the elements in the array
			}else{
				frameRate = 0; //Set to zero if the subject presses an answer before a frame is shown (i.e. if frameRate is an empty array)
			}

			//Kill the keyboard listener if keyboardListener has been defined
			if (typeof keyboardListener !== 'undefined') {
				jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
			}

			//Place all the data to be saved from this trial in one data object
			var trial_data = { 
				"rt": response.rt, //The response time
				"key_press": response.key, //The key that the subject pressed
				"correct": correctOrNot(), //If the subject response was correct
				"choices": trial.choices, //The set of valid keys
				"correct_choice": trial.correct_choice, //The correct choice
				"trial_duration": trial.trial_duration, //The trial duration 
				"response_ends_trial": trial.response_ends_trial, //If the response ends the trial
				"number_of_apertures": trial.number_of_apertures,
				"number_of_dots": trial.number_of_dots,
				"number_of_sets": trial.number_of_sets,
				"coherent_direction": trial.coherent_direction,
				"coherence": trial.coherence,
				"opposite_coherence": trial.opposite_coherence,
				"dot_radius": trial.dot_radius,
				"dot_life": trial.dot_life,
				"move_distance": trial.move_distance,
				"aperture_width": trial.aperture_width,
				"aperture_height": trial.aperture_height,
				"dot_color": trial.dot_color,
				"background_color": trial.background_color,
				"RDK_type": trial.RDK_type,
				"aperture_type": trial.aperture_type,
				"reinsert_type": trial.reinsert_type,
				"frame_rate": frameRate, //The average frame rate for the trial
				"frame_rate_array": JSON.stringify(frameRateArray), //The array of ms per frame in this trial, in the form of a JSON string
				"number_of_frames": numberOfFrames, //The number of frames in this trial
				"aperture_center_x": trial.aperture_center_x,
				"aperture_center_y": trial.aperture_center_y,
				"fixation_cross": trial.fixation_cross,
				"fixation_cross_width": trial.fixation_cross_width,
				"fixation_cross_height": trial.fixation_cross_height,
				"fixation_cross_color": trial.fixation_cross_color,
				"fixation_cross_thickness": trial.fixation_cross_thickness,
				"border": trial.border,
				"border_thickness": trial.border_thickness,
				"border_color": trial.border_color,
				"canvas_width": canvasWidth,
				"canvas_height": canvasHeight
				
			}
			
			//Remove the canvas as the child of the display_element element
			display_element.innerHTML='';
			
			//Restore the settings to JsPsych defaults
			body.style.margin = originalMargin;
			body.style.padding = originalPadding;
			body.style.backgroundColor = originalBackgroundColor

			//End this trial and move on to the next trial
			jsPsych.finishTrial(trial_data);
			
		} //End of end_trial