from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'setup' PLAYERS_PER_GROUP = None NUM_ROUNDS = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): prolificID = models.StringField( label="Please enter your Prolific ID so that we can match your payment." ) consistency_prob_update = models.StringField( label="You observe a price change of -3, how do you have to update your estimate of the likelihood that the stock is in the good state?", widget=widgets.RadioSelect, choices=[["I increase the estimate.","I increase the estimate."],["I decrease the estimate.","I decrease the estimate."],["Can't be answered.","Can't be answered."]] ) consistency_payment = models.FloatField( label="Assume the correct statistical likelihood that the stock is in the good state is 70%. Which estimate would be in the range such that you earn a bonus payment?", widget=widgets.RadioSelect, choices=[[55,"55%"],[67,"67%"],[77,"77%"],[83,"83%"]] ) consistency_states = models.StringField( label="Evaluate the statement: The state of a stock does not change throughout the experiment.", widget=widgets.RadioSelect, choices=[["True","True"],["False","False"],["Can't be answered","Can't be answered"]] ) comprehension_check = models.BooleanField() pathA = models.IntegerField() # FUNCTIONS def assign_path(players): paths=random.sample([1,2,3,4,5,6], 4) return paths # PAGES class Welcome(Page): @staticmethod def is_displayed(player): if player.round_number==1: participant = player.participant paths = assign_path(player) participant.pathA = paths[0] participant.pathB = paths[1] participant.pathC = paths[2] participant.pathD = paths[3] return player.round_number==1 class ProlificID(Page): form_model = "player" form_fields = ["prolificID"] def error_message(player, values): length = values["prolificID"] if len(length) < 24 or len(length) > 24: return "Your Prolific ID consists of 24 characters." @staticmethod def is_displayed(player): return player.round_number==1 class revision(Page): form_model = "player" @staticmethod def is_displayed(player): if player.round_number == 1: player.comprehension_check = False else: prev_player = player.in_round(player.round_number - 1) player.comprehension_check = prev_player.comprehension_check player.consistency_prob_update = prev_player.consistency_prob_update player.consistency_payment = prev_player.consistency_payment player.consistency_states = prev_player.consistency_states return player.comprehension_check == False and player.round_number > 1 class Instructions(Page): form_model = "player" form_fields = ["consistency_prob_update","consistency_payment","consistency_states"] @staticmethod def is_displayed(player): if player.round_number == 1: player.comprehension_check = False else: prev_player = player.in_round(player.round_number - 1) player.comprehension_check = prev_player.comprehension_check return player.comprehension_check == False class Check(Page): form_model = "player" @staticmethod def is_displayed(player): if player.round_number == 1: player.comprehension_check = False else: prev_player = player.in_round(player.round_number - 1) player.comprehension_check = prev_player.comprehension_check if player.comprehension_check == True: prev_player = player.in_round(player.round_number - 1) player.consistency_prob_update = prev_player.consistency_prob_update player.consistency_payment = prev_player.consistency_payment player.consistency_states = prev_player.consistency_states else: if player.consistency_prob_update == "I decrease the estimate." and player.consistency_payment == 67 and player.consistency_states == "True": player.comprehension_check = True return player.consistency_prob_update == "I decrease the estimate." and player.consistency_payment == 67 and player.consistency_states == "True" class endsetup(Page): form_model = "player" @staticmethod def is_displayed(player): return player.round_number == 3 and player.comprehension_check == False @staticmethod def app_after_this_page(player, upcoming_apps): return upcoming_apps[2] page_sequence = [Welcome, ProlificID, revision, Instructions, Check, endsetup]