from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class SetTypes (WaitPage): # def after_all_players_arrive(self): # self.subsession.get_group_matrix() # print(self.subsession.get_group_matrix()) after_all_players_arrive = 'SetType' # wait_for_all_groups = True 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 = "We are waiting for the other participants. We thank you for your patience!" class Type_WillBeAssigned (Page): def is_displayed(self): return self.round_number == 1 class Type_Assign (Page): def is_displayed(self): return self.round_number == 1 class BeliefsWillStart (Page): def is_displayed(self): return self.round_number == 1 class BeliefsInstructions (Page): group_by_arrival_time = True def is_displayed(self): return self.round_number == 1 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, ) class PGGInstructions (Page): def is_displayed(self): return self.round_number == 1 class FirstRoundWillStart (Page): def is_displayed(self): return self.round_number == 1 #class Shuffle_Players (WaitPage): # body_text = "Waiting for 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 Shuffle_Groups (WaitPage): body_text = "We are waiting for the other participants. We thank you for your patience!" after_all_players_arrive = 'do_my_shuffle' wait_for_all_groups = True class Partner_Matched (Page): pass 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 ) 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, opponent_addedtoPGG=opponent.addedtoPGG, my_type=me.type, opponent_type=opponent.type, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay ) class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' body_text = "We are waiting for the other participants to make their decisions. We thank you for your patience!" class Count_Partners (WaitPage): after_all_players_arrive = 'my_method' body_text = "Waiting for 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_earnings=me.earnings, my_kept=me.kept, my_type=me.type, opponent_type=opponent.type, my_typedisplay=me.typedisplay, opponent_typedisplay=opponent.typedisplay ) 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 == 24 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 app_after_this_page(self, upcoming_apps): #if this is the last round quit the experiment if self.round_number == 24:##change to last round number return "svo" page_sequence = [SetTypes, SetTypes2, Get_multiplier_previous_round, Type_WillBeAssigned, Type_Assign, BeliefsWillStart, BeliefsInstructions, Beliefs, PGGInstructions, FirstRoundWillStart, Shuffle_Groups, Count_Partners, Partner_Matched, Partner_Assigned, Contribute, ResultsWaitPage, Results, Attention_Check_2_Page]