from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Part2_Self' PLAYERS_PER_GROUP = None NUM_ROUNDS = 42 SCHEDULE1 = (4, 8, 2, 3, 4, 2, 1, 1, 11, 5, 4, 3, 3, 7, 3, 6, 5, 4, 6, 6, 1, 4, 1, 9, 5, 2, 7, 3, 4, 5, 6, 5, 1, 4, 3, 8, 6, 1, 9, 4, 2, 6, 5, 2, 8, 7, 1, 9, 8, 5, 3, 4, 1, 8, 1, 8, 7, 1, 6, 10, 3, 9, 3) SCHEDULE2 = (7, 2, 5, 5, 5, 5, 6, 6, 1, 1, 5, 3, 5, 3, 5, 1, 7, 5, 6, 1, 6, 2, 5, 7, 2, 8, 4, 5, 4, 5, 5, 2, 5, 5, 9, 1, 4, 5, 7, 2, 6, 4, 8, 5, 2, 3, 9, 5, 5, 1, 9, 10, 1, 3, 4, 2, 10, 5, 4, 8, 6, 3, 6) DOMINANT_CHOICE = (2, 2, 2, 1, 2, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2) VECTOR_DOMINANCE = (False, True, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False) CUMULATIVE_DOMINANCE = (False, False, True, True, False, True, True, False, False, False, True, True, False, False, True, False, True, True, False, True, False) DISCOUNTING_DOMINANCE = (True, False, False, False, True, False, False, True, True, False, False, False, True, True, False, True, False, False, True, False, True) CUMULATIVE_DOMINANCE_SAME_SUM = (False, False, True, False, False, False, True, False, False, False, True, True, False, False, True, False, False, False, False, True, False) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): choice1pay1 = models.IntegerField() choice1pay2 = models.IntegerField() choice1pay3 = models.IntegerField() choice2pay1 = models.IntegerField() choice2pay2 = models.IntegerField() choice2pay3 = models.IntegerField() chosenpay1 = models.IntegerField() chosenpay2 = models.IntegerField() chosenpay3 = models.IntegerField() decision_that_counts_round = models.IntegerField() decision = models.IntegerField(choices=[[1, '1'], [2, '2']], label='Please select which payment schedule you would rather be given, option 1 or option 2.', widget=widgets.RadioSelect) decision_that_counts = models.IntegerField() Is_Dominant = models.BooleanField() vector_dominant = models.BooleanField() cumulatively_dominant = models.BooleanField() discounting_dominant = models.BooleanField() cumulatively_dominant_same_sum = models.BooleanField() disp_rounds = models.IntegerField() decision_explanation = models.LongStringField(label='Please explain your reasoning for making this choice.') number_surveys = models.IntegerField() def set_decision_that_counts_round(player: Player): import random player.decision_that_counts_round = random.randint(1,C.NUM_ROUNDS//2) def set_decision_that_counts(player: Player): for i in range(1,C.NUM_ROUNDS+1): if player.decision_that_counts_round==i: counts=player.in_round(i) player.decision_that_counts=counts.decision def set_chosen(player: Player): if player.decision_that_counts==1: player.chosenpay1=C.SCHEDULE1[3*(player.decision_that_counts_round-1)] player.chosenpay2=C.SCHEDULE1[3*(player.decision_that_counts_round-1)+1] player.chosenpay3=C.SCHEDULE1[3*(player.decision_that_counts_round-1)+2] if player.decision_that_counts==2: player.chosenpay1=C.SCHEDULE2[3*(player.decision_that_counts_round-1)] player.chosenpay2=C.SCHEDULE2[3*(player.decision_that_counts_round-1)+1] player.chosenpay3=C.SCHEDULE2[3*(player.decision_that_counts_round-1)+2] def set_Is_Dominant(player: Player): if player.decision==C.DOMINANT_CHOICE[player.round_number-1]: player.Is_Dominant=1 else: player.Is_Dominant=0 def set_dominance_type(player: Player): r=player.round_number if C.VECTOR_DOMINANCE[r-1]==True: player.vector_dominant=1 player.cumulatively_dominant=0 player.discounting_dominant=0 player.cumulatively_dominant_same_sum=0 if C.CUMULATIVE_DOMINANCE[r-1]==True: player.vector_dominant=0 player.cumulatively_dominant=1 player.discounting_dominant=0 if C.CUMULATIVE_DOMINANCE_SAME_SUM[r-1]==True: player.cumulatively_dominant_same_sum=1 if C.CUMULATIVE_DOMINANCE_SAME_SUM[r-1]==False: player.cumulatively_dominant_same_sum=0 if C.DISCOUNTING_DOMINANCE[r-1]==True: player.vector_dominant=0 player.cumulatively_dominant=0 player.discounting_dominant=1 player.cumulatively_dominant_same_sum=0 def set_disp_rounds(player: Player): player.disp_rounds=C.NUM_ROUNDS//2 class WelcomePart2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): if player.round_number==1: return True else: return False class InstructionsPart2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): if player.round_number==1: return True else: return False @staticmethod def before_next_page(player: Player, timeout_happened): set_disp_rounds(player) class MyWaitPage(WaitPage): @staticmethod def is_displayed(player: Player): if player.round_number==1: return True else: return False class ChoicesPart2(Page): form_model = 'player' form_fields = ['decision'] @staticmethod def is_displayed(player: Player): session = player.session subsession = player.subsession if player.round_number<=C.NUM_ROUNDS/2: for p in subsession.get_players(): player.choice1pay1=C.SCHEDULE1[3*(player.round_number-1)] player.choice1pay2=C.SCHEDULE1[3*(player.round_number-1)+1] player.choice1pay3=C.SCHEDULE1[3*(player.round_number-1)+2] player.choice2pay1=C.SCHEDULE2[3*(player.round_number-1)] player.choice2pay2=C.SCHEDULE2[3*(player.round_number-1)+1] player.choice2pay3=C.SCHEDULE2[3*(player.round_number-1)+2] set_disp_rounds(player) player.number_surveys=0 return True else: return False @staticmethod def before_next_page(player: Player, timeout_happened): set_Is_Dominant(player), set_dominance_type(player) class DecisionThatCounts2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): if player.round_number==C.NUM_ROUNDS//2: return True else: return False @staticmethod def before_next_page(player: Player, timeout_happened): set_decision_that_counts_round(player) set_decision_that_counts(player) set_chosen(player) class MyWaitPage2(WaitPage): @staticmethod def is_displayed(player: Player): if player.round_number==C.NUM_ROUNDS//2: return True else: return False class DecisionThatCounts2Redux(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): if player.round_number==C.NUM_ROUNDS//2: return True else: return False class EndPart2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): if player.round_number==C.NUM_ROUNDS//2: return True else: return False class Part3_Survey(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): if player.round_number==C.NUM_ROUNDS//2+1: return True else: return False class SurveyQuestions(Page): form_model = 'player' form_fields = ['decision_explanation'] @staticmethod def is_displayed(player: Player): session = player.session subsession = player.subsession if player.round_number<=C.NUM_ROUNDS//2: return False else: for p in subsession.get_players(): r=player.round_number-C.NUM_ROUNDS//2 player.choice1pay1=C.SCHEDULE1[3*(r-1)] player.choice1pay2=C.SCHEDULE1[3*(r-1)+1] player.choice1pay3=C.SCHEDULE1[3*(r-1)+2] player.choice2pay1=C.SCHEDULE2[3*(r-1)] player.choice2pay2=C.SCHEDULE2[3*(r-1)+1] player.choice2pay3=C.SCHEDULE2[3*(r-1)+2] relevant_player=player.in_round(r) player.decision=relevant_player.decision player.Is_Dominant=relevant_player.Is_Dominant if player.Is_Dominant==1: prev_player=player.in_round(player.round_number-1) player.number_surveys=0+prev_player.number_surveys return False else: prev_player=player.in_round(player.round_number-1) player.number_surveys=1+prev_player.number_surveys if player.number_surveys<=4: return True if player.number_surveys>4: return False page_sequence = [WelcomePart2, InstructionsPart2, MyWaitPage, ChoicesPart2, DecisionThatCounts2, MyWaitPage2, DecisionThatCounts2Redux, EndPart2, Part3_Survey, SurveyQuestions]