from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Stephen Nei' doc = """ This app is the meat of the experiment, where players interact. 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_part3_treatment1' players_per_group = 2 num_rounds = 2 bias_weight = 2 bias_otherweight = 1 draws_from_bag = 2 cost_lower_limit = 0 cost_upper_limit = 10 equivalence_bag_total = 100 max_cost = 10 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): both_paid_CostThenSignal = models.BooleanField() def set_paid(self): self.both_paid_CostThenSignal = True players = self.get_players() for p in players: self.both_paid_CostThenSignal = self.both_paid_CostThenSignal and (p.reservation_cost_CostThenSignal >= self.subsession.cost_to_view) 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_CostThenSignal1 = models.IntegerField( min=1, max=Constants.equivalence_bag_total, widget=widgets.Slider(attrs={'step':'2'}), doc="used for soliciting beliefs" ) probReservation_CostThenSignal2 = models.IntegerField( min=1, max=Constants.equivalence_bag_total, widget=widgets.Slider(attrs={'step':'2'}), doc="used for soliciting beliefs" ) reservation_cost_CostThenSignal = models.FloatField( min=0, max=Constants.max_cost, widget=widgets.Slider(attrs={'step':'0.1'}), doc="used to get reservation cost for participating" ) draw_from_box = models.BooleanField() touched_slider = models.IntegerField(blank=True)