from otree.api import * # global variables # wrong_num = [] # wrong_round = [] class C(BaseConstants): NAME_IN_URL = 'Understanding_test' PLAYERS_PER_GROUP = None NUM_ROUNDS = 3 INSTRUCTIONCONTROL_TEMPLATE = 'survey/instructionControl.html' INSTRUCTIONEXPERIMENT_TEMPLATE = 'survey/instructionExperiment.html' # game with 3 options PAYOFF_A11_2, PAYOFF_A12_2, PAYOFF_A13_2, PAYOFF_A21_2, PAYOFF_A22_2, PAYOFF_A23_2, PAYOFF_A31_2, PAYOFF_A32_2, PAYOFF_A33_2 = 30, 20, 0, 40, 44, 20, 60, 50, 70 PAYOFF_B11_2, PAYOFF_B12_2, PAYOFF_B13_2, PAYOFF_B21_2, PAYOFF_B22_2, PAYOFF_B23_2, PAYOFF_B31_2, PAYOFF_B32_2, PAYOFF_B33_2 = 15, 20, 40, 0, 60, 40, 66, 20, 33 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): yourID = models.StringField( label='1. Please fill in your Prolific ID.', blank=True ) yourPay = models.StringField( choices=[['Right', 'The right one'], ['Left', 'the left one']], label='2. Which number in each cell represents your potential payoff?', widget=widgets.RadioSelect, ) decideCell = models.BooleanField( choices=[[True, 'Yes'], [False, 'No']], label='3. You can select a cell directly.', widget=widgets.RadioSelect, ) yourChoice = models.StringField( choices=[['row1', 'The row on the top'], ['row2', 'The row in the middle'], ['row3', 'The row on the bottom']], label="4. Which row will be selected if you click the button 'I will choose Option II'? ", widget=widgets.RadioSelect, ) selectPoint = models.IntegerField( choices=[[1, str(C.PAYOFF_A31_2)], [2, str(C.PAYOFF_A13_2)], [3, str(C.PAYOFF_B13_2)], [4, str(C.PAYOFF_B31_2)]], label='5. If you choose Option III, and the computer choose option i, how many points will you get?', widget=widgets.RadioSelect, ) selectPay = models.IntegerField( choices=[[1, str(C.PAYOFF_A31_2)], [2, str(C.PAYOFF_A13_2/5)], [3, str(C.PAYOFF_A31_2/50)], [4, str(C.PAYOFF_B31_2/50)]], label='6. If this round is selected, how many pounds will you earn?', widget=widgets.RadioSelect, ) tryAgain = models.IntegerField( choices=[[1, 'Continue'], [2, 'Try Again'], [3, 'End']], label='Have another chance or not.', widget=widgets.RadioSelect ) # continueExperiment = models.IntegerField( # choices=[[1, 'Continue'], [2, 'Exit']], # label='I agree this document and want to continue', # widget=widgets.RadioSelect, # ) readUnderstand = models.IntegerField( choices=[[1, 'I have read and understood the conditions outlined above.\n' 'I consent to participate in the study and agree to the collection, storage, and use of my data as\ described above.'], [2, 'I dont agree to the collection, storage, and use of my data as described above. I decide to leave.']], label='', widget=widgets.RadioSelect, ) # allright = models.IntegerField # FUNCTIONS # PAGES class Introduction(Page): group = models.IntegerField def vars_for_template(player:Player): if player.session.config['name'] == 'strategy_Learning': Introduction.group = 1 else: Introduction.group = 2 # print(Introduction.group) return {'group': Introduction.group == 1} class InfCons(Page): form_model = 'player' form_fields = ['readUnderstand'] @staticmethod def app_after_this_page(player:Player, upcoming_apps): if player.readUnderstand == 2: return upcoming_apps[-1] class Understand(Page): form_model = 'player' form_fields = ['yourID','yourPay', 'decideCell', 'yourChoice', 'selectPoint', 'selectPay'] def vars_for_template(player:Player): return { 'payoffA11': C.PAYOFF_A11_2, 'payoffA12': C.PAYOFF_A12_2, 'payoffA13': C.PAYOFF_A13_2, 'payoffB11': C.PAYOFF_B11_2, 'payoffB12': C.PAYOFF_B12_2, 'payoffB13': C.PAYOFF_B13_2, 'payoffA21': C.PAYOFF_A21_2, 'payoffA22': C.PAYOFF_A22_2, 'payoffA23': C.PAYOFF_A23_2, 'payoffB21': C.PAYOFF_B21_2, 'payoffB22': C.PAYOFF_B22_2, 'payoffB23': C.PAYOFF_B23_2, 'payoffA31': C.PAYOFF_A31_2, 'payoffA32': C.PAYOFF_A32_2, 'payoffA33': C.PAYOFF_A33_2, 'payoffB31': C.PAYOFF_B31_2, 'payoffB32': C.PAYOFF_B32_2, 'payoffB33': C.PAYOFF_B33_2, } class TestResult(Page): form_model = 'player' form_fields = ['tryAgain'] allright = models.IntegerField @staticmethod def vars_for_template(player: Player): wrong_num = 0 wrong_round = [] if player.yourPay != 'Left': wrong_num += 1 wrong_round.append(2) if player.decideCell: wrong_num += 1 wrong_round.append(3) if player.yourChoice != 'row2': wrong_num += 1 wrong_round.append(4) if player.selectPoint != 1: wrong_num += 1 wrong_round.append(5) if player.selectPay != 3: wrong_num += 1 wrong_round.append(6) if wrong_num == 0: TestResult.allright = 1 elif player.round_number == 3: TestResult.allright = 3 else: TestResult.allright = 2 return { 'wrong_num': wrong_num, 'wrong_round': wrong_round, 'allright': TestResult.allright } def app_after_this_page(player:Player, upcoming_apps): if player.tryAgain == 1: return upcoming_apps[0] if player.tryAgain == 3: return upcoming_apps[-1] page_sequence = [Introduction, InfCons, Understand, TestResult]