from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'h_a' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 payoff_matrix1_A_X = 6 payoff_matrix1_A_Y = 1 payoff_matrix1_B_XY = 5 belief_opinion_A = 1 # Das muss ich nach der prestudy einstellen belief_behavior_A = 1 # Das ebenso belief_payoff = cu(0.25) Participation_Fee = cu(0.25) class Subsession(BaseSubsession): relevant_guess_opinion = models.BooleanField() def creating_session(subsession): import random subsession.relevant_guess_opinion = random.choice([True, False]) # Hier wird die relevante Schätzfrage bestimmt. 0 sei opinion_guess - 1 sei behavior_guess for group in subsession.get_groups(): print('hi') group.remainder = group.id_in_subsession % 2 group.relevant_matrix = random.choice([1, 2]) # Let 1 be Matrix 1 and 2 be Matrix 2 group.lottery = random.randint(0,100) class Group(BaseGroup): # Remainders: remainder = models.IntegerField() relevant_matrix = models.IntegerField( widget=widgets.RadioSelect, choices=[1, 2] ) lottery = models.IntegerField() class Player(BasePlayer): # Prolific-ID: prolificID = models.StringField() #Treatment treatment_order = models.IntegerField(initial=2) # Consent: consent = models.StringField(widget=widgets.CheckboxInput()) # Control Questions: answer_to_question1 = models.StringField(choices=['£0', '£0.25', '£0.50', '£0.75', '£1.00'], widget=widgets.RadioSelectHorizontal) answer_to_question2 = models.StringField( choices=['...behavior in the decision-making task as I stated in the opinion assessment.', '...option in the guessing task as I stated in the opinion assessment.']) answer_to_question3 = models.StringField( choices=['...behavior in the decision-making task as I stated in the behavior assessment.', '...option in the guessing task as I stated in the behavior assessment.']) answer_to_question4 = models.StringField( choices=['...dependent...', '...independent...']) answer_to_question5 = models.FloatField() answer_to_question6 = models.FloatField() answer_to_question7 = models.StringField(choices=['Me ', 'Opponent'], widget=widgets.RadioSelectHorizontal) answer_to_question8 = models.StringField(choices=['£0', '£0.10', '£0.25', '£0.50', '£0.60'], widget=widgets.RadioSelectHorizontal) answer_to_question9 = models.StringField( choices=['Only the participant who became Player X', 'All participants', 'Only the participant who became Player Y']) answer_to_question10 = models.StringField( choices=['...the payoff consequences of Player Y remain unknown to Player X.', '...Player X can save on costs of revealing the game.', '...matrix 1 will be chosen by the program.']) # Guesses opinion_guess = models.IntegerField( widget=widgets.RadioSelect, choices=[0, 1] ) behavior_guess = models.IntegerField( widget=widgets.RadioSelect, choices=[0, 1] ) # Decision decision = models.IntegerField( label="If you become Player A, which allocation ?", choices=[0, 1, 2, 3]) # 1 is A, 0 is B, 2 means reveal game, 3 is the start dictator_choice = models.IntegerField(choices=[0, 1]) # Reveal Game reveal_game = models.IntegerField( choices=[0, 1] ) # Demographics age = models.IntegerField(min=0, max=150) gender = models.StringField(choices=['Female', 'Male', 'Other'], widget=widgets.RadioSelectHorizontal) income = models.StringField(choices=['<10.000', '10.000-19.999', '20.000-29.999', '30.000-39.999', '40.000-49.999', '50.000-59.999', '60.000-69.999', '70.000-79.999', '80.000-89.999', '90.000-99.999', '100.000<', 'Rather not say']) # Survey1 altruism_1 = models.IntegerField(min=0, max=1000) altruism_2 = models.IntegerField(min=0, max=10) # Payoff dictator_payoff = models.CurrencyField() guess_payoff = models.CurrencyField() # Auction bid = models.CurrencyField() auction_winner = models.CurrencyField() dictator = models.IntegerField() auction_payment = models.CurrencyField() auction_payoff = models.CurrencyField() # PAGES class Prolific_ID(Page): form_model = 'player' form_fields = ['prolificID'] @staticmethod def before_next_page(player, timeout_happened): print('hier', player.group.remainder) player.decision = 3 print(player.decision) if player.group.remainder == 1: print('haddor') player.treatment_order = 1 else: print('haddorasasas') player.treatment_order = 0 class WelcomeStudy(Page): pass class Consent(Page): form_model = 'player' form_fields = ['consent'] class General_Information(Page): pass class Part_A(Page): pass class General_Information_prestudy(Page): pass class Instruction_DecisionTask_earlierstudy(Page): pass class Instruction_GuessingTask_earlierstudy(Page): pass class Part_B(Page): pass class Instruction_GuessingTask(Page): pass class Control_Questions_a(Page): form_model = 'player' form_fields = ['answer_to_question1', 'answer_to_question2', 'answer_to_question3', 'answer_to_question4'] def error_message(self, values): print('values is', values) if values['answer_to_question1'] != '£0.25': return 'The answer to question 1 is not correct. You can maximally earn £0.25 in the guessing task. A random draw determines which of the two ' \ 'guesses is payoff relevant. If you answered the chosen one correctly, you earn £0.25.' if values['answer_to_question2'] != '...option in the guessing task as I stated in the opinion assessment.': return 'The answer to question 2 is not correct. The opinion guess is correct if you correctly guessed the ' \ 'majority\'s choice in the guessing task (Part 1) of the earlier study. ' if values['answer_to_question3'] != '...behavior in the decision-making task as I stated in the behavior assessment.': return 'The answer to question 3 is not correct. The behavior guess is correct if you correctly guessed the ' \ 'majority\'s choice in the decision-making task (Part 2) of the earlier study.' if values['answer_to_question4'] != '...independent...': return 'The answer to question 4 is not correct. A guess in the guessing task is meant to be made independent on whether ' \ 'Player X chose "reveal game".' class Guessing_Task_1_1(Page): @staticmethod def is_displayed(player): return player.treatment_order == 1 form_model = 'player' form_fields = ['opinion_guess'] class Guessing_Task_1_0(Page): @staticmethod def is_displayed(player): return player.treatment_order == 0 form_model = 'player' form_fields = ['behavior_guess'] class Guessing_Task_2_1(Page): @staticmethod def is_displayed(player): return player.treatment_order == 1 form_model = 'player' form_fields = ['behavior_guess'] class Guessing_Task_2_0(Page): @staticmethod def is_displayed(player): return player.treatment_order == 0 form_model = 'player' form_fields = ['opinion_guess'] class Instruction_DecisionTask(Page): pass class Control_Questions_b(Page): form_model = 'player' form_fields = ['answer_to_question5', 'answer_to_question6', 'answer_to_question7', 'answer_to_question8', 'answer_to_question9', 'answer_to_question10'] def error_message(self, values): print('values is', values) if values['answer_to_question5'] != 0.6 : return 'The answer to question 1 is not correct. You lost the auction and do not have to pay any bid.' \ ' Your endowment is £0.6 and neither you, nor your opponent can bid lower than £0 or higher than £0.6. Therefore, ' \ 'you cannot remain with less than £0 and more than £0.6. The highest bidder wins the auction and pays the second-highest bid.' if values['answer_to_question6'] != 0.39 : return 'The answer to question 2 is not correct. Your opponent\'s endowment is £0.6 and neither you, nor your opponent can bid lower than £0 or higher than £0.6. Therefore, ' \ 'they cannot remain with less than £0 and more than £0.6. The highest bidder wins the auction and pays the second-highest bid.' if values['answer_to_question7'] != 'Opponent' : return 'The answer to question 3 is not correct. Your opponent bid more than you, the highest bid wins the auction ' \ 'and has a 90% probability to become Payer X.' if values['answer_to_question8'] != '£0.50': return 'The answer to question 4 is not correct. Player Y can maximally earn £0.50 and at least £0.10.' if values['answer_to_question9'] != 'All participants': return 'The answer to question 5 is not correct. All participants make an allocation decision. After this decision ' \ 'a random draw determines who is attributed the role of Player X. Only Player X\'s decision is implemented.' if values['answer_to_question10'] != '...the payoff consequences of Player Y remain unknown to Player X.': return 'The answer to question 6 is not correct. There are no costs of revealing the game and the program chooses' \ ' between matrix 1 and matrix 2 with equal probability, independent of Player X\'s choice.' class Auction(Page): form_model = 'player' form_fields = ['bid'] class DecisionMaking_Task(Page): form_model = 'player' form_fields = ['decision'] @staticmethod def before_next_page(player, timeout_happened): if player.decision == 2: player.reveal_game = 1 else: player.reveal_game = 0 class DecisionMaking_Task_Revealed(Page): @staticmethod def is_displayed(player): return player.decision == 2 form_model = 'player' form_fields = ['decision'] class Part_C(Page): pass class Survey(Page): form_model = 'player' form_fields = ['age', 'gender', 'income'] class Survey1(Page): form_model = 'player' form_fields = ['altruism_1', 'altruism_2'] class ResultsWaitPage(WaitPage): @staticmethod def after_all_players_arrive(group: Group): print('In der Funktion') player_list = group.get_players() print(group.get_players()) player_1 = player_list[0] player_2 = player_list[1] # auction winner if player_1.bid > player_2.bid: player_1.auction_winner = 1 player_2.auction_winner = 0 if player_2.bid > player_1.bid: player_1.auction_winner = 0 player_2.auction_winner = 1 if player_1.bid == player_2.bid: if Subsession.relevant_guess_opinion == 1: # Hier nutze ich die 1/0-Zufallsvariable der Schätzfrage für Entscheidung über Auction Winner bei Draw. player_1.auction_winner = 1 player_2.auction_winner = 0 else: player_1.auction_winner = 0 player_2.auction_winner = 1 # auction payment if player_1.auction_winner == 1: player_1.auction_payment = player_2.bid player_2.auction_payment = 0 else: player_1.auction_payment = 0 player_2.auction_payment = player_1.bid # Auction payoff if player_1.auction_winner == 1: player_1.auction_payoff = 0.6 - player_2.bid player_2.auction_payoff = 0.6 else: player_1.auction_payoff = 0.6 player_2.auction_payoff = 0.6 - player_1.bid # dictator if group.lottery < 90: if player_1.auction_winner == 1: player_1.dictator = 1 player_2.dictator = 0 else: player_1.dictator = 0 player_2.dictator = 1 else: if player_1.auction_winner == 1: player_1.dictator = 0 player_2.dictator = 1 else: player_1.dictator = 1 player_2.dictator = 0 # dictator choice if player_1.dictator == 1: player_1.dictator_choice = player_1.decision player_2.dictator_choice = player_1.decision else: player_1.dictator_choice = player_2.decision player_2.dictator_choice = player_2.decision if group.relevant_matrix == 1: if player_1.dictator == 1: if player_1.decision == 1: player_1.dictator_payoff = 0.6 player_2.dictator_payoff = 0.1 else: player_1.dictator_payoff = 0.5 player_2.dictator_payoff = 0.5 else: if player_2.decision == 1: player_2.dictator_payoff = 0.6 player_1.dictator_payoff = 0.1 else: player_2.dictator_payoff = 0.5 player_1.dictator_payoff = 0.5 else: if player_1.dictator == 1: if player_1.decision == 1: player_1.dictator_payoff = 0.6 player_2.dictator_payoff = 0.5 else: player_1.dictator_payoff = 0.5 player_2.dictator_payoff = 0.1 else: if player_2.decision == 1: player_2.dictator_payoff = 0.6 player_1.dictator_payoff = 0.5 else: player_2.dictator_payoff = 0.5 player_1.dictator_payoff = 0.1 # Guessing Task Payoff # Player_1 if Subsession.relevant_guess_opinion == 1: if player_1.opinion_guess == C.belief_opinion_A: player_1.guess_payoff = C.belief_payoff else: player_1.guess_payoff = 0 else: if player_1.behavior_guess == C.belief_behavior_A: player_1.guess_payoff = C.belief_payoff else: player_1.guess_payoff = 0 #Player_2 if Subsession.relevant_guess_opinion == 1: if player_2.opinion_guess == C.belief_opinion_A: player_2.guess_payoff = C.belief_payoff else: player_2.guess_payoff = 0 else: if player_2.behavior_guess == C.belief_behavior_A: player_2.guess_payoff = C.belief_payoff else: player_2.guess_payoff = 0 # Total Payoff player_1.payoff = C.Participation_Fee + player_1.dictator_payoff + player_1.auction_payoff + player_1.guess_payoff player_2.payoff = C.Participation_Fee + player_2.dictator_payoff + player_2.auction_payoff + player_2.guess_payoff class Feedback(Page): pass page_sequence = [Prolific_ID, WelcomeStudy, Consent, General_Information, Part_A, General_Information_prestudy, Instruction_DecisionTask_earlierstudy, Instruction_GuessingTask_earlierstudy, Part_B, Instruction_GuessingTask, Control_Questions_a, Guessing_Task_1_1, Guessing_Task_1_0, Guessing_Task_2_1, Guessing_Task_2_0, Instruction_DecisionTask, Control_Questions_b, Auction, DecisionMaking_Task, DecisionMaking_Task_Revealed, Part_C, Survey, Survey1, ResultsWaitPage, Feedback]