from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'private' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 payoff_matrix1_A_X = 6 payoff_matrix1_A_Y = 1 payoff_matrix1_B_XY = 5 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. 1 sei opinion_guess - 0 sei behavior_guess for group in subsession.get_groups(): print('hi') group.remainder = group.id_in_subsession % 2 class Group(BaseGroup): # Remainders: remainder = 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=['£0', '£0.10', '£0.25', '£0.50', '£0.60'], widget=widgets.RadioSelectHorizontal) answer_to_question5 = models.StringField( choices=['Only the participant who became Player X', 'All participants', 'Only the participant who became Player Y']) # 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]) # 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() # PAGES class Prolific_ID(Page): form_model = 'player' form_fields = ['prolificID'] @staticmethod def before_next_page(player, timeout_happened): print('hier', player.group.remainder) 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 Instruction_DecisionTask(Page): pass class Instruction_GuessingTask(Page): pass class Control_Questions(Page): form_model = 'player' form_fields = ['answer_to_question1', 'answer_to_question2', 'answer_to_question3', 'answer_to_question4', 'answer_to_question5'] 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 Part 1. A random draw determines which of the two ' \ 'guesses in Part 1 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 exactly this guessing task (Part 1). ' 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).' if values['answer_to_question4'] != '£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_question5'] != '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.' 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 DecisionMaking_Task(Page): form_model = 'player' form_fields = ['decision'] 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] if player_1.decision == 1: player_1.payoff = 0.6 player_2.payoff = 0.1 else: player_1.payoff = 0.5 player_2.payoff = 0.5 player_1.dictator_payoff = player_1.payoff player_2.dictator_payoff = player_2.payoff player_1.payoff = C.Participation_Fee + player_1.payoff player_2.payoff = C.Participation_Fee + player_2.payoff class Feedback(Page): pass page_sequence = [Prolific_ID, WelcomeStudy, Consent, General_Information, Instruction_DecisionTask, Instruction_GuessingTask, Control_Questions, Guessing_Task_1_1, Guessing_Task_1_0, Guessing_Task_2_1, Guessing_Task_2_0, DecisionMaking_Task, Survey, Survey1, ResultsWaitPage, Feedback]