from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'questionnaire' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 type2 = 2 #1 = control, 2 = treatment class Subsession(BaseSubsession): pass class Group(BaseGroup): def final_payoff_function(group: BaseGroup): ps = group.get_players() for p in ps: p.final_payoff = p.participant.vars.get('payoff_stage4') + p.participant.vars.get('payoff_stage5') def hf(self): for k in self.get_players(): if k.Que7 == "yes": k.show = 1 if k.Que7 == "no": k.show = 0 class Player(BasePlayer): Que1 = models.StringField(label="What is your gender?", choices=["Male", "Female", "Other"]) Que2 = models.StringField(label="What is the highest level of school you have completed or the highest degree you have received?", choices=["High School", "Bachelor Degree", "Master Degree", "PhD"]) Que3 = models.StringField(label="Do you study at the faculty of Economics and Administration (ESF)?", choices=["yes", "no"]) Que4 = models.IntegerField(label="How old are you in years?") Que5 = models.StringField(label="Have you ever felt discriminated against/ excluded in your personal or professional life?", choices=["yes", "no"]) Que6 = models.LongStringField(label="Please shortly describe shortly what drove your money distribution decisions between Beneficiaries 1 and 2; and Beneficiaries 3 and 4 in Stage 5?") Que7 = models.StringField(label="Are you color blind or do you have trouble seeing certain colors?", choices=["yes", "no"]) Que8 = models.StringField(label="Could you see the difference between blue and green jersey?", choices=["yes", "no"]) Que9 = models.StringField(label="Could you see the difference between the red and yellow hat?", choices=["yes", "no"]) show = models.IntegerField(initial=5) final_payoff = models.CurrencyField() # PAGES class InfQ(Page): def vars_for_template(player: Player): return dict( ava_pic=player.participant.vars.get('ava_pic') ) class ResultsWaitPage(WaitPage): def after_all_players_arrive(group: Group): group.final_payoff_function() class QuestionsQ(Page): form_model = 'player' form_fields = ['Que1', 'Que2', 'Que3', 'Que4', 'Que5', 'Que6', 'Que7'] def is_displayed(player: Player): return C.type2 == 2 def vars_for_template(player: Player): return dict( ava_pic=player.participant.vars.get('ava_pic') ) class QuestionsQ2(Page): form_model = 'player' form_fields = ['Que1', 'Que2', 'Que3', 'Que4', 'Que5'] def is_displayed(player: Player): return C.type2 == 1 def vars_for_template(player: Player): return dict( ava_pic=player.participant.vars.get('ava_pic') ) class QuestionsQ3(Page): form_model = 'player' form_fields = ['Que8', 'Que9'] def is_displayed(player: Player): return player.show == 1 def vars_for_template(player: Player): return dict( ava_pic=player.participant.vars.get('ava_pic') ) class Results(Page): def vars_for_template(player: Player): return dict( ava_pic=player.participant.vars.get('ava_pic'), final_payoff=player.final_payoff, payoff_stage4=player.participant.vars.get('payoff_stage4'), payoff_stage5=player.participant.vars.get('payoff_stage5'), corr_answers=player.participant.vars.get('corr_answers'), ) class FinalPage(Page): def vars_for_template(player: Player): return dict( ava_pic=player.participant.vars.get('ava_pic') ) class HpWaitPage(WaitPage): def after_all_players_arrive(group: Group): group.hf() page_sequence = [InfQ, QuestionsQ, QuestionsQ2, HpWaitPage, QuestionsQ3, ResultsWaitPage, Results, FinalPage]