from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import csv import numpy doc = """ Part 1 - PLAY: 10 Rounds """ class Constants(BaseConstants): name_in_url = 'code_SS_part1_play' players_per_group = 4 # --> only relevant for Players B - Part 2 # basically the group brings together all Players A from the same batch/session num_rounds = 10 # r1_rand_num_purple = random.randint(1, 100) r2_rand_num_purple = random.randint(1, 100) r3_rand_num_purple = random.randint(1, 100) r4_rand_num_purple = random.randint(1, 100) r5_rand_num_purple = random.randint(1, 100) r6_rand_num_purple = random.randint(1, 100) r7_rand_num_purple = random.randint(1, 100) r8_rand_num_purple = random.randint(1, 100) r9_rand_num_purple = random.randint(1, 100) r10_rand_num_purple = random.randint(1, 100) # r1_rand_num_orange = random.randint(1, 100) r2_rand_num_orange = random.randint(1, 100) r3_rand_num_orange = random.randint(1, 100) r4_rand_num_orange = random.randint(1, 100) r5_rand_num_orange = random.randint(1, 100) r6_rand_num_orange = random.randint(1, 100) r7_rand_num_orange = random.randint(1, 100) r8_rand_num_orange = random.randint(1, 100) r9_rand_num_orange = random.randint(1, 100) r10_rand_num_orange = random.randint(1, 100) # search_cost = [1, 5] first_box = ["left", "right"] class Subsession(BaseSubsession): content_purple = models.IntegerField() content_orange = models.IntegerField() num_last_round = models.IntegerField() def creating_session(self): # # PURPLE Box content: LOW (5 tokens) vs. MID (9 tokens) vs. HIGH (19 tokens) if self.round_number == 1: if Constants.r1_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r1_rand_num_purple >= 100 / 3) and (Constants.r1_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 2: if Constants.r2_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r2_rand_num_purple >= 100 / 3) and (Constants.r2_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 3: if Constants.r3_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r3_rand_num_purple >= 100 / 3) and (Constants.r3_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 4: if Constants.r4_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r4_rand_num_purple >= 100 / 3) and (Constants.r4_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 5: if Constants.r5_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r5_rand_num_purple >= 100 / 3) and (Constants.r5_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 6: if Constants.r6_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r6_rand_num_purple >= 100 / 3) and (Constants.r6_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 7: if Constants.r7_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r7_rand_num_purple >= 100 / 3) and (Constants.r7_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 8: if Constants.r8_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r8_rand_num_purple >= 100 / 3) and (Constants.r8_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 9: if Constants.r9_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r9_rand_num_purple >= 100 / 3) and (Constants.r9_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 10: if Constants.r10_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r10_rand_num_purple >= 100 / 3) and (Constants.r10_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 # # # ORANGE Box content: LOW (5 tokens) vs. MID (9 tokens) vs. HIGH (19 tokens) if self.round_number == 1: if Constants.r1_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r1_rand_num_orange >= 100 / 3) and (Constants.r1_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 2: if Constants.r2_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r2_rand_num_orange >= 100 / 3) and (Constants.r2_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 3: if Constants.r3_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r3_rand_num_orange >= 100 / 3) and (Constants.r3_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 4: if Constants.r4_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r4_rand_num_orange >= 100 / 3) and (Constants.r4_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 5: if Constants.r5_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r5_rand_num_orange >= 100 / 3) and (Constants.r5_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 6: if Constants.r6_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r6_rand_num_orange >= 100 / 3) and (Constants.r6_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 7: if Constants.r7_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r7_rand_num_orange >= 100 / 3) and (Constants.r7_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 8: if Constants.r8_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r8_rand_num_orange >= 100 / 3) and (Constants.r8_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 9: if Constants.r9_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r9_rand_num_orange >= 100 / 3) and (Constants.r9_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 10: if Constants.r10_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r10_rand_num_orange >= 100 / 3) and (Constants.r10_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 # # print(Constants.r1_rand_num_purple, Constants.r1_rand_num_orange,Constants.r2_rand_num_purple, Constants.r2_rand_num_orange, Constants.r3_rand_num_purple, Constants.r3_rand_num_orange, Constants.r4_rand_num_purple, Constants.r4_rand_num_orange, Constants.r5_rand_num_purple, Constants.r5_rand_num_orange, Constants.r6_rand_num_purple, Constants.r6_rand_num_orange, Constants.r7_rand_num_purple, Constants.r7_rand_num_orange, Constants.r8_rand_num_purple, Constants.r8_rand_num_orange, Constants.r9_rand_num_purple, Constants.r9_rand_num_orange, Constants.r10_rand_num_purple, Constants.r10_rand_num_orange) # # self.num_last_round = Constants.num_rounds # for p in self.get_players(): p.content_purple = self.content_purple p.content_orange = self.content_orange p.search_cost = random.choice([1, 5]) # SEARCH COST: LOW (1 token) vs. HIGH (5 tokens) p.first_box = random.choice(["left", "right"]) # FIRST BOX OPENED: LEFT (Box 1) == Purple vs. RIGHT (Box 2) == Orange class Group(BaseGroup): def set_payoffs(self): for p in self.get_players(): p.set_payoff() class Player(BasePlayer): # content_purple = models.IntegerField() content_orange = models.IntegerField() search_cost = models.IntegerField() first_box = models.StringField() # # decision = models.IntegerField( label="", choices=[[1, 'Sì'], [0, 'No']], doc="""Player's decision""", widget=widgets.RadioSelect, ) decision_type = models.StringField() highest_value = models.IntegerField() payoff_int = models.IntegerField() cum_payoff = models.CurrencyField() cum_payoff_int = models.IntegerField() # round_number = models.IntegerField() # part1_content_purple_r1 = models.IntegerField() part1_content_purple_r2 = models.IntegerField() part1_content_purple_r3 = models.IntegerField() part1_content_purple_r4 = models.IntegerField() part1_content_purple_r5 = models.IntegerField() part1_content_purple_r6 = models.IntegerField() part1_content_purple_r7 = models.IntegerField() part1_content_purple_r8 = models.IntegerField() part1_content_purple_r9 = models.IntegerField() part1_content_purple_r10 = models.IntegerField() # part1_content_orange_r1 = models.IntegerField() part1_content_orange_r2 = models.IntegerField() part1_content_orange_r3 = models.IntegerField() part1_content_orange_r4 = models.IntegerField() part1_content_orange_r5 = models.IntegerField() part1_content_orange_r6 = models.IntegerField() part1_content_orange_r7 = models.IntegerField() part1_content_orange_r8 = models.IntegerField() part1_content_orange_r9 = models.IntegerField() part1_content_orange_r10 = models.IntegerField() # part1_first_box_r1 = models.StringField() part1_first_box_r2 = models.StringField() part1_first_box_r3 = models.StringField() part1_first_box_r4 = models.StringField() part1_first_box_r5 = models.StringField() part1_first_box_r6 = models.StringField() part1_first_box_r7 = models.StringField() part1_first_box_r8 = models.StringField() part1_first_box_r9 = models.StringField() part1_first_box_r10 = models.StringField() # part1_search_cost_r1 = models.IntegerField() part1_search_cost_r2 = models.IntegerField() part1_search_cost_r3 = models.IntegerField() part1_search_cost_r4 = models.IntegerField() part1_search_cost_r5 = models.IntegerField() part1_search_cost_r6 = models.IntegerField() part1_search_cost_r7 = models.IntegerField() part1_search_cost_r8 = models.IntegerField() part1_search_cost_r9 = models.IntegerField() part1_search_cost_r10 = models.IntegerField() # part1_search_choice_r1 = models.IntegerField() part1_search_choice_r2 = models.IntegerField() part1_search_choice_r3 = models.IntegerField() part1_search_choice_r4 = models.IntegerField() part1_search_choice_r5 = models.IntegerField() part1_search_choice_r6 = models.IntegerField() part1_search_choice_r7 = models.IntegerField() part1_search_choice_r8 = models.IntegerField() part1_search_choice_r9 = models.IntegerField() part1_search_choice_r10 = models.IntegerField() # part1_payoff_r1 = models.IntegerField() part1_payoff_r2 = models.IntegerField() part1_payoff_r3 = models.IntegerField() part1_payoff_r4 = models.IntegerField() part1_payoff_r5 = models.IntegerField() part1_payoff_r6 = models.IntegerField() part1_payoff_r7 = models.IntegerField() part1_payoff_r8 = models.IntegerField() part1_payoff_r9 = models.IntegerField() part1_payoff_r10 = models.IntegerField() # def set_payoff(self): if self.round_number == 1: self.part1_payoff_r1 = int(self.in_round(self.round_number).payoff) if self.round_number == 2: self.part1_payoff_r2 = int(self.in_round(self.round_number).payoff) if self.round_number == 3: self.part1_payoff_r3 = int(self.in_round(self.round_number).payoff) if self.round_number == 4: self.part1_payoff_r4 = int(self.in_round(self.round_number).payoff) if self.round_number == 5: self.part1_payoff_r5 = int(self.in_round(self.round_number).payoff) if self.round_number == 6: self.part1_payoff_r6 = int(self.in_round(self.round_number).payoff) if self.round_number == 7: self.part1_payoff_r7 = int(self.in_round(self.round_number).payoff) if self.round_number == 8: self.part1_payoff_r8 = int(self.in_round(self.round_number).payoff) if self.round_number == 9: self.part1_payoff_r9 = int(self.in_round(self.round_number).payoff) if self.round_number == 10: self.part1_payoff_r10 = int(self.in_round(self.round_number).payoff)