from otree.api import * c = cu doc = 'Provides video instructions for the earning task, with comprehension questions for additional understanding.' class C(BaseConstants): # built-in constants NAME_IN_URL = 'RET_instructions' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 # user-defined constants Q1_ANSWER = 'CQ1: The answer is TRUE. They will be presented with a series of matrices and will need to count the number of 1s.' Q2_ANSWER = 'CQ2: The answer is FALSE. They will be rewarded per matrix they complete.' Q3_ANSWER = 'CQ3: The answer is FALSE. One of you will be picked at random to complete the earnings task, while the other waits.' UW_TETON_BG_TEMPLATE = 'RET_instructions/uw_teton_bg.html' class Subsession(BaseSubsession): pass def after_all_players_arrive(subsession: Subsession): session = subsession.session # pull the matrix you stored in the code‐entry app matrix = subsession.session.vars.get('couple_matrix') if not matrix: # safety check in case someone forgot to run grouping first raise RuntimeError("No couple_matrix in session.vars") # re‐apply it in this app's subsession subsession.set_group_matrix(matrix) class Group(BaseGroup): pass def my_function(group: Group): pass class Player(BasePlayer): cq_1 = models.BooleanField(choices=[[True, 'True'], [False, 'False']], label='The person assigned to earning money will earn money by counting the number of 1s in a matrix.') cq_2 = models.BooleanField(choices=[[True, 'True'], [False, 'False']], label='The person earning money will only be rewarded if they get every matrix correct.') cq_3 = models.BooleanField(choices=[[True, 'True'], [False, 'False']], label='You and your partner will both get the opportunity to do the earnings task.') def custom_export(players): # Header yield [ 'session_code', 'participant_id_in_session', 'participant_code', 'id_in_group', 'group_number', 'RET_cq_1', 'RET_cq_2', 'RET_cq_3' ] # Rows for p in players: pp = p.participant pg = p.group ps = p.session yield [ ps.code, pp.id_in_session, pp.code, p.id_in_group, pg.id_in_subsession, p.cq_1, p.cq_2, p.cq_3 ] class GroupingWaitPage(WaitPage): wait_for_all_groups = True after_all_players_arrive = after_all_players_arrive class ExpIntro(Page): form_model = 'player' class EarnerInstructions(Page): form_model = 'player' form_fields = ['cq_1'] # vars_for_template is deprecated in favor of python-based renderers @staticmethod def vars_for_template(player: Player): session = player.session import random # Generate C.M_SIZExC.M_SIZE matrix with random 0s and 1s matrix = [[random.randint(0, 1) for _ in range(session.config['m_size'])] for _ in range(session.config['m_size'])] # Calculate the sum of all 1s in the matrix matrix_sum = sum(sum(row) for row in matrix) # Calculate max earnings from the task max_budget = session.config['x_rate'] * session.config['num_correct'] # Passing Python variables to the HTML template of the page return dict( matrix=matrix, matrix_sum=matrix_sum, max_budget = max_budget ) class CQ_2(Page): form_model = 'player' form_fields = ['cq_2'] # vars_for_template is deprecated in favor of python-based renderers @staticmethod def vars_for_template(player: Player): session = player.session import random # Generate C.M_SIZExC.M_SIZE matrix with random 0s and 1s matrix = [[random.randint(0, 1) for _ in range(session.config['m_size'])] for _ in range(session.config['m_size'])] # Calculate the sum of all 1s in the matrix matrix_sum = sum(sum(row) for row in matrix) # Calculate max earnings from the task max_budget = session.config['x_rate'] * session.config['num_correct'] # Passing Python variables to the HTML template of the page return dict( matrix=matrix, matrix_sum=matrix_sum, max_budget = max_budget ) class CQ_3(Page): form_model = 'player' form_fields = ['cq_3'] # vars_for_template is deprecated in favor of python-based renderers @staticmethod def vars_for_template(player: Player): session = player.session import random # Generate C.M_SIZExC.M_SIZE matrix with random 0s and 1s matrix = [[random.randint(0, 1) for _ in range(session.config['m_size'])] for _ in range(session.config['m_size'])] # Calculate the sum of all 1s in the matrix matrix_sum = sum(sum(row) for row in matrix) # Calculate max earnings from the task max_budget = session.config['x_rate'] * session.config['num_correct'] # Passing Python variables to the HTML template of the page return dict( matrix=matrix, matrix_sum=matrix_sum, max_budget = max_budget ) class CQ_Answers(Page): form_model = 'player' # vars_for_template is deprecated in favor of python-based renderers @staticmethod def vars_for_template(player: Player): session = player.session import random # Generate C.M_SIZExC.M_SIZE matrix with random 0s and 1s matrix = [[random.randint(0, 1) for _ in range(session.config['m_size'])] for _ in range(session.config['m_size'])] # Calculate the sum of all 1s in the matrix matrix_sum = sum(sum(row) for row in matrix) # Calculate max earnings from the task max_budget = session.config['x_rate'] * session.config['num_correct'] # Passing Python variables to the HTML template of the page return dict( matrix=matrix, matrix_sum=matrix_sum, max_budget = max_budget ) class RET_instructionsEndPage(WaitPage): wait_for_all_groups = True page_sequence = [GroupingWaitPage, ExpIntro, EarnerInstructions, CQ_2, CQ_3, CQ_Answers, RET_instructionsEndPage]