from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class SetTypes (WaitPage): after_all_players_arrive = 'SetType' def is_displayed(self): return self.round_number == 1 body_text = "Other participants may take longer to read instructions or make decisions. We thank you for your patience!" class SetTypes2 (WaitPage): after_all_players_arrive = 'set_type' def is_displayed(self): return self.round_number == 1 class Get_multiplier_previous_round (WaitPage): """Get Endowment and Multiplier from previous application""" after_all_players_arrive = 'get_multiplier_previous_round' body_text = "Waiting for other the other participants. Please be patient." class Type_WillBeAssigned (Page): def is_displayed(self): return self.round_number == 1 timeout_seconds = 20 def before_next_page(self): if self.timeout_happened: self.player.timeout = True class Type_Assign (Page): def is_displayed(self): return self.round_number == 1 timeout_seconds = 30 def before_next_page(self): if self.timeout_happened: self.player.timeout = True class BeliefsWillStart (Page): def is_displayed(self): return self.round_number == 1 timeout_seconds = 20 def before_next_page(self): if self.timeout_happened: self.player.timeout = True class BeliefsInstructions (Page): def is_displayed(self): return self.round_number == 1 timeout_seconds = 20 def before_next_page(self): if self.timeout_happened: self.player.timeout = True class Beliefs (Page): form_model = 'player' form_fields = ['beliefs_HH', 'beliefs_HL', 'beliefs_LH', 'beliefs_LL'] def is_displayed(self): self.participant.vars['numbs'] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] return self.round_number == 1 def vars_for_template(self): me = self.player opponent = me.other_player() import random num = random.choice(self.participant.vars['numbs']) print("num") print(num) return dict( my_contribution=me.contribution, opponent_contribution=opponent.contribution, my_multiplier=me.multiplier, opponent_multplier=opponent.multiplier, my_endowment = me.endowment, opponent_endowment=opponent.endowment, my_addedtoPGG=me.addedtoPGG, opponent_addedtoPGG=opponent.addedtoPGG, my_type=me.type, opponent_type=opponent.type, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay, my_num = num, ) timeout_seconds = 60 def before_next_page(self): if self.timeout_happened: self.player.timeout = True self.player.timeout_beliefs = True if self.player.type == "HH": self.player.beliefs_HH = c(46) self.player.beliefs_HL = c(36) self.player.beliefs_LH = c(15) self.player.beliefs_LL = c(16) if self.player.type == "HL": self.player.beliefs_HH = c(32) self.player.beliefs_HL = c(29) self.player.beliefs_LH = c(12) self.player.beliefs_LL = c(9) if self.player.type == "LH": self.player.beliefs_HH = c(30) self.player.beliefs_HL = c(26) self.player.beliefs_LH = c(15) self.player.beliefs_LL = c(12) if self.player.type == "LL": self.player.beliefs_HH = c(31) self.player.beliefs_HL = c(26) self.player.beliefs_LH = c(14) self.player.beliefs_LL = c(11) class Beliefs_Pref (Page): form_model = 'player' form_fields = ['beliefs_preference'] def error_message(self, value): print('values is', value['beliefs_preference']) if (value['beliefs_preference'] != "HH,HL,LH,LL") and (value['beliefs_preference'] != "HH,HL,LL,LH") and (value['beliefs_preference'] != "HH,LH,HL,LL") and (value['beliefs_preference'] != "HH,LH,LL,HL") and (value['beliefs_preference'] != "HH,LL,HL,LH") and (value['beliefs_preference'] != "HH,LL,LH,HL") and (value['beliefs_preference'] != "HL,HH,LH,LL") and (value['beliefs_preference'] != "HL,HH,LL,LH") and (value['beliefs_preference'] != "HL,LH,HH,LL") and (value['beliefs_preference'] != "HL,LH,LL,HH") and (value['beliefs_preference'] != "HL,LL,HH,LH") and (value['beliefs_preference'] != "HL,LL,LH,HH") and (value['beliefs_preference'] != "LH,HL,HH,LL") and (value['beliefs_preference'] != "LH,HL,LL,HH") and (value['beliefs_preference'] != "LH,HH,HL,LL") and (value['beliefs_preference'] != "LH,HH,LL,HL") and (value['beliefs_preference'] != "LH,LL,HL,HH") and (value['beliefs_preference'] != "LH,LL,HH,HL") and (value['beliefs_preference'] != "LL,HL,LH,HH") and (value['beliefs_preference'] != "LL,HL,HH,LH") and (value['beliefs_preference'] != "LL,LH,HL,HH") and (value['beliefs_preference'] != "LL,LH,HH,HL") and (value['beliefs_preference'] != "LL,HH,HL,LH") and (value['beliefs_preference'] != "LL,HH,LH,HL"): return 'Select all 4 types' def is_displayed(self): return self.round_number == 1 timeout_seconds = 60 def before_next_page(self): if self.timeout_happened: self.player.timeout = True self.player.timeout_preferencesbeliefs = True self.player.beliefs_preference = "HH,HL,LH,LL" def vars_for_template(self): #create variables that are displayed to players me = self.player opponent = me.other_player() return dict( my_multiplier=me.multiplier, opponent_multplier=opponent.multiplier, my_endowment = me.endowment, opponent_endowment=opponent.endowment, my_type=me.type, opponent_type=opponent.type, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay ) class Set_Beliefs (WaitPage): after_all_players_arrive = 'belief_preferences_set' body_text = "Waiting for other the other participants. Please be patient." wait_for_all_groups = True # def after_all_players_arrive(self): # self.subsession.get_group_matrix() # print(self.subsession.get_group_matrix()) # after_all_players_arrive = 'belief_preferences_set' # wait_for_all_groups = True def is_displayed(self): return self.round_number == 1 class PGGInstructions (Page): def is_displayed(self): return self.round_number == 1 timeout_seconds = 60 def before_next_page(self): if self.timeout_happened: self.player.timeout = True class FirstRoundWillStart (Page): def is_displayed(self): return self.round_number == 1 timeout_seconds = 20 def before_next_page(self): if self.timeout_happened: self.player.timeout = True class Shuffle_Players (WaitPage): after_all_players_arrive = 'random_group_order' wait_for_all_groups = True body_text = "Waiting for other the other participants. Please be patient." # def after_all_players_arrive(self): # self.subsession.get_group_matrix() # print(self.subsession.get_group_matrix()) # after_all_players_arrive = 'random_group_order' # wait_for_all_groups = True class Partner_Matched (Page): form_model = 'player' form_fields = ['preference'] def error_message(self, value): print('values is', value['preference']) if (value['preference'] != "HH,HL,LH,LL") and (value['preference'] != "HH,HL,LL,LH") and (value['preference'] != "HH,LH,HL,LL") and (value['preference'] != "HH,LH,LL,HL") and (value['preference'] != "HH,LL,HL,LH") and (value['preference'] != "HH,LL,LH,HL") and (value['preference'] != "HL,HH,LH,LL") and (value['preference'] != "HL,HH,LL,LH") and (value['preference'] != "HL,LH,HH,LL") and (value['preference'] != "HL,LH,LL,HH") and (value['preference'] != "HL,LL,HH,LH") and (value['preference'] != "HL,LL,LH,HH") and (value['preference'] != "LH,HL,HH,LL") and (value['preference'] != "LH,HL,LL,HH") and (value['preference'] != "LH,HH,HL,LL") and (value['preference'] != "LH,HH,LL,HL") and (value['preference'] != "LH,LL,HL,HH") and (value['preference'] != "LH,LL,HH,HL") and (value['preference'] != "LL,HL,LH,HH") and (value['preference'] != "LL,HL,HH,LH") and (value['preference'] != "LL,LH,HL,HH") and (value['preference'] != "LL,LH,HH,HL") and (value['preference'] != "LL,HH,HL,LH") and (value['preference'] != "LL,HH,LH,HL"): return 'Select all 4 types' def get_timeout_seconds(self): if self.participant.vars.get('is_dropout'): return 1 # instant timeout, 1 second else: return 60 def before_next_page(self): if self.timeout_happened: self.player.timeout = True self.player.timeout_preferences = True self.player.preference = "HH,HL,LH,LL" def vars_for_template(self): #create variables that are displayed to players me = self.player opponent = me.other_player() return dict( my_multiplier=me.multiplier, opponent_multplier=opponent.multiplier, my_endowment = me.endowment, opponent_endowment=opponent.endowment, my_type=me.type, opponent_type=opponent.type, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay ) class Shuffle_Groups (WaitPage): after_all_players_arrive = 'do_my_shuffle' wait_for_all_groups = True body_text = "Waiting for other the other participants. Please be patient." # def after_all_players_arrive(self): # self.subsession.get_group_matrix() # print(self.subsession.get_group_matrix()) # after_all_players_arrive = 'do_my_shuffle' # wait_for_all_groups = True class Partner_Assigned (Page): def vars_for_template(self): #create variables that are displayed to players me = self.player opponent = me.other_player() return dict( my_contribution=me.contribution, opponent_contribution=opponent.contribution, my_multiplier=me.multiplier, opponent_multplier=opponent.multiplier, my_endowment = me.endowment, opponent_endowment=opponent.endowment, my_addedtoPGG=me.addedtoPGG, opponent_addedtoPGG=opponent.addedtoPGG, my_type=me.type, opponent_type=opponent.type, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay ) def get_timeout_seconds(self): if self.participant.vars.get('is_dropout'): return 1 # instant timeout, 1 second else: return 30 def before_next_page(self): if self.timeout_happened: self.player.timeout = True class Contribute(Page): """Player: Choose how much to contribute""" form_model = 'player' form_fields = ['contribution'] def vars_for_template(self): me = self.player opponent = me.other_player() return dict( my_contribution=me.contribution, opponent_contribution=opponent.contribution, my_multiplier=me.multiplier, opponent_multplier=opponent.multiplier, my_endowment = me.endowment, opponent_endowment=opponent.endowment, my_addedtoPGG=me.addedtoPGG, my_type=me.type, opponent_type=opponent.type, opponent_addedtoPGG=opponent.addedtoPGG, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay ) def get_timeout_seconds(self): if self.participant.vars.get('is_dropout'): return 1 # instant timeout, 1 second else: return 30 def before_next_page(self): if self.timeout_happened: if self.round_number == 1: self.participant.vars['no_response'] = 1 self.player.timeout_contribution = True print("no_response2") print(self.participant.vars['no_response']) opponent = self.player.other_player() import random if self.player.type == "HH": if opponent.type == "HH": self.player.contribution = random.choice([c(42),c(47),c(52)]) if opponent.type == "HL": self.player.contribution = random.choice([c(33),c(38),c(43)]) if opponent.type == "LH": self.player.contribution = random.choice([c(27),c(32),c(37)]) if opponent.type == "LL": self.player.contribution = random.choice([c(24),c(29),c(34)]) if self.player.type == "HL": if opponent.type == "HH": self.player.contribution = random.choice([c(28),c(33),c(38)]) if opponent.type == "HL": self.player.contribution = random.choice([c(24),c(29),c(34)]) if opponent.type == "LH": self.player.contribution = random.choice([c(20),c(25),c(30)]) if opponent.type == "LL": self.player.contribution = random.choice([c(16),c(21),c(26)]) if self.player.type == "LH": if opponent.type == "HH": self.player.contribution = random.choice([c(12),c(17),c(22)]) if opponent.type == "HL": self.player.contribution = random.choice([c(11),c(16),c(21)]) if opponent.type == "LH": self.player.contribution = random.choice([c(11),c(16),c(21)]) if opponent.type == "LL": self.player.contribution = random.choice([c(8),c(13),c(18)]) if self.player.type == "LL": if opponent.type == "HH": self.player.contribution = random.choice([c(7),c(12),c(17)]) if opponent.type == "HL": self.player.contribution = random.choice([c(5),c(10),c(15)]) if opponent.type == "LH": self.player.contribution = random.choice([c(6),c(11),c(16)]) if opponent.type == "LL": self.player.contribution = random.choice([c(6),c(11),c(16)]) else: self.participant.vars['no_response'] = self.participant.vars['no_response'] + 1 self.player.timeout_contribution = True print("no_response2") print(self.participant.vars['no_response']) if self.participant.vars['no_response'] >= 2: self.participant.vars['is_dropout'] = True print("is_dropout") print(self.participant.vars['is_dropout']) self.player.is_dropout = True print(self.player.is_dropout) opponent = self.player.other_player() import random if self.player.type == "HH": if opponent.type == "HH": self.player.contribution = random.choice([c(42),c(47),c(52)]) if opponent.type == "HL": self.player.contribution = random.choice([c(33),c(38),c(43)]) if opponent.type == "LH": self.player.contribution = random.choice([c(27),c(32),c(37)]) if opponent.type == "LL": self.player.contribution = random.choice([c(24),c(29),c(34)]) if self.player.type == "HL": if opponent.type == "HH": self.player.contribution = random.choice([c(28),c(33),c(38)]) if opponent.type == "HL": self.player.contribution = random.choice([c(24),c(29),c(34)]) if opponent.type == "LH": self.player.contribution = random.choice([c(20),c(25),c(30)]) if opponent.type == "LL": self.player.contribution = random.choice([c(16),c(21),c(26)]) if self.player.type == "LH": if opponent.type == "HH": self.player.contribution = random.choice([c(12),c(17),c(22)]) if opponent.type == "HL": self.player.contribution = random.choice([c(11),c(16),c(21)]) if opponent.type == "LH": self.player.contribution = random.choice([c(11),c(16),c(21)]) if opponent.type == "LL": self.player.contribution = random.choice([c(8),c(13),c(18)]) if self.player.type == "LL": if opponent.type == "HH": self.player.contribution = random.choice([c(7),c(12),c(17)]) if opponent.type == "HL": self.player.contribution = random.choice([c(5),c(10),c(15)]) if opponent.type == "LH": self.player.contribution = random.choice([c(6),c(11),c(16)]) if opponent.type == "LL": self.player.contribution = random.choice([c(6),c(11),c(16)]) class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' body_text = "Waiting for other the other participants. Please be patient." class ResultsWaitPage2(WaitPage): after_all_players_arrive = 'my_method' body_text = "Waiting for other the other participants. Please be patient." class Results(Page): """Players payoff: How much each has earned""" def vars_for_template(self): me = self.player opponent = me.other_player() return dict( my_contribution=me.contribution, opponent_contribution=opponent.contribution, my_multiplier=me.multiplier, opponent_multplier=opponent.multiplier, my_endowment = me.endowment, opponent_endowment=opponent.endowment, my_addedtoPGG=me.addedtoPGG, opponent_addedtoPGG=opponent.addedtoPGG, my_type=me.type, opponent_type=opponent.type, my_earnings=me.earnings, my_kept=me.kept, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay ) def get_timeout_seconds(self): if self.participant.vars.get('is_dropout'): return 1 # instant timeout, 1 second else: return 60 def before_next_page(self): if self.timeout_happened: self.player.timeout = True print(self.participant.vars['is_dropout']) class Attention_Check_2_Page(Page): form_model = 'player' form_fields = ['Attention_Check_2'] def is_displayed(self): self.participant.vars['numbs'] = [1, 2, 3, 4] return self.round_number == 16 def vars_for_template(self): me = self.player opponent = me.other_player() import random num = random.choice(self.participant.vars['numbs']) print("num") print(num) return dict( my_contribution=me.contribution, opponent_contribution=opponent.contribution, my_multiplier=me.multiplier, opponent_multplier=opponent.multiplier, my_endowment = me.endowment, opponent_endowment=opponent.endowment, my_addedtoPGG=me.addedtoPGG, opponent_addedtoPGG=opponent.addedtoPGG, my_type=me.type, opponent_type=opponent.type, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay, my_num = num, ) def get_timeout_seconds(self): if self.participant.vars.get('is_dropout'): return 1 # instant timeout, 1 second else: return 30 def before_next_page(self): if self.timeout_happened: self.player.timeout = True self.player.Attention_Check_2 = 0 print("self.player.Attention_Check_2") print(self.player.Attention_Check_2) def app_after_this_page(self, upcoming_apps): #if this is the last round quit the experiment if self.round_number == 16:##change to last round number return "svo" page_sequence = [SetTypes, SetTypes2, Get_multiplier_previous_round, Type_WillBeAssigned, Type_Assign, BeliefsWillStart, BeliefsInstructions, Beliefs, Beliefs_Pref, Set_Beliefs, PGGInstructions, FirstRoundWillStart, Shuffle_Players, Partner_Matched, Shuffle_Groups, Partner_Assigned, Contribute, ResultsWaitPage, ResultsWaitPage2, Results, Attention_Check_2_Page]