from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import itertools from random import randint author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'schulzefrank' players_per_group = None num_rounds = 1 ownpay=[0, 16, 32, 48, 64, 80, 96, 112, 128, 144] firmpay=[20, 40, 60, 80, 100, 120, 140, 160, 180, 200] class Subsession(BaseSubsession): def creating_session(self): colors = itertools.cycle([True, False]) for p in self.get_players(): p.monitor = next(colors) class Group(BaseGroup): pass class Player(BasePlayer): monitor = models.BooleanField() choice = models.SmallIntegerField( choices=[ (0, 'A1'), (1, 'A2'), (2, 'A3'), (3, 'A4'), (4, 'A5'), (5, 'A6'), (6, 'A7'), (7, 'A8'), (8, 'A9'), (9, 'A10'),], widget=widgets.RadioSelect, verbose_name='Please choose a firm.' ) detected = models.BooleanField(default=False) female = models.BooleanField( choices=[ (True, 'Female'), (False, 'Male')], widget=widgets.RadioSelect, verbose_name='What is your gender?' ) study = models.StringField( verbose_name='What is your field of study?' ) payment = models.IntegerField() def set_payoff(self): if self.monitor==False or self.choice<2: self.payment = Constants.ownpay[self.choice] random = randint(1, 6) if self.monitor==True and self.choice>2 and self.choice<5: if random==6: self.payment=0 self.detected = True else: self.payment = Constants.ownpay[self.choice] if self.monitor==True and self.choice>4 and self.choice<7: if random==6 or random==5: self.payment=0 self.detected = True else: self.payment = Constants.ownpay[self.choice] if self.monitor==True and self.choice>6 and self.choice<9: if random>3: self.payment=0 self.detected = True else: self.payment = Constants.ownpay[self.choice] if self.monitor==True and self.choice>8: if random>2: self.payment=0 self.detected = True else: self.payment = Constants.ownpay[self.choice] self.payoff = self.payment