from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'Final_Results' players_per_group = None num_rounds = 1 Participation_Fee = 500 Multiplier_1 = 30 Multiplier_2 = 1 Rounds_in_MainGame = 5 #Change this to 12 before the actuatl game optR = [200,230,260,290,320,350,380,410] lottery = [650,650,650,650,650,50,50,50,50,50] class Subsession(BaseSubsession): info = models.BooleanField() F_Form = models.FloatField() payment1_round = models.IntegerField() def creating_session(self): import random # Payment round for DM1 is the same for all participants in the same session self.payment1_round = random.randint(1, Constants.Rounds_in_MainGame) # Payment round for DM2 is different for each participant for p in self.get_players(): p.payment2_page = random.randint(1, 2) p.payment2_problem = random.randint(1, 8) p.payment2_card = random.randint(1, 10) def get_game(self): self.info = self.session.config['info'] self.F_Form = self.session.config['F_Form'] class Group(BaseGroup): pass class Player(BasePlayer): payment2_page = models.IntegerField() payment2_problem = models.IntegerField() payment2_card = models.IntegerField() payment1 = models.IntegerField() payment2 = models.IntegerField() payoff_W = models.IntegerField() payoff_M = models.IntegerField() choice_WM = models.IntegerField() final_payment = models.IntegerField() def get_payment(self): # Payoff determination for Decision Making 1 self.payment1 = self.participant.vars['Payoff_hist'][self.subsession.payment1_round - 1] * Constants.Multiplier_1 # Payoff determination for Decision Making 2 if self.payment2_page == 1: self.choice_WM = self.participant.vars['Risk_Choices'][self.payment2_problem - 1] else: self.choice_WM = self.participant.vars['Ambiguity_Choices'][self.payment2_problem - 1] # Because the participant choose 20 Red & 20 Black cards, the lottery is the same between Page 1 and Page 2. self.payoff_W = Constants.lottery[self.payment2_card - 1] self.payoff_M = Constants.optR[self.payment2_problem - 1] self.payment2 = [self.payoff_M, self.payoff_W][self.choice_WM] self.final_payment = self.payment1 + self.payment2 + Constants.Participation_Fee