from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'irf' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'my_dictator' players_per_group = 2 num_rounds = 1 endowment = c(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): winner_amountA = models.IntegerField(label='How much should the winner of the first task receive?') winner_amountB = models.IntegerField(label='How much should the winner of the last task receive?') winner_differenceA = models.IntegerField(initial=0) winner_differenceB = models.IntegerField(initial=0) # numList = [] # for i in range(10): # x = random.range(20) # numList.append(x) # def set_numbers(self): # players = self.get_players() # for p in players: # p.pNumList = self.numList # for i in p.pNumList: # print(i) def set_payoffs1(self): print(self.winner_amountA) players = self.get_players() for p in players: p.is_correctA() if players[0].num_correctA > players[1].num_correctA: print(players[0].winnings) print(self.winner_amountA) players[0].is_winnerA = True players[0].winnings += self.winner_amountA players[1].winnings += 100 - self.winner_amountA elif players[0].num_correctA == players[1].num_correctA: players[0].winnings += 50 players[1].winnings += 50 else: print(players[1].id_in_group) players[1].is_winnerA = True players[1].winnings += self.winner_amountA players[0].winnings += 100 - self.winner_amountA self.winner_differenceA = abs(players[0].num_correctA - players[1].num_correctA) def set_payoffs2(self): players = self.get_players() for p in players: p.is_correctB() #print(p.id_in_group) if players[0].num_correctB > players[1].num_correctB: # print(players[0].name) players[0].is_winnerB = True players[0].winnings += self.winner_amountB players[1].winnings += 100 - self.winner_amountB elif players[0].num_correctB == players[1].num_correctB: players[0].winnings += 50 players[1].winnings += 50 else: #print(players[1].name) players[1].is_winnerB = True players[1].winnings += self.winner_amountB players[0].winnings += 100 - self.winner_amountB self.winner_differenceB = abs(players[0].num_correctB - players[1].num_correctB) class Player(BasePlayer): # pNumList = [] winnings = models.CurrencyField(initial=0) is_winnerA = models.BooleanField(initial=False) is_winnerB = models.BooleanField(initial=False) num_correctA = models.IntegerField(initial=0) num_correctB = models.IntegerField(initial=0) q1a = models.IntegerField(label='What is 17*9') q2a = models.IntegerField(label='What is 16*4') q3a = models.IntegerField(label='What is 13*12') q4a = models.IntegerField(label='What is 18*9') q5a = models.IntegerField(label='What is 12*14') q6a = models.IntegerField(label='What is 15*6') q7a = models.IntegerField(label='What is 70 - 15?') q1b = models.IntegerField(label='What is 21*12') q2b = models.IntegerField(label='What is 7*23') q3b = models.IntegerField(label='What is 14*3') q4b = models.IntegerField(label='What is 25*7') q5b = models.IntegerField(label='What is 19*12') q6b = models.IntegerField(label='What is 6*14') q7b = models.IntegerField(label='What is 40 - 15?') # x = random.randrange(20) #y = random.randrange(20) #testx = models.IntegerField(initial= x) #testy = models.IntegerField(initial= y) # string = 'What is {} * {}?'.format(testx, testy) #q8a = models.StringField(label='What is {} * {}?'.format(x, y)) name = models.StringField(label='What is your name?', blank=True) gender = models.BooleanField(label = 'What is your gender', choices =[[True, 'Female'], [False, 'Male']], widget = widgets.RadioSelectHorizontal, blank = True) politics = models.IntegerField(label='From Left to Right, what is your political learning?', choices=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], widget=widgets.RadioSelectHorizontal, blank=True) gameTheory = models.BooleanField(label='Have you ever taken a course in Game Theory?', choices=[[True, 'Yes'], [False, 'No']], widget=widgets.RadioSelectHorizontal, blank=True) education = models.IntegerField(label='What is your highest completed level of education?', choices=[[1, 'GED equivalent/HS'], [2, 'Undergrad'], [3, 'Masters'], [4, 'PhD']], widget=widgets.RadioSelect, blank=True) talent = models.IntegerField(label='On as scale of 1-10, indicate how important you think talent should be in determining your wealth') luck = models.IntegerField(label='On as scale of 1-10, indicate how important you think luck should be in determining your wealth') hardWork = models.IntegerField(label='On as scale of 1-10, indicate how important you think hard work should be in determining your wealth') nash = models.BooleanField(label='Does this game have a (mixed or pure) strategy Nash equilibrium?', choices=[[True, 'Yes'], [False, 'No']], widget=widgets.RadioSelectHorizontal, blank=True) def is_correctA(self): if self.q1a == 153: self.num_correctA += 1 if self.q2a == 64: self.num_correctA += 1 if self.q3a == 156: self.num_correctA += 1 if self.q4a == 162: self.num_correctA += 1 if self.q5a == 168: self.num_correctA += 1 if self.q6a == 90: self.num_correctA += 1 if self.q7a == 55: self.num_correctA += 1 def is_correctB(self): if self.q1b == 252: self.num_correctB += 1 if self.q2b == 161: self.num_correctB += 1 if self.q3b == 42: self.num_correctB += 1 if self.q4b == 175: self.num_correctB += 1 if self.q5b == 228: self.num_correctB += 1 if self.q6b == 84: self.num_correctB += 1 if self.q7b == 25: self.num_correctB += 1 pass