from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'open' players_per_group = None num_rounds = 1 start_money = 30 participation_fee = 6 round_loss = 3 instructions = 'start/summary.html' pie = [30, 27, 24, 21, 18, 15, 12, 9, 6, 3] start_money = 30 participation_fee = 6 round_loss = 3 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for player in self.get_players(): player.participant.vars['agreed'] = False class Group(BaseGroup): agreement = models.BooleanField() match12 = models.StringField(initial="No") match13 = models.StringField(initial="No") match23 = models.StringField(initial="No") current1_1 = models.IntegerField(initial=0) current1_2 = models.IntegerField(initial=0) current1_3 = models.IntegerField(initial=0) history1 = models.StringField(initial="") current2_1 = models.IntegerField(initial=0) current2_2 = models.IntegerField(initial=0) current2_3 = models.IntegerField(initial=0) history2 = models.StringField(initial="") current3_1 = models.IntegerField(initial=0) current3_2 = models.IntegerField(initial=0) current3_3 = models.IntegerField(initial=0) history3 = models.StringField(initial="") def set_agreement(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) if self.current1_1 == self.current2_1 and self.current1_2 == self.current2_2 and self.current1_3 == self.current2_3 and ( self.current1_1 + self.current1_2 + self.current1_3) > 0: self.agreement = True p1.final_share = self.current1_1 p2.final_share = self.current1_2 p3.final_share = self.current1_3 if self.current1_1 == self.current3_1 and self.current1_2 == self.current3_2 and self.current1_3 == self.current3_3 and ( self.current1_1 + self.current1_2 + self.current1_3) > 0: self.agreement = True p1.final_share = self.current2_1 p2.final_share = self.current2_2 p3.final_share = self.current2_3 if self.current3_1 == self.current2_1 and self.current3_2 == self.current2_2 and self.current3_3 == self.current2_3 and ( self.current2_1 + self.current2_2 + self.current2_3) > 0: self.agreement = True p1.final_share = self.current3_1 p2.final_share = self.current3_2 p3.final_share = self.current3_3 class Player(BasePlayer): quiz1 = models.BooleanField(label="", choices=[(True, "Yes"), (False, "No")], widget=widgets.RadioSelect) quiz2 = models.IntegerField(label="") quiz3 = models.IntegerField(label="") final_share = models.IntegerField() def live_offers(self, data): answer1 = data['current1'] answer2 = data['current2'] answer3 = data['current3'] player_id = data['player_id'] # print("I got" + str(answer1) + "from" + str(player_id)) if player_id == 1: self.group.current1_1 = answer1 self.group.current1_2 = answer2 self.group.current1_3 = answer3 self.group.history1 += str(answer1) + "/" + str(answer2) + "/" + str(answer3) + ";" if player_id == 2: self.group.current2_1 = answer1 self.group.current2_2 = answer2 self.group.current2_3 = answer3 self.group.history2 += str(answer1) + "/" + str(answer2) + "/" + str(answer3) + ";" if player_id == 3: self.group.current3_1 = answer1 self.group.current3_2 = answer2 self.group.current3_3 = answer3 self.group.history3 += str(answer1) + "/" + str(answer2) + "/" + str(answer3) + ";" if self.group.current1_1 == self.group.current2_1 and self.group.current1_2 == self.group.current2_2 and self.group.current1_3 == self.group.current2_3 and ( self.group.current1_1 + self.group.current1_2 + self.group.current1_3) > 0: smatch12 = 1 self.group.match12 = "Yes" else: smatch12 = 0 self.group.match12 = "No" if self.group.current1_1 == self.group.current3_1 and self.group.current1_2 == self.group.current3_2 and self.group.current1_3 == self.group.current3_3 and ( self.group.current1_1 + self.group.current1_2 + self.group.current1_3) > 0: smatch13 = 1 self.group.match13 = "Yes" else: smatch13 = 0 self.group.match13 = "No" if self.group.current3_1 == self.group.current2_1 and self.group.current3_2 == self.group.current2_2 and self.group.current3_3 == self.group.current2_3 and ( self.group.current2_1 + self.group.current2_2 + self.group.current2_3) > 0: smatch23 = 1 self.group.match23 = "Yes" else: smatch23 = 0 self.group.match23 = "No" response = { 'number': player_id, 'response1': answer1, 'response2': answer2, 'response3': answer3, 'match12': smatch12, 'match13': smatch13, 'match23': smatch23, } return {0: response} gender = models.IntegerField(choices=[(1, "Male"), (2, "Female"), (3, "Other")], label="Gender:", widget=widgets.RadioSelect) age = models.IntegerField(choices=[(1, "Younger than 18"), (2, "18-20"), (3, "21-23"), (4, "24-26"), (5, "27-29"), (6, "30 or older")], label="Age:") nationality = models.StringField(label="Nationality:") study = models.IntegerField(choices=[(1, "Medicine"), (2, "Engineering"), (3, "Mathematics and computer science"), (4, "Natural science"), (5, "Law"), (6, "Economics and business"), (7, "Social science"), (8, "Humanities")], label="Field of study:") guess = models.IntegerField(choices=[(1, "1 male participant and 1 female participant"), (2, "2 male participants"), (3, "2 female participants")], label="What do you think is the gender composition of the other two players with whom you have just negotiated?", widget=widgets.RadioSelect) friends = models.BooleanField(choices=[(True, "Yes"), (False, "No")], widget=widgets.RadioSelect, label="When you heard the voices of other participants, were you able to recognize any friend, classmate, or acquaintance? ") competetiveness = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, ""), (11, "")], label="", widget=widgets.RadioSelectHorizontal) competetition = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, ""), (11, "")], label="", widget=widgets.RadioSelectHorizontal) risk = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, ""), (11, "")], label="", widget=widgets.RadioSelectHorizontal) time = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, ""), (11, "")], label="", widget=widgets.RadioSelectHorizontal) intentions = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, ""), (11, "")], label="", widget=widgets.RadioSelectHorizontal) altruism = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, ""), (11, "")], label="", widget=widgets.RadioSelectHorizontal) bottle = models.IntegerField(choices=[(1, "5 Euro bottle"), (2, "10 Euro bottle"), (3, "15 Euro bottle"), (4, "20 Euro bottle"), (5, "25 Euro bottle"), (6, "30 Euro bottle"), ], label="Which bottle do you give?", widget=widgets.RadioSelect) punish = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), (8, ""), (9, ""), (10, ""), (11, "")], label="", widget=widgets.RadioSelectHorizontal) heard = models.BooleanField(choices=[(True, "Yes"), (False, "No")], widget=widgets.RadioSelect, label="Have you talked to people who have participated in other sessions of this experiment before?") content = models.BooleanField(choices=[(True, "Yes"), (False, "No")], widget=widgets.RadioSelect, label="Have you heard about the content of this experiment before?") aim = models.StringField(label="What do you think is the aim of this experiment?") understand = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), ], label="", widget=widgets.RadioSelectHorizontal) time_pressure = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), ], label="", widget=widgets.RadioSelectHorizontal) enjoy = models.IntegerField(choices=[(1, ""), (2, ""), (3, ""), (4, ""), (5, ""), (6, ""), (7, ""), ], label="", widget=widgets.RadioSelectHorizontal)