from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'final_payoff' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): round_1 = models.IntegerField() round_2 = models.IntegerField() round_3 = models.IntegerField() main_pay = models.CurrencyField() risk_pay = models.CurrencyField() round_1_pay = models.CurrencyField() round_2_pay = models.CurrencyField() round_3_pay = models.CurrencyField() final_pound_pay = models.FloatField() def set_payoff(self): rounds_1_10 = [i for i in range(1, 11)]#11)] SET TO (1, 11) FOR FULL GAME or SET TO (1, 2) FOR SHORT TEST rounds_11_20 = [i for i in range(1, 11)]#1, 11)] SET TO (1, 11) FOR FULL GAME or SET TO (1, 2) FOR SHORT TEST rounds_21_30 = [i for i in range(1, 11)]#1, 11)] SET TO (1, 11) FOR FULL GAME or SET TO (1, 2) FOR SHORT TEST round1 = random.choice(rounds_1_10) round2 = random.choice(rounds_11_20) round3 = random.choice(rounds_21_30) self.round_1_pay =self.participant.vars['rounds_1_10'][round1-1] self.round_2_pay = self.participant.vars['rounds_11_20'][round2-1] self.round_3_pay = self.participant.vars['rounds_21_30'][round3-1] rounds_1_10.remove(round1) while self.round_1_pay==-9: if len(rounds_1_10)==0: self.round_1_pay = 0 break round1 = random.choice(rounds_1_10) rounds_1_10.remove(round1) self.round_1_pay = self.participant.vars['rounds_1_10'][round1 - 1] if self.round_1_pay==-9 and len(rounds_1_10)==0: self.round_1_pay=0 rounds_11_20.remove(round2) while self.round_2_pay==-9: if len(rounds_11_20)==0: self.round_2_pay = 0 break round2 = random.choice(rounds_11_20) rounds_11_20.remove(round2) self.round_2_pay = self.participant.vars['rounds_11_20'][round2 - 1] if self.round_2_pay==-9 and len(rounds_11_20)==0: self.round_2_pay=0 rounds_21_30.remove(round3) while self.round_3_pay==-9: if len(rounds_21_30)==0: self.round_3_pay = 0 break round3 = random.choice(rounds_21_30) rounds_21_30.remove(round3) self.round_3_pay = self.participant.vars['rounds_21_30'][round3 - 1] if self.round_3_pay==-9 and len(rounds_21_30)==0: self.round_3_pay=0 self.round_1 = round1 self.round_2 = round2 + 10 # SET TO + 10 FOR FULL GAME or SET TO + 1 FOR SHORT TEST self.round_3 = round3 + 20 # SET TO + 20 FOR FULL GAME or SET TO +2 FOR SHORT TEST self.main_pay = self.round_1_pay + self.round_2_pay + self.round_3_pay self.risk_pay = self.participant.vars['risk_pay'] self.participant.payoff=self.participant.vars['risk_pay'] + self.main_pay self.final_pound_pay = round(float(self.participant.payoff)*0.4,2) pass