#-- CUSTOM set definition file --#
# By: Chris van Run
# For: Rachida Ganga

# Note, you need to add or check if you have the following in the SDL and PCL:
# ------------
# SDL header:
# active_buttons = 3;
# button_codes = 1,2,3;
# write_codes = true;   
# stimulus_properties = description, string, question_string, string, expected_answer, string;
# event_code_delimiter = ",";

# ------------
# PCL (before present() of questiontrial.present());
# questiontrial.get_stimulus_event(1).set_event_code("Question," + questions[i_trial] + "," + string(correctresp[i_trial]));
# questiontrial.present();

# Just some good practices, be very carefull if these are counts show anything!:
unc_over_1 : time_uncertainty > 1
over1_count = count( unc_over_1 )
unc_over_5 : time_uncertainty > 5
over5_count = count( unc_over_5 )

event_table custom_etable( trial, event_type, code, description, question_string, expected_answer, time, time_uncertainty)

# Get all the events that were questions (I cheated and added a description 'Questions' to them)
questions: event_type == "Picture" and description == "Question"

# Get all the response events that where very close to the question
responses: event_type == "Response" and rel_index_range( -1, -1 ) is questions

# Filter these further to only keep the actual responses made with the button codes that are used to answer questions
answers(responses): code == "2" or code == "3"

questions_count = count( questions )
answers_count = count( answers )

# Match with a windows of response time between 100 ms and 10 seconds
pair:: simple_match_all( 100, 10000, questions, answers )

# select only those pairs who's first item (questions) expected answer matches the response of the second item of the pair (answer).
correct( pair ):: expected_answer1 == code2
incorrect( pair ):: expected_answer1 != code2

# Count both sets
correct_count = count( correct )
incorrect_count = count( incorrect )

event_pair_property correctness(correct, incorrect)
event_pair_table custom_pair_table( trial1, question_string1, expected_answer1, code2, correctness)

# If running a scenario that produces a .log file you should now also see a .txt file that contains the responses.
print custom_pair_table( pair, "\t", "\n" )
