from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import csv import numpy doc = """ Part 2 - PLAY: 20 Rounds """ class Constants(BaseConstants): name_in_url = 'code_SS_part2_play_playersA' 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 = 20 # 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) r11_rand_num_purple = random.randint(1, 100) r12_rand_num_purple = random.randint(1, 100) r13_rand_num_purple = random.randint(1, 100) r14_rand_num_purple = random.randint(1, 100) r15_rand_num_purple = random.randint(1, 100) r16_rand_num_purple = random.randint(1, 100) r17_rand_num_purple = random.randint(1, 100) r18_rand_num_purple = random.randint(1, 100) r19_rand_num_purple = random.randint(1, 100) r20_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) r11_rand_num_orange = random.randint(1, 100) r12_rand_num_orange = random.randint(1, 100) r13_rand_num_orange = random.randint(1, 100) r14_rand_num_orange = random.randint(1, 100) r15_rand_num_orange = random.randint(1, 100) r16_rand_num_orange = random.randint(1, 100) r17_rand_num_orange = random.randint(1, 100) r18_rand_num_orange = random.randint(1, 100) r19_rand_num_orange = random.randint(1, 100) r20_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): # # < in each round > # 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 if self.round_number == 11: if Constants.r11_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r11_rand_num_purple >= 100 / 3) and (Constants.r11_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 12: if Constants.r12_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r12_rand_num_purple >= 100 / 3) and (Constants.r12_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 13: if Constants.r13_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r13_rand_num_purple >= 100 / 3) and (Constants.r13_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 14: if Constants.r14_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r14_rand_num_purple >= 100 / 3) and (Constants.r14_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 15: if Constants.r15_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r15_rand_num_purple >= 100 / 3) and (Constants.r15_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 16: if Constants.r16_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r16_rand_num_purple >= 100 / 3) and (Constants.r16_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 17: if Constants.r17_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r17_rand_num_purple >= 100 / 3) and (Constants.r17_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 18: if Constants.r18_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r18_rand_num_purple >= 100 / 3) and (Constants.r18_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 19: if Constants.r19_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r19_rand_num_purple >= 100 / 3) and (Constants.r19_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 if self.round_number == 20: if Constants.r20_rand_num_purple < 100 / 3: self.content_purple = 5 elif (Constants.r20_rand_num_purple >= 100 / 3) and (Constants.r20_rand_num_purple < 100 / 3 * 2): self.content_purple = 9 else: self.content_purple = 19 # # # < in each round > # 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 if self.round_number == 11: if Constants.r11_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r11_rand_num_orange >= 100 / 3) and (Constants.r11_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 12: if Constants.r12_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r12_rand_num_orange >= 100 / 3) and (Constants.r12_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 13: if Constants.r13_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r13_rand_num_orange >= 100 / 3) and (Constants.r13_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 14: if Constants.r14_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r14_rand_num_orange >= 100 / 3) and (Constants.r14_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 15: if Constants.r15_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r15_rand_num_orange >= 100 / 3) and (Constants.r15_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 16: if Constants.r16_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r16_rand_num_orange >= 100 / 3) and (Constants.r16_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 17: if Constants.r17_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r17_rand_num_orange >= 100 / 3) and (Constants.r17_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 18: if Constants.r18_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r18_rand_num_orange >= 100 / 3) and (Constants.r18_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 19: if Constants.r19_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r19_rand_num_orange >= 100 / 3) and (Constants.r19_rand_num_orange < 100 / 3 * 2): self.content_orange = 9 else: self.content_orange = 19 if self.round_number == 20: if Constants.r20_rand_num_orange < 100 / 3: self.content_orange = 5 elif (Constants.r20_rand_num_orange >= 100 / 3) and (Constants.r20_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, Constants.r11_rand_num_purple, Constants.r11_rand_num_orange, Constants.r12_rand_num_purple, Constants.r12_rand_num_orange, Constants.r13_rand_num_purple, Constants.r13_rand_num_orange, Constants.r14_rand_num_purple, Constants.r14_rand_num_orange, Constants.r15_rand_num_purple, Constants.r15_rand_num_orange, Constants.r16_rand_num_purple, Constants.r16_rand_num_orange, Constants.r17_rand_num_purple, Constants.r17_rand_num_orange, Constants.r18_rand_num_purple, Constants.r18_rand_num_orange, Constants.r19_rand_num_purple, Constants.r19_rand_num_orange, Constants.r20_rand_num_purple, Constants.r20_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() # part2_content_purple_r1 = models.IntegerField() part2_content_purple_r2 = models.IntegerField() part2_content_purple_r3 = models.IntegerField() part2_content_purple_r4 = models.IntegerField() part2_content_purple_r5 = models.IntegerField() part2_content_purple_r6 = models.IntegerField() part2_content_purple_r7 = models.IntegerField() part2_content_purple_r8 = models.IntegerField() part2_content_purple_r9 = models.IntegerField() part2_content_purple_r10 = models.IntegerField() part2_content_purple_r11 = models.IntegerField() part2_content_purple_r12 = models.IntegerField() part2_content_purple_r13 = models.IntegerField() part2_content_purple_r14 = models.IntegerField() part2_content_purple_r15 = models.IntegerField() part2_content_purple_r16 = models.IntegerField() part2_content_purple_r17 = models.IntegerField() part2_content_purple_r18 = models.IntegerField() part2_content_purple_r19 = models.IntegerField() part2_content_purple_r20 = models.IntegerField() # part2_content_orange_r1 = models.IntegerField() part2_content_orange_r2 = models.IntegerField() part2_content_orange_r3 = models.IntegerField() part2_content_orange_r4 = models.IntegerField() part2_content_orange_r5 = models.IntegerField() part2_content_orange_r6 = models.IntegerField() part2_content_orange_r7 = models.IntegerField() part2_content_orange_r8 = models.IntegerField() part2_content_orange_r9 = models.IntegerField() part2_content_orange_r10 = models.IntegerField() part2_content_orange_r11 = models.IntegerField() part2_content_orange_r12 = models.IntegerField() part2_content_orange_r13 = models.IntegerField() part2_content_orange_r14 = models.IntegerField() part2_content_orange_r15 = models.IntegerField() part2_content_orange_r16 = models.IntegerField() part2_content_orange_r17 = models.IntegerField() part2_content_orange_r18 = models.IntegerField() part2_content_orange_r19 = models.IntegerField() part2_content_orange_r20 = models.IntegerField() # part2_first_box_r1 = models.StringField() part2_first_box_r2 = models.StringField() part2_first_box_r3 = models.StringField() part2_first_box_r4 = models.StringField() part2_first_box_r5 = models.StringField() part2_first_box_r6 = models.StringField() part2_first_box_r7 = models.StringField() part2_first_box_r8 = models.StringField() part2_first_box_r9 = models.StringField() part2_first_box_r10 = models.StringField() part2_first_box_r11 = models.StringField() part2_first_box_r12 = models.StringField() part2_first_box_r13 = models.StringField() part2_first_box_r14 = models.StringField() part2_first_box_r15 = models.StringField() part2_first_box_r16 = models.StringField() part2_first_box_r17 = models.StringField() part2_first_box_r18 = models.StringField() part2_first_box_r19 = models.StringField() part2_first_box_r20 = models.StringField() # part2_search_cost_r1 = models.IntegerField() part2_search_cost_r2 = models.IntegerField() part2_search_cost_r3 = models.IntegerField() part2_search_cost_r4 = models.IntegerField() part2_search_cost_r5 = models.IntegerField() part2_search_cost_r6 = models.IntegerField() part2_search_cost_r7 = models.IntegerField() part2_search_cost_r8 = models.IntegerField() part2_search_cost_r9 = models.IntegerField() part2_search_cost_r10 = models.IntegerField() part2_search_cost_r11 = models.IntegerField() part2_search_cost_r12 = models.IntegerField() part2_search_cost_r13 = models.IntegerField() part2_search_cost_r14 = models.IntegerField() part2_search_cost_r15 = models.IntegerField() part2_search_cost_r16 = models.IntegerField() part2_search_cost_r17 = models.IntegerField() part2_search_cost_r18 = models.IntegerField() part2_search_cost_r19 = models.IntegerField() part2_search_cost_r20 = models.IntegerField() # part2_search_choice_r1 = models.IntegerField() part2_search_choice_r2 = models.IntegerField() part2_search_choice_r3 = models.IntegerField() part2_search_choice_r4 = models.IntegerField() part2_search_choice_r5 = models.IntegerField() part2_search_choice_r6 = models.IntegerField() part2_search_choice_r7 = models.IntegerField() part2_search_choice_r8 = models.IntegerField() part2_search_choice_r9 = models.IntegerField() part2_search_choice_r10 = models.IntegerField() part2_search_choice_r11 = models.IntegerField() part2_search_choice_r12 = models.IntegerField() part2_search_choice_r13 = models.IntegerField() part2_search_choice_r14 = models.IntegerField() part2_search_choice_r15 = models.IntegerField() part2_search_choice_r16 = models.IntegerField() part2_search_choice_r17 = models.IntegerField() part2_search_choice_r18 = models.IntegerField() part2_search_choice_r19 = models.IntegerField() part2_search_choice_r20 = models.IntegerField() # part2_payoff_r1 = models.IntegerField() part2_payoff_r2 = models.IntegerField() part2_payoff_r3 = models.IntegerField() part2_payoff_r4 = models.IntegerField() part2_payoff_r5 = models.IntegerField() part2_payoff_r6 = models.IntegerField() part2_payoff_r7 = models.IntegerField() part2_payoff_r8 = models.IntegerField() part2_payoff_r9 = models.IntegerField() part2_payoff_r10 = models.IntegerField() part2_payoff_r11 = models.IntegerField() part2_payoff_r12 = models.IntegerField() part2_payoff_r13 = models.IntegerField() part2_payoff_r14 = models.IntegerField() part2_payoff_r15 = models.IntegerField() part2_payoff_r16 = models.IntegerField() part2_payoff_r17 = models.IntegerField() part2_payoff_r18 = models.IntegerField() part2_payoff_r19 = models.IntegerField() part2_payoff_r20 = models.IntegerField() # def set_payoff(self): if self.round_number == 1: self.part2_payoff_r1 = int(self.in_round(self.round_number).payoff) if self.round_number == 2: self.part2_payoff_r2 = int(self.in_round(self.round_number).payoff) if self.round_number == 3: self.part2_payoff_r3 = int(self.in_round(self.round_number).payoff) if self.round_number == 4: self.part2_payoff_r4 = int(self.in_round(self.round_number).payoff) if self.round_number == 5: self.part2_payoff_r5 = int(self.in_round(self.round_number).payoff) if self.round_number == 6: self.part2_payoff_r6 = int(self.in_round(self.round_number).payoff) if self.round_number == 7: self.part2_payoff_r7 = int(self.in_round(self.round_number).payoff) if self.round_number == 8: self.part2_payoff_r8 = int(self.in_round(self.round_number).payoff) if self.round_number == 9: self.part2_payoff_r9 = int(self.in_round(self.round_number).payoff) if self.round_number == 10: self.part2_payoff_r10 = int(self.in_round(self.round_number).payoff) if self.round_number == 11: self.part2_payoff_r11 = int(self.in_round(self.round_number).payoff) if self.round_number == 12: self.part2_payoff_r12 = int(self.in_round(self.round_number).payoff) if self.round_number == 13: self.part2_payoff_r13 = int(self.in_round(self.round_number).payoff) if self.round_number == 14: self.part2_payoff_r14 = int(self.in_round(self.round_number).payoff) if self.round_number == 15: self.part2_payoff_r15 = int(self.in_round(self.round_number).payoff) if self.round_number == 16: self.part2_payoff_r16 = int(self.in_round(self.round_number).payoff) if self.round_number == 17: self.part2_payoff_r17 = int(self.in_round(self.round_number).payoff) if self.round_number == 18: self.part2_payoff_r18 = int(self.in_round(self.round_number).payoff) if self.round_number == 19: self.part2_payoff_r19 = int(self.in_round(self.round_number).payoff) if self.round_number == 20: self.part2_payoff_r20 = int(self.in_round(self.round_number).payoff)