jspsych/plugins/jspsych-rdk.js
//Function to end the trial proper

Function to end the trial proper
Function to end the trial proper
function end_trial() {
			stopDotMotion = true;
			numberOfFrames = frameRate.length;
			var frameRateArray = frameRate;
			if(frameRate.length > 0){
				frameRate = frameRate.reduce((total,current) => total + current)/frameRate.length; 
			}else{
				frameRate = 0; 
			}
			if (typeof keyboardListener !== 'undefined') {
				jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
			}
			var trial_data = { 
				"rt": response.rt, 
				"key_press": response.key, 
				"correct": correctOrNot(), 
				"choices": trial.choices, 
				"correct_choice": trial.correct_choice, 
				"trial_duration": trial.trial_duration, 
				"response_ends_trial": trial.response_ends_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, 
				"frame_rate_array": JSON.stringify(frameRateArray), 
				"number_of_frames": numberOfFrames, 
				"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
			}
			display_element.innerHTML='';
			body.style.margin = originalMargin;
			body.style.padding = originalPadding;
			body.style.backgroundColor = originalBackgroundColor
			jsPsych.finishTrial(trial_data);
		} 
function end_trial ( ) { stopDotMotion = true ; numberOfFrames = frameRate . length ; var frameRateArray = frameRate ; if ( frameRate . length > 0 ) { frameRate = frameRate . reduce ( ( total , current ) => total + current ) / frameRate . length ; } else { frameRate = 0 ; } if ( typeof keyboardListener !== 'undefined' ) { jsPsych . pluginAPI . cancelKeyboardResponse ( keyboardListener ) ; } var trial_data = { "rt" : response . rt , "key_press" : response . key , "correct" : correctOrNot ( ) , "choices" : trial . choices , "correct_choice" : trial . correct_choice , "trial_duration" : trial . trial_duration , "response_ends_trial" : trial . response_ends_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 , "frame_rate_array" : JSON . stringify ( frameRateArray ) , "number_of_frames" : numberOfFrames , "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 } display_element . innerHTML = '' ; body . style . margin = originalMargin ; body . style . padding = originalPadding ; body . style . backgroundColor = originalBackgroundColor jsPsych . finishTrial ( trial_data ) ; }
Function to end the trial proper
Function to end the trial proper
//Stop the dot motion animation
 //Store the number of frames
 //Variable to store the frame rate array
 //Calculate the average frame rate
 //Check to make sure that the array is not empty
 //Sum up all the elements in the array
 //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
 //Place all the data to be saved from this trial in one data object
 //The response time
 //The key that the subject pressed
 //If the subject response was correct
 //The set of valid keys
 //The correct choice
 //The trial duration 
 //If the response ends the trial
 //The average frame rate for the trial
 //The array of ms per frame in this trial, in the form of a JSON string
 //The number of frames in this trial
 //Remove the canvas as the child of the display_element element
 //Restore the settings to JsPsych defaults
 //End this trial and move on to the next trial
 //End of end_trial
