from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'result_racism' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): oe = models.IntegerField( initial='0' ) gn = models.IntegerField( initial='0' ) prop = models.IntegerField( initial='-1' ) propr = models.IntegerField( initial='-1' ) rec = models.IntegerField( initial='-1' ) dec = models.StringField( initial='' ) amt = models.FloatField( Initial='0' ) mem = models.FloatField( Initial='-1' ) led = models.FloatField( Initial='-1' ) rn = models.IntegerField() # def final_payoff(player): # x = np.random.randint(1, 6) # print(x) # if x == 1: # player.payoff = player.participant.pt1 # elif x == 2: # player.payoff = player.participant.pt2 # elif x == 3: # player.payoff = player.participant.pt3 # elif x == 4: # player.payoff = player.participant.pt4 # elif x == 5: # player.payoff = player.participant.pt5 # elif x == 6: # player.payoff = player.participant.pt6 # PAGES class MyPage(Page): def before_next_page(player: Player, timeout_happened): x = int(random.uniform(1, 35)) # x=13 player.rn = x # print(x) if x > 0: if x < 7: player.payoff = player.participant.pt1 player.oe = player.participant.oe1 player.gn = player.participant.gn1 if player.participant.dec1 == True: player.dec = 'Football' else: player.dec = 'Ballet' if x > 6: if x < 13: player.payoff = player.participant.pt2 player.oe = player.participant.oe2 player.gn = player.participant.gn2 if player.participant.dec2 == True: player.dec = 'Cooperate' else: player.dec = 'Defect' if x > 12: if x < 19: player.payoff = player.participant.pt3 player.gn = player.participant.gn3 player.prop = player.participant.prop1 player.propr = 40-player.participant.prop1 player.rec = player.participant.rec1 if x > 18: if x < 25: player.payoff = player.participant.pt4 player.gn = player.participant.gn4 player.prop = player.participant.prop2 player.propr = 30 - player.participant.prop2 player.rec = player.participant.rec2 if x > 24: if x < 31: player.payoff = player.participant.pt5 player.oe = player.participant.oe5 player.gn = player.participant.gn5 player.amt = player.participant.dec5 if x == 31: player.payoff = player.participant.pt6 if x == 32: player.payoff = player.participant.pt7 elif x == 33: player.payoff = player.participant.pt8 player.mem = player.participant.mem1 player.led = player.participant.led1 if x == 34: player.payoff = player.participant.pt9 player.mem = player.participant.mem2 player.led = player.participant.led2 if x == 35: player.payoff = player.participant.pt9 player.mem = player.participant.mem2 player.led = player.participant.led2 class ResultsWaitPage(WaitPage): pass class Results(Page): pass # form_model = "player" # # def vars_for_template(player): # round = player.rn # state31 = False # if round == 31: # state31 = True # # decision = player.dec # receive = player.rec # proposal = player.prop # gamenum = player.gn # odd = player.oe # amount = player.amt # member = player.mem # leader = player.led # return dict( # round=round, # state31=state31, # decision=decision, # receive=receive, # proposal=proposal, # gamenum=gamenum, # odd=odd, # amount=amount, # member=member, # leader=leader # ) # # def vars_for_template(player): # return dict( # a=1, # b=2, # c=3 # ) page_sequence = [MyPage, Results]