from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Stephen Nei' doc = """ App to explain basic experimental setting and to test subjects understand how to provide beliefs. Overall experiment description: Look at how subjects respond to costs when gathering information from others. Subjects will be guessing the contents of a "bag" of "marbles" They will receive private signals in the form of draws from the bag. They will have the chance to exchange information with other participants. Depending on the treatment, they will either have to pay for this opportunity before receiving their signal, after receiving their signal, or not at all. Goals are to see if: 1) Subjects respond to costs (eg pay cost when signal is weak, don't when signal is strong) 2) Subjects recognize other agents are doing this (eg respond more weakly when costs are introduced) """ class Constants(BaseConstants): name_in_url = 'selection_experiment_part2_instructionsAndCheck' players_per_group = None num_rounds = 3 instructions_template = 'selection_experiment_part2_instructionsAndCheck/instructions.html' base_payment = c(50) additional_payment = c(10) bias_weight = 2 bias_otherweight = 1 draws_from_bag = 2 cost_lower_limit = 0 cost_upper_limit = 10 equivalence_bag_total = 100 class Subsession(BaseSubsession): bag_type = models.StringField() cost_to_view = models.FloatField() nickels_in_box = models.IntegerField() nickel_drawn = models.StringField() def creating_session(self): self.nickels_in_box = random.randint(0,100) nickel_drawn = random.choices(["was","was not"],weights=[self.nickels_in_box,100-self.nickels_in_box],k=1) self.nickel_drawn = "".join(nickel_drawn) bag_type = random.choice([True,False]) for p in self.get_players(): if bag_type: self.bag_type = "RED" first_draw = random.choices(['red', 'blue'],weights=[Constants.bias_weight,Constants.bias_otherweight],k=1) p.first_draw = "".join(first_draw) second_draw = random.choices(['red', 'blue'],weights=[Constants.bias_weight, Constants.bias_otherweight], k=1) p.second_draw = "".join(second_draw) else: self.bag_type = "BLUE" first_draw = random.choices(['blue', 'red'],weights=[Constants.bias_weight, Constants.bias_otherweight], k=1) p.first_draw = "".join(first_draw) second_draw = random.choices(['blue', 'red'],weights=[Constants.bias_weight, Constants.bias_otherweight], k=1) p.second_draw = "".join(second_draw) self.cost_to_view = random.uniform(Constants.cost_lower_limit,Constants.cost_upper_limit) class Group(BaseGroup): pass class Player(BasePlayer): first_draw = models.StringField( doc="first draw for the player from the bag" ) second_draw = models.StringField( doc="second draw for the player from the bag" ) probReservation_amount = models.IntegerField( min=0, max=Constants.equivalence_bag_total, widget=widgets.Slider(), doc="used for soliciting beliefs" ) draw_from_box = models.BooleanField() touched_slider = models.IntegerField(blank=True)