from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Franziska Heinicke' doc = """ The main task of the exogenous/endogenous luck and lying experiment. """ class Constants(BaseConstants): name_in_url = 'eel_main' players_per_group = None num_rounds = 3 fix_control = c(20) high_coin = c(80) low_coin = c(20) instructions_control = 'luck_main/Instruction_control.html' instructions_endo = 'luck_main/Instruction_endo.html' instructions_exo = 'luck_main/Instruction_exo.html' class Subsession(BaseSubsession): def creating_session(self): for player in self.get_players(): player.coin_outcome = random.choice([True, False]) ##True==Head if self.round_number == 1: for player in self.get_players(): #player.participant.vars['treatment'] = self.session.config['treatment'] player.participant.vars['paying_round'] = random.randint(1, Constants.num_rounds) player.paying_round = player.participant.vars['paying_round'] #player.participant.vars['performance'] = 7 ##Change when joining with other app. else: for player in self.get_players(): player.paying_round = player.participant.vars['paying_round'] class Group(BaseGroup): pass class Player(BasePlayer): winning_side = models.BooleanField(choices=[(True, "Head"), (False, "Tail")]) coin_outcome = models.BooleanField() dice_report = models.IntegerField(choices=[1, 2, 3, 4, 5, 6], widget=widgets.RadioSelect, label="Dice outcome:") winning = models.BooleanField() paying_round = models.IntegerField() round_payoff = models.CurrencyField() def set_payoff(self): if self.participant.vars['treatment'] == "control": self.round_payoff = self.dice_report*self.participant.vars['performance'] + Constants.fix_control if self.participant.vars['treatment'] == "exo": if self.coin_outcome: self.round_payoff = self.dice_report*self.participant.vars['performance'] + Constants.high_coin self.winning = True else: self.round_payoff = self.dice_report * self.participant.vars['performance'] + Constants.low_coin self.winning = False if self.participant.vars['treatment'] == "endo": if self.coin_outcome == self.winning_side: self.round_payoff = self.dice_report * self.participant.vars['performance'] + Constants.high_coin self.winning = True else: self.round_payoff = self.dice_report * self.participant.vars['performance'] + Constants.low_coin self.winning = True if self.round_number == self.paying_round: self.payoff = self.round_payoff self.participant.vars['payment'] = self.round_payoff self.participant.vars['dice'] = self.dice_report self.participant.vars['winning'] = self.winning else: self.payoff = c(0)