from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class initial_agent(Page): template_name = 'platform_demo/initial.html' form_model = 'player' form_fields = ['background_agent','first_bid_agent'] def is_displayed(self): return self.round_number == 1 and self.player.role == Constants.role_agent class initial_principal(Page): template_name = 'platform_demo/initial.html' form_model = 'player' form_fields = ['background_principal','first_bid_principal'] def is_displayed(self): return self.round_number == 1 and self.player.role == Constants.role_principal class InitialWaitPage(WaitPage): after_all_players_arrive = 'define_background' def is_displayed(self): return self.group.case_solved == False class bid_agent_1_visible(Page): template_name = 'platform_demo/bid_agent.html' form_model = 'player' form_fields = ['visible_bid','visible_cut'] def is_displayed(self): return self.round_number == 1 and self.player.role == Constants.role_agent def vars_for_template(self): return { 'cake_width': Constants.cake_width, 'visibility': 'visible', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, num_round = self.player.round_number, role = 'agent', visibility = 'visible', ) class bid_agent_1_secret(Page): template_name = 'platform_demo/bid_agent.html' form_model = 'player' form_fields = ['secret_bid','secret_cut'] def is_displayed(self): return self.round_number == 1 and self.player.role == Constants.role_agent def vars_for_template(self): return { 'cake_width': Constants.cake_width, 'visibility': 'secret', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, this_visible_cut=self.player.visible_cut, this_visible_bid=self.player.visible_bid, num_round=self.player.round_number, role='agent', visibility='secret', ) class bid_agent_n_visible(Page): template_name = 'platform_demo/bid_agent.html' form_model = 'player' form_fields = ['visible_bid', 'visible_cut'] def is_displayed(self): return self.round_number > 1 and self.group.case_solved == 0 and self.player.role == Constants.role_agent def vars_for_template(self): return { 'last_agent_cut': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_cut, 'last_principal_cut': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_cut, 'last_agent_bid': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_bid, 'last_principal_bid': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_bid, 'initial_spectrum': self.group.in_round(1).visible_spectrum, 'visibility': 'visible', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, last_agent_cut_visible = self.player.in_round(self.round_number - 1).visible_cut, last_agent_bid_visible = self.player.in_round(self.round_number - 1).visible_bid, last_agent_cut_secret = self.player.in_round(self.round_number - 1).secret_cut, last_agent_bid_secret = self.player.in_round(self.round_number - 1).secret_bid, last_principal_bid = self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_bid, last_principal_cut=self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_cut, num_round=self.player.round_number, role='agent', visibility='visible', ) class bid_agent_n_secret(Page): template_name = 'platform_demo/bid_agent.html' form_model = 'player' form_fields = ['secret_bid', 'secret_cut'] def is_displayed(self): return self.round_number > 1 and self.group.case_solved == 0 and self.player.role == Constants.role_agent def vars_for_template(self): return { 'last_agent_cut': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_cut, 'last_principal_cut': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_cut, 'last_agent_bid': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_bid, 'last_principal_bid': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_bid, 'initial_spectrum': self.group.in_round(1).visible_spectrum, 'visibility': 'secret', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, last_agent_cut_visible = self.player.in_round(self.round_number - 1).visible_cut, last_agent_cut_secret = self.player.in_round(self.round_number - 1).secret_cut, last_agent_bid_visible = self.player.in_round(self.round_number - 1).visible_bid, last_agent_bid_secret = self.player.in_round(self.round_number - 1).secret_bid, last_principal_cut = self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_cut, last_principal_bid_visible = self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_bid, this_visible_cut = self.player.visible_cut, this_visible_bid = self.player.visible_bid, num_round=self.player.round_number, role='agent', visibility='secret', ) class bid_principal_1_visible(Page): template_name = 'platform_demo/bid_principal.html' form_model = 'player' form_fields = ['visible_bid','visible_cut'] def is_displayed(self): return self.round_number == 1 and self.player.role == Constants.role_principal def vars_for_template(self): return { 'cake_width': Constants.cake_width, 'visibility': 'visible', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, num_round=self.player.round_number, role='principal', visibility='visible', ) class bid_principal_1_secret(Page): template_name = 'platform_demo/bid_principal.html' form_model = 'player' form_fields = ['secret_bid','secret_cut'] def is_displayed(self): return self.round_number == 1 and self.player.role == Constants.role_principal def vars_for_template(self): return { 'cake_width': Constants.cake_width, 'visibility': 'secret', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, this_visible_cut=self.player.visible_cut, this_visible_bid=self.player.visible_bid, num_round=self.player.round_number, role='principal', visibility='secret', ) class bid_principal_n_visible(Page): template_name = 'platform_demo/bid_principal.html' form_model = 'player' form_fields = ['visible_bid', 'visible_cut'] def is_displayed(self): return self.round_number > 1 and self.group.case_solved == 0 and self.player.role == Constants.role_principal def vars_for_template(self): return { 'last_agent_cut': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_cut, 'last_principal_cut': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_cut, 'last_agent_bid': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_bid, 'last_principal_bid': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_bid, 'initial_spectrum': self.group.in_round(1).visible_spectrum, 'visibility': 'visible', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, last_agent_cut=self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_cut, last_agent_bid=self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_bid, last_principal_cut_visible = self.player.in_round(self.round_number - 1).visible_cut, last_principal_bid_visible = self.player.in_round(self.round_number - 1).visible_bid, last_principal_cut_secret = self.player.in_round(self.round_number - 1).secret_cut, last_principal_bid_secret = self.player.in_round(self.round_number - 1).secret_bid, num_round=self.player.round_number, role='principal', visibility='visible', ) class bid_principal_n_secret(Page): template_name = 'platform_demo/bid_principal.html' form_model = 'player' form_fields = ['secret_bid', 'secret_cut'] def is_displayed(self): return self.round_number > 1 and self.group.case_solved == 0 and self.player.role == Constants.role_principal def vars_for_template(self): return { 'last_agent_cut': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_cut, 'last_principal_cut': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_cut, 'last_agent_bid': self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_bid, 'last_principal_bid': self.group.get_player_by_role(Constants.role_principal).in_round(self.round_number - 1).visible_bid, 'initial_spectrum': self.group.in_round(1).visible_spectrum, 'visibility': 'secret', } def js_vars(self): return dict( first_bid_agent = self.player.first_bid_agent, first_bid_principal = self.player.first_bid_principal, initial_spectrum = self.group.in_round(1).visible_spectrum, cake_width = Constants.cake_width, last_agent_cut=self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_cut, last_agent_bid=self.group.get_player_by_role(Constants.role_agent).in_round(self.round_number - 1).visible_bid, last_principal_cut_visible = self.player.in_round(self.round_number - 1).visible_cut, last_principal_cut_secret = self.player.in_round(self.round_number - 1).secret_cut, last_principal_bid_visible = self.player.in_round(self.round_number - 1).visible_bid, last_principal_bid_secret = self.player.in_round(self.round_number - 1).secret_bid, this_visible_cut=self.player.visible_cut, this_visible_bid=self.player.visible_bid, num_round=self.player.round_number, role='principal', visibility='secret', ) class RoundWaitPage(WaitPage): after_all_players_arrive = 'define_settlement' def is_displayed(self): return self.group.case_solved == 0 class result_solved(Page): def is_displayed(self): return self.round_number == 1 and self.group.case_solved == 1\ or self.round_number == 2 and self.group.case_solved == 1 and self.group.in_round(1).case_solved == 0\ or self.round_number == 3 and self.group.case_solved == 1 and self.group.in_round(2).case_solved == 0 class result_suggested(Page): form_model = 'player' form_fields = ['settlement_accepted'] def is_displayed(self): return self.round_number == 3 and self.group.case_solved == 0 class resultWaitPage(WaitPage): def after_all_players_arrive(self): pass def is_displayed(self): return self.round_number == 3 and self.group.case_solved == 0 class result_suggestion_accepted(Page): def is_displayed(self): return self.round_number == 3 and self.group.case_solved == 0 and \ self.group.get_player_by_role(Constants.role_agent).settlement_accepted == 1 and\ self.group.get_player_by_role(Constants.role_principal).settlement_accepted == 1 class result_suggestion_not_accepted(Page): def is_displayed(self): return self.round_number == 3 and self.group.case_solved == 0 and\ self.group.get_player_by_role(Constants.role_agent).settlement_accepted == 0 or\ self.round_number == 3 and self.group.case_solved == 0 and\ self.group.get_player_by_role(Constants.role_principal).settlement_accepted == 0 page_sequence = [ initial_agent, initial_principal, InitialWaitPage, bid_agent_1_visible, bid_agent_1_secret, bid_agent_n_visible, bid_agent_n_secret, bid_principal_1_visible, bid_principal_1_secret, bid_principal_n_visible, bid_principal_n_secret, RoundWaitPage, result_solved, result_suggested, resultWaitPage, result_suggestion_accepted, result_suggestion_not_accepted, ]