from otree.api import * doc = """ part1 """ PPG = 3 class C(BaseConstants): NAME_IN_URL = 'part1_mediation' PLAYERS_PER_GROUP = PPG NUM_ROUNDS = 1 PAYOFF_MUTUAL_H = 0 PAYOFF_MUTUAL_L = 6 PAYOFF_H_WHEN_HL = 16 PAYOFF_L_WHEN_HL = 4 PAYOFF_MEDIATOR = 10 VALIDATION = {'mypayoffhh': PAYOFF_MUTUAL_H, 'partnerpayoffll': PAYOFF_MUTUAL_L, 'mypayoffhl': PAYOFF_H_WHEN_HL, 'mypayofflh': PAYOFF_L_WHEN_HL, 'mediatorpayoff': PAYOFF_MEDIATOR, 'rounds': True, 'others': True, 'mediator': True} class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): terminal = models.IntegerField( label="Please enter the terminal number." ) mypayoffhh = models.IntegerField( label="What will be the Blue player's earnings if both players choose H?" ) partnerpayoffll = models.IntegerField( label="What will be the Green player's earnings if both players choose L?" ) mypayoffhl = models.IntegerField( label="What will be the Blue player's earnings if the Blue player chooses H and the Green player chooses L?" ) mypayofflh = models.IntegerField( label="What will be the Blue player's earnings if the Blue player chooses L and the Green player chooses H?" ) mediatorpayoff = models.IntegerField( label="What will be the Red player’s earnings?" ) rounds = models.BooleanField( label="This experiment consists of one round." ) others = models.BooleanField( label="The Blue player and the Green player can talk in the chat and choose an action." ) mediator = models.BooleanField( label="The Red player can talk in the chat but does not make a decision." ) num_clicks = models.IntegerField( initial=0 ) # PAGES class Welcome(Page): form_model = 'player' form_fields = ['terminal'] class Instructions(Page): pass #@staticmethod #def before_next_page(player: Player, timeout_happened): #participant = player.participant #participant.payoff = player.payoff class Comprehension(Page): errors = [] form_model = 'player' form_fields = ['mypayoffhh', 'partnerpayoffll', 'mypayoffhl', 'mypayofflh', 'mediatorpayoff', 'rounds', 'others', 'mediator'] @staticmethod def error_message(self, values): Comprehension.errors = [] error_messages = dict() for field_name in C.VALIDATION: if values[field_name] != C.VALIDATION[field_name]: Comprehension.errors.append(field_name) error_messages[field_name] = 'Wrong answer! Please read the instructions again.' return error_messages @staticmethod def js_vars(player): return dict( errors=Comprehension.errors ) @staticmethod def live_method(player: Player, data): player.num_clicks += 1 return {} #class Comprehension1(Page): #form_model = 'player' #form_fields = ['mypayoffhh'] #timeout_seconds = 90 #@staticmethod #def error_message(player: Player, value): #if value['mypayoffhh'] != C.PAYOFF_MUTUAL_H: #return 'Wrong answer. Please check the table again.' #class ComprehensionWaitPage(WaitPage): # wait_for_all_groups = True #pass class Feedback(Page): pass class Part1WaitPage(WaitPage): wait_for_all_groups = True page_sequence = [Welcome, Instructions, Comprehension, Feedback, Part1WaitPage]