from . import models from ._builtin import Page, WaitPage from .models import Constants def vars_for_all_templates(self): return { 'lottery_a_hi': Constants.lottery_a_hi, 'lottery_b_hi': Constants.lottery_b_hi, 'lottery_a_lo': Constants.lottery_a_lo, 'lottery_b_lo': Constants.lottery_b_lo } # ******************************************************************************************************************** # # *** CLASS INSTRUCTIONS *** # # ******************************************************************************************************************** # class Start(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): return { 'audio_path': 'oyun3bolum4.mp3', } class AutonomyChoice(Page): def is_displayed(self): return self.subsession.round_number == 1 form_model = 'player' form_fields = ['first_autonomy_choice'] def vars_for_template(self): return { 'audio_path': 'oyun3bolum4kurallar.mp3', } def before_next_page(self): self.participant.vars['choice_mpla1'] = self.player.first_autonomy_choice self.participant.vars['choice_neg'] = self.player.first_autonomy_choice class AutonomyChoice2(Page): def is_displayed(self): return self.subsession.round_number == 1 and self.player.first_autonomy_choice == 2 form_model = 'player' form_fields = ['second_autonomy_choice'] def before_next_page(self): self.participant.vars['choice_neg'] = self.player.second_autonomy_choice class Instructions_n(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 and self.participant.vars['choice_neg'] == 1 def vars_for_template(self): return { 'num_choices': len(self.participant.vars['mpla_choices_n']) } class Instructions_p(Page): # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 and self.participant.vars['choice_neg'] == 0 def vars_for_template(self): return { 'num_choices': len(self.participant.vars['mpla_choices_p']) } class ComprehensionCheck(Page): def is_displayed(self): return self.subsession.round_number == 1 form_model = 'player' form_fields = ['comp_checkA', 'comp_checkB'] class ComprehensionCheckFail(Page): def is_displayed(self): return self.subsession.round_number == 1 form_model = 'player' def is_displayed(self): return self.player.comp_checkA == 0 or self.player.comp_checkB == 1 # ******************************************************************************************************************** # # *** PAGE DECISION *** # # ******************************************************************************************************************** # class MplAutonomyNeg(Page): def is_displayed(self): return self.participant.vars['choice_neg'] == 1 # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' # form fields # ---------------------------------------------------------------------------------------------------------------- def get_form_fields(self): # unzip list of form_fields from list form_fields = [list(t) for t in zip(*self.participant.vars['mpla_choices_n'])][1] # provide form field associated with pagination or full list if Constants.one_choice_per_page: page = self.subsession.round_number return [form_fields[page - 1]] else: return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): # specify info for progress bar total = len(self.participant.vars['mpla_choices_n']) + 1 page = self.subsession.round_number + 1 progress = page / total * 100 if Constants.one_choice_per_page: return { 'page': page, 'total': total, 'progress': progress, 'choices': [self.player.participant.vars['mpla_choices_n'][self.subsession.round_number - 1]] } else: return { 'choices': self.player.participant.vars['mpla_choices_n'] } # set player's payoff # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list round_number = self.subsession.round_number form_fields = [list(t) for t in zip(*self.participant.vars['mpla_choices_n'])][1] indices = [list(t) for t in zip(*self.participant.vars['mpla_choices_n'])][0] index = indices[round_number - 1] # if choices are displayed sequentially # ------------------------------------------------------------------------------------------------------------ if Constants.one_choice_per_page: # replace current choice in current_choice = getattr(self.player, form_fields[round_number - 1]) self.participant.vars['mpla_choices_made'][index - 1] = current_choice # if current choice equals index to pay ... if index == self.player.participant.vars['mpla_index_to_pay']: # # set payoff self.player.set_payoffs() # after final choice if round_number == Constants.num_choices: # determine consistency self.player.set_consistency() # set switching row self.player.set_switching_row() # if choices are displayed in tabular format # ------------------------------------------------------------------------------------------------------------ if not Constants.one_choice_per_page: # replace choices in for j, choice in zip(indices, form_fields): choice_i = getattr(self.player, choice) self.participant.vars['mpla_choices_made'][j - 1] = choice_i # set payoff self.player.set_payoffs() # determine consistency self.player.set_consistency() # set switching row self.player.set_switching_row() class MplAutonomyPos(Page): def is_displayed(self): return self.participant.vars['choice_neg'] == 0 # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' # form fields # ---------------------------------------------------------------------------------------------------------------- def get_form_fields(self): # unzip list of form_fields from list form_fields = [list(t) for t in zip(*self.participant.vars['mpla_choices_p'])][1] # provide form field associated with pagination or full list if Constants.one_choice_per_page: page = self.subsession.round_number return [form_fields[page - 1]] else: return form_fields # variables for template # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): # specify info for progress bar total = len(self.participant.vars['mpla_choices_p']) +1 page = self.subsession.round_number +1 progress = page / total * 100 if Constants.one_choice_per_page: return { 'page': page, 'total': total, 'progress': progress, 'choices': [self.player.participant.vars['mpla_choices_p'][self.subsession.round_number - 1]] } else: return { 'choices': self.player.participant.vars['mpla_choices_p'] } # set player's payoff # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list round_number = self.subsession.round_number form_fields = [list(t) for t in zip(*self.participant.vars['mpla_choices_p'])][1] indices = [list(t) for t in zip(*self.participant.vars['mpla_choices_p'])][0] index = indices[round_number - 1] # if choices are displayed sequentially # ------------------------------------------------------------------------------------------------------------ if Constants.one_choice_per_page: # replace current choice in current_choice = getattr(self.player, form_fields[round_number - 1]) self.participant.vars['mpla_choices_made'][index - 1] = current_choice # if current choice equals index to pay ... if index == self.player.participant.vars['mpla_index_to_pay']: # # set payoff self.player.set_payoffs() # after final choice if round_number == Constants.num_choices: # determine consistency self.player.set_consistency() # set switching row self.player.set_switching_row() # if choices are displayed in tabular format # ------------------------------------------------------------------------------------------------------------ if not Constants.one_choice_per_page: # replace choices in for j, choice in zip(indices, form_fields): choice_i = getattr(self.player, choice) self.participant.vars['mpla_choices_made'][j - 1] = choice_i # set payoff self.player.set_payoffs() # determine consistency self.player.set_consistency() # set switching row self.player.set_switching_row() # ******************************************************************************************************************** # # *** PAGE RESULTS *** # # ******************************************************************************************************************** # class ResultsWaitPage(WaitPage): def is_displayed(self): return self.subsession.round_number == Constants.num_rounds def after_all_players_arrive(self): self.group.set_payments() # class Results(Page): # # skip results until last page # # ---------------------------------------------------------------------------------------------------------------- # def is_displayed(self): # if Constants.one_choice_per_page: # return self.subsession.round_number == Constants.num_rounds # else: # return True # # variables for template # # ---------------------------------------------------------------------------------------------------------------- # def vars_for_template(self): # # unzip into list of lists # choices = [list(t) for t in zip(*self.participant.vars['mpla_choices'])] # indices = choices[0] # # get index, round, and choice to pay # index_to_pay = self.player.participant.vars['mpla_index_to_pay'] # round_to_pay = indices.index(index_to_pay) + 1 # choice_to_pay = self.participant.vars['mpla_choices'][round_to_pay - 1] # if Constants.one_choice_per_page: # return { # 'choice_to_pay': [choice_to_pay], # 'option_to_pay': self.player.in_round(round_to_pay).option_to_pay, # 'payoff': self.player.in_round(round_to_pay).payoff, # } # else: # return { # 'choice_to_pay': [choice_to_pay], # 'option_to_pay': self.player.option_to_pay, # 'payoff': self.player.payoff # } class End(Page): # only display instruction in round 16 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == Constants.num_rounds # def before_next_page(self): # self.player.set_payoffs() # ******************************************************************************************************************** # # *** PAGE SEQUENCE *** # # ******************************************************************************************************************** # page_sequence = [ Start, AutonomyChoice, AutonomyChoice2, # Instructions_n, # Instructions_p, # Introduction, MplAutonomyNeg, MplAutonomyPos, ResultsWaitPage # End ]