from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Welcome(Page): def is_displayed(self): if self.round_number == 1: self.participant.vars['belief_payoff'] = 0 return self.round_number == 1 class Instructions(Page): def vars_for_template(self): return {'role_change': self.session.config['role_change']} def is_displayed(self): return self.round_number == 1 class Test(Page): def is_displayed(self): return self.round_number == 1 class Beliefs(Page): form_model = 'player' form_fields = ['belief_sender', 'belief_receiver'] def is_displayed(self): return self.round_number in [Constants.belief_round, Constants.num_rounds/2 - Constants.belief_round, Constants.num_rounds/2 + Constants.belief_round, Constants.num_rounds - Constants.belief_round] def before_next_page(self): self.player.set_belief_payoffs() self.participant.vars['belief_payoff'] = self.participant.vars['belief_payoff'] + self.player.belief_payoff # print(self.participant.vars['belief_payoff']) # print(self.player.belief_payoff) # for p in self.session.get_participants(): # p.vars['belief_payoff'] = p.vars['belief_payoff'] + self.player.belief_payoff # print(self.participant.vars['belief_payoff']) def vars_for_template(self): return {'previous': Constants.belief_round - 1} class Sender(Page): form_model = 'group' form_fields = ['message'] def is_displayed(self): return self.player.role() == 'sender' def vars_for_template(self): sender_table, receiver_table = self.subsession.payoff_matrices() return{'sender_matrix': sender_table, 'receiver_matrix': receiver_table, 'image_path': 'sender_receiver/{}.gif'.format(self.group.state) } class WaitForSender(WaitPage): title_text = "Please wait" body_text = "Waiting for player A to send a message." class Receiver(Page): form_model = 'group' form_fields = ['action'] def is_displayed(self): return self.player.role() == 'receiver' def vars_for_template(self): sender_table, receiver_table = self.subsession.payoff_matrices() return{'sender_matrix': sender_table, 'receiver_matrix': receiver_table} class ResultsWaitPage(WaitPage): title_text = "Please wait" body_text = "Waiting for player B to choose an action." def after_all_players_arrive(self): self.group.set_payoffs() self.group.information_group() class Results(Page): def vars_for_template(self): sender_table, receiver_table = self.subsession.payoff_matrices() if self.round_number in [2, Constants.num_rounds/2 - 2, Constants.num_rounds/2 + 2, Constants.num_rounds - 2]: return {'sender_matrix': sender_table, 'receiver_matrix': receiver_table, 'truth': self.subsession.in_round(self.round_number - 1).truth_running, 'follow': self.subsession.in_round(self.round_number - 1).followed_running} else: return {'sender_matrix': sender_table, 'receiver_matrix': receiver_table} class WaitSubsession(WaitPage): title_text = "Please wait" body_text = "Waiting for next round to begin." wait_for_all_groups = True def after_all_players_arrive(self): self.subsession.information() if self.round_number == Constants.num_rounds: for p in self.session.get_participants(): p.vars['game_payoff'] = p.payoff print(p.vars['game_payoff']) print(p.vars['belief_payoff']) class WaitInstructions(WaitPage): title_text = "Please wait" body_text = "Waiting for first round to begin." wait_for_all_groups = True page_sequence = [ Welcome, Instructions, Test, WaitInstructions, Beliefs, Sender, WaitForSender, Receiver, ResultsWaitPage, Results, WaitSubsession]