from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants authors = 'Sargis Karavardanyan and Grigor Karavardanyan' def common_vars_for_template(page): return dict( my_role=page.player.role(), opponent_role=page.player.other_player().role(), my_color="text-danger font-weight-bold font-italic" if page.player.role() == 'Police' else "text-primary font-weight-bold", my_button_color="btn-danger" if page.player.role() == 'Police' else "btn-primary", opponent_color="text-danger font-weight-bold font-italic" if page.player.role() == 'Protester' else "text-primary font-weight-bold", my_actions=["Low", "High"] if page.player.role() == 'Protester' else ["Repress", "Tolerate"], opponent_actions=["Low", "High"] if page.player.role() == 'Police' else ["Repress", "Tolerate"], my_treatment=page.player.participant.vars['treatment'] if page.player.role() == 'Protester' else None ) class Introduction(Page): timeout_seconds = 180 def vars_for_template(self): return common_vars_for_template(self) def is_displayed(self): return self.round_number == 1 class ImportantNotes(Page): timeout_seconds = 180 def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return common_vars_for_template(self) class Questionnaire(Page): timeout_seconds = 180 form_model = 'player' def get_form_fields(self): return ['q_q{}'.format(i) for i in range(1, 7)] def is_displayed(self): return self.round_number == 1 class SharedDecision(Page): timeout_seconds = 20 form_model = 'player' form_fields = ['decision'] template_name = "signaling/Decision.html" def vars_for_template(self): return common_vars_for_template(self) def before_next_page(self): if self.timeout_happened: if self.player.role() == 'Police': self.player.decision = 'Repress' else: self.player.decision = 'Low' class ProtesterDecision(SharedDecision): def is_displayed(self): return self.player.role() == 'Protester' class WaitForP1(WaitPage): template_name = 'signaling/police_wait_page.html' def vars_for_template(self): return common_vars_for_template(self) def is_displayed(self): return self.player.role() == 'Police' pass class PoliceDecision(SharedDecision): def is_displayed(self): return self.player.role() == 'Police' class WaitForAll(WaitPage): wait_for_all_groups = True # makes everyone in the subsession (20x people) wait after answering a question # this is the only way to make payout increase for all protesters in case they answer high, otherwise sync # is not guaranteed and players may see payout before others have finished making decisions after_all_players_arrive = 'set_payoffs' template_name = 'signaling/protester_wait_page.html' def vars_for_template(self): me = self.player opponent = me.other_player() shared_dict = common_vars_for_template(self) page_dict = dict( my_decision=me.decision, opponent_decision=opponent.decision ) return {**shared_dict, **page_dict} # def is_displayed(self): # return self.round_number == Constants.num_rounds class BlankWaitPage(WaitPage): def is_displayed(self): return self.player.role() == 'Police' and self.player.other_player().decision is None class History(Page): timeout_seconds = 20 def vars_for_template(self): return dict( my_role=self.player.role(), player_in_all_rounds_rev=reversed(self.player.in_all_rounds()) ) class Summary(Page): timeout_seconds = 30 def vars_for_template(self): paying_round = self.session.vars['paying_round'] return dict( final_payoff=self.player.in_round(paying_round).payoff, player_in_all_rounds_rev=reversed(self.player.in_all_rounds()), paying_round=paying_round ) def is_displayed(self): return self.round_number == Constants.num_rounds class PersonalitySurvey(Page): timeout_seconds = 300 form_model = 'player' def get_form_fields(self): return ['ps_q{}'.format(i) for i in range(1, 21)] def is_displayed(self): return self.round_number == Constants.num_rounds class ExitSurvey(Page): timeout_seconds = 180 form_model = 'player' form_fields = [ 'age', 'gender', 'ethnicity', 'ethnicity_other', 'marital_status', 'field_of_study', 'GPA', 'college_classification', 'study_difficulty'] def is_displayed(self): return self.round_number == Constants.num_rounds class PaymentInfo(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): participant = self.participant return dict(redemption_code=participant.label or participant.code) page_sequence = [Introduction, ImportantNotes, Questionnaire, ProtesterDecision, WaitForP1, PoliceDecision, WaitForAll, History, Summary, PersonalitySurvey, ExitSurvey, PaymentInfo]