from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'demo_worker' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): pay_round = models.IntegerField() consent_choice = models.StringField( label="", choices=["Consent", "Do not consent"], widget=widgets.RadioSelect ) consent_choice2 = models.StringField( blank=True, label="", choices=["Leave"], widget=widgets.RadioSelect ) prolific_id = models.StringField(label="What is your Prolific ID?") htown = models.StringField( label="Where is your hometown?" ) hgpa = models.IntegerField( label="How many AP and/or GI classes you took in high school?", min=0 ) hsoc = models.IntegerField( label="How many involvement/extra curricular activities you had in high school?" ) msword = models.IntegerField() adobeill = models.IntegerField() comps = models.IntegerField() compc = models.IntegerField() ans1 = models.IntegerField( blank=True, choices=[[1, "17"], [2, "19"], [3, "21"], [4, "29"]], widget=widgets.RadioSelect, label=" " ) ans2 = models.IntegerField( blank=True, choices=[[1, "32124"], [2, "34218"], [3, "35614"], [4, "37652"]], widget=widgets.RadioSelect, label=" " ) ans3 = models.IntegerField( blank=True, choices=[[1, "965"], [2, "975"], [3, "6515"], [4, "6525"]], widget=widgets.RadioSelect, label=" " ) ans4 = models.IntegerField( blank=True, choices=[[1, "x > -5"], [2, "x > -6"], [3, "x < -5"], [4, "x < -6"]], widget=widgets.RadioSelect, label=" " ) ans5 = models.IntegerField( blank=True, choices=[[1, "73"], [2, "79"], [3, "83"], [4, "87"]], widget=widgets.RadioSelect, label=" " ) ans6 = models.IntegerField( blank=True, choices=[[1, "2"], [2, "-2"], [3, "13"], [4, "-13"]], widget=widgets.RadioSelect, label=" " ) ans7 = models.IntegerField( blank=True, choices=[[1, "-18"], [2, "-16"], [3, "-14"], [4, "-12"]], widget=widgets.RadioSelect, label=" " ) ans8 = models.IntegerField( blank=True, choices=[[1, "3"], [2, "4"], [3, "6"], [4, "8"]], widget=widgets.RadioSelect, label=" " ) ans9 = models.IntegerField( blank=True, choices=[[1, "610.5"], [2, "612"], [3, "612.5"], [4, "613"]], widget=widgets.RadioSelect, label=" " ) ans10 = models.IntegerField( blank=True, choices=[[1, "20"], [2, "18"], [3, "16"], [4, "14"]], widget=widgets.RadioSelect, label=" " ) corr = models.IntegerField( initial='0' ) a1 = models.IntegerField() a2 = models.IntegerField() a3 = models.IntegerField() a4 = models.IntegerField() a5 = models.IntegerField() a6 = models.IntegerField() a7 = models.IntegerField() a8 = models.IntegerField() a9 = models.IntegerField() a10 = models.IntegerField() a11 = models.IntegerField() comb = models.IntegerField( label='When do you want to stop? Please choose between 0 and 10 seconds.', min=0, max=10 ) # PAGES class Consent(Page): pass class Consent2(Page): pass class Consent3(Page): form_model = "player" form_fields = ["consent_choice"] class EndNowC(Page): @staticmethod def is_displayed(player): return player.consent_choice == 'Do not consent' class ProlificID(Page): form_model = "player" form_fields = ["prolific_id"] class Inst(Page): form_model = "player" form_fields = ["consent_choice2"] class EndNowD(Page): @staticmethod def is_displayed(player): return player.field_maybe_none('consent_choice2') == 'Leave' class MyPage(Page): form_model = 'player' form_fields = ['htown', 'hgpa', 'hsoc','msword','adobeill'] class MathInst(Page): pass # @staticmethod # def before_next_page(player, timeout_happened): # participant = player.participant # import time # # # remember to add 'expiry' to PARTICIPANT_FIELDS. # participant.expiry = time.time() + 1*150 # # # def get_timeout_seconds(player): # participant = player.participant # import time # return participant.expiry - time.time() class Q1(Page): form_model = 'player' form_fields = ['ans1'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans1') == 2: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=1 ) class Q2(Page): form_model = 'player' form_fields = ['ans2'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans2') == 2: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=2 ) class Q3(Page): form_model = 'player' form_fields = ['ans3'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans3') == 4: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=3 ) class Q4(Page): form_model = 'player' form_fields = ['ans4'] timer_text = 'Time left to complete this section:' # get_timeout_seconds = get_timeout_seconds timeout_seconds = 15 # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans4') == 4: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=4 ) class Q5(Page): form_model = 'player' form_fields = ['ans5'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans5') == 4: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=5 ) class Q6(Page): form_model = 'player' form_fields = ['ans6'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans6') == 2: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=6 ) class Q7(Page): form_model = 'player' form_fields = ['ans7'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans7') == 1: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=7 ) class Q8(Page): form_model = 'player' form_fields = ['ans8'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans8') == 3: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=8 ) class Q9(Page): form_model = 'player' form_fields = ['ans9'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans9') == 3: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=9 ) class Q10(Page): form_model = 'player' form_fields = ['ans10'] timer_text = 'Time left to complete this section:' timeout_seconds = 15 # get_timeout_seconds = get_timeout_seconds # # @staticmethod # def is_displayed(player): # return get_timeout_seconds(player) > 1 @staticmethod def before_next_page(player, timeout_happened): if player.field_maybe_none('ans10') == 4: player.corr = player.corr + 1 def vars_for_template(player: Player): return dict( n0=10 ) class Intev1(Page): pass # def vars_for_template(player: Player): # if get_timeout_seconds(player) < 0.1: # txt='Time ran out!' # else: # txt='' # return dict( # txterr=txt # ) class SocInst1(Page): pass class SocInst2(Page): form_model = 'player' form_fields = ['comps'] @staticmethod def error_message(player, values): # print('values is', values) if values['comps'] != 3: return 'Please try again.' class SOC(Page): form_model = 'player' form_fields = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'a10', 'a11'] @staticmethod def is_displayed(player): return player.comps == 3 class EndNow(Page): @staticmethod def is_displayed(player): return player.comps != 3 class Intev2(Page): pass class CombInst1(Page): pass class CombInst2(Page): form_model = 'player' form_fields = ['compc'] @staticmethod def error_message(player, values): if values['compc'] != 3: return 'Please try again.' class Comb(Page): form_model = 'player' form_fields = ['comb'] @staticmethod def is_displayed(player): return player.compc == 3 class EndNow2(Page): @staticmethod def is_displayed(player): return player.compc != 3 class Intev3(Page): form_model = 'player' def before_next_page(player: Player, timeout_happened): x = int(random.uniform(1, 4)) # x=1 player.pay_round = x if x == 1: player.payoff = player.corr elif x == 4: player.payoff = player.corr elif x == 2: player.payoff = 0 elif x == 3: player.payoff = 0 class Result(Page): form_model = 'player' page_sequence = [Consent, Consent2, Consent3, EndNowC, ProlificID, Inst, EndNowD, MyPage, MathInst, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Intev1, SocInst1, SocInst2, SOC, EndNow, Intev2, CombInst1, CombInst2, Comb, EndNow2, Intev3, Result] # page_sequence=[CombInst2, Comb] # page_sequence = [MathInst, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Intev1, # SocInst1, SocInst2, SOC, EndNow, Intev2, CombInst1, CombInst2, Comb, EndNow2, Intev3, Result]