from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Stephen Nei' doc = """ A test of oTree/mTurk interface and a pilot for collecting data on mTurkers' interaction with the experimental set-up without the complication of having users directly interact """ class Constants(BaseConstants): name_in_url = 'Ambiguity_survey' players_per_group = None num_rounds = 1 draws_from_bag = 10 bag_size = 101 participation_reward = 50 reward_for_majority = 100 reward_for_number = 100 cost_lower = 0 cost_upper = 50 possible_add_draws = [1,3,5,7,9] class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.bag_contents = random.randint(0,Constants.bag_size) p.cost_to_view = random.randint(Constants.cost_lower,Constants.cost_upper) p.add_draws = random.choice(Constants.possible_add_draws) draw_isOrange = random.choices([0,1],weights=[Constants.bag_size-p.bag_contents,p.bag_contents],k=Constants.draws_from_bag) p.numOrangeDraws = sum(draw_isOrange) addDraw_isOrange = random.choices([0,1],weights=[p.bag_contents,Constants.bag_size-p.bag_contents],k=p.add_draws) p.addNumOrange = sum(addDraw_isOrange) p.reimburseRound = random.choice([0,1]) p.attn_check = True class Group(BaseGroup): pass class Player(BasePlayer): bag_contents = models.IntegerField() cost_to_view = models.IntegerField() add_draws = models.IntegerField() numOrangeDraws = models.IntegerField() addNumOrange = models.IntegerField() repeatNumOrange = models.IntegerField( min=0, max=Constants.draws_from_bag ) majorityColor = models.IntegerField( choices=[ [1,'Orange'], [2,'Green'], ], widget=widgets.RadioSelect ) ballPossibleColors = models.IntegerField( choices=[ [1,'Green'], [2,'Blue'], [3,'Orange'], ],blank=True,widget=widgets.RadioSelect ) probReservation_first = models.IntegerField( min=0, max=Constants.bag_size, doc="used for soliciting beliefs" ) probReservation_second = models.IntegerField( min=0, max=Constants.bag_size, doc="used for soliciting beliefs" ) majorityColor_second = models.IntegerField( choices=[ [1, 'Orange'], [2, 'Green'], ], widget=widgets.RadioSelect ) reservation_cost = models.IntegerField( min=Constants.cost_lower, max=Constants.cost_upper, doc="used to get reservation cost for participating" ) reimburseRound = models.IntegerField() attn_check = models.BooleanField()