from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Welcome(Page): pass class Instructions(Page): pass class Comprehension(Page): form_model = 'player' form_fields = ['Comprehension1', 'Comprehension2'] #def before_next_page(player): # 'set_cq' class BinaryChoice(Page): form_model = 'player' form_fields = ['BC1'] def is_displayed(self): #if player.Comprehension1== False and player.Comprehension2== True: # return True return self.player.Comprehension1== True and self.player.Comprehension2== False # return player.cq == True class BinaryChoice2(Page): form_model = 'player' form_fields = ['BC2'] def is_displayed(self): # if player.Comprehension1== False and player.Comprehension2== True: # return True return self.player.Comprehension1 == True and self.player.Comprehension2 == False class BinaryChoice3(Page): form_model = 'player' form_fields = ['BC3'] def is_displayed(self): # if player.Comprehension1== False and player.Comprehension2== True: # return True return self.player.Comprehension1 == True and self.player.Comprehension2 == False class PriceList(Page): form_model = 'player' form_fields = ['PL1', 'PL2', 'PL3', 'PL4', 'PL5', 'PL6', 'PL7', 'PL8', 'PL9', 'PL10','PL11'] def is_displayed(self): #if player.Comprehension1== False and player.Comprehension2== True: # return True return self.player.Comprehension1== True and self.player.Comprehension2== False class Payoff(Page): #calculate payoffs, a bit complicated could probably be easier solfed with loops but did not have time to tidy def before_next_page(self): self.player.payoff = Constants.participation_fee #self.player.set_payoff() import random sl1 = random.choices([1,2,3,4]) self.player.sl1 = sl1[0] sl2 = random.choices([1,2,3,4,5,6,7,8,9,10,11]) self.player.sl2 = sl2[0] if self.player.Comprehension1 == True and self.player.Comprehension2 == False: if sl1[0] == 1: if self.player.BC1 == 1: self.player.payoff = Constants.participation_fee + c(5) elif self.player.BC1 == 2: sl3 = random.choices([0, 10]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee+ c(sl3[0]) elif sl1[0] == 2: if self.player.BC2 == 1: self.player.payoff = Constants.participation_fee+ c(5) elif self.player.BC2 == 2: sl3 = random.choices([0, 10], [0.25, 0.75]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee+ c(sl3[0]) elif sl1[0] == 3: if self.player.BC3 == 1: self.player.payoff = Constants.participation_fee + c(5) elif self.player.BC3 == 2: sl3 = random.choices([0, 10], [0.75, 0.25]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl1[0] == 4: if sl2[0] == 1: if self.player.PL1 == 2: self.player.payoff = Constants.participation_fee + c(0) elif self.player.PL1 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 2: if self.player.PL2 == 2: self.player.payoff = Constants.participation_fee + c(1) elif self.player.PL2 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 3: if self.player.PL3 == 2: self.player.payoff = Constants.participation_fee + c(2) elif self.player.PL3 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 4: if self.player.PL4 == 2: self.player.payoff = Constants.participation_fee + c(3) elif self.player.PL4 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 5: if self.player.PL5 == 2: self.player.payoff = Constants.participation_fee + c(4) elif self.player.PL5 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 6: if self.player.PL6 == 2: self.player.payoff = Constants.participation_fee + c(5) elif self.player.PL6 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 7: if self.player.PL7 == 2: self.player.payoff = Constants.participation_fee + c(6) elif self.player.PL7 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 8: if self.player.PL8 == 2: self.player.payoff = Constants.participation_fee + c(7) elif self.player.PL8 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 9: if self.player.PL9 == 2: self.player.payoff = Constants.participation_fee + c(8) elif self.player.PL9 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 10: if self.player.PL10 == 2: self.player.payoff = Constants.participation_fee + c(9) elif self.player.PL10 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = c(sl3[0]) self.player.payoff = Constants.participation_fee + c(sl3[0]) elif sl2[0] == 11: if self.player.PL11 == 2: self.player.payoff = Constants.participation_fee + c(10) elif self.player.PL11 == 1: sl3 = random.choices([5, 10], [0.3, 0.7]) self.player.sl3 = sl3[0] self.player.payoff = Constants.participation_fee + c(sl3[0]) else: self.player.payoff = Constants.participation_fee class Results(Page): pass page_sequence = [Welcome, Instructions, Comprehension, BinaryChoice, BinaryChoice2, BinaryChoice3, PriceList, Payoff, Results]