from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, cu, ) from otree.app_template.models import Player import random author = 'Monika Leszczynska' doc = """ Choosing an app and doing the task with an additional tool """ class Constants(BaseConstants): name_in_url = 'matrices' players_per_group = None task_timer = 180 decision_timer = 60 num_rounds = 15 d_total = 20 b_total = 60 total_letters = 80 matrix_rate = cu(0.10) fixed_payoff = cu(1.00) completion_url = "https://app.prolific.co/submissions/complete?cc=558227BA" class Subsession(BaseSubsession): def creating_session(self): n = Constants.total_letters for p in self.get_players(): # create a list of letter choices # ---------------------------------------------------------------------------------------------------------- indices = [j for j in range(1, n + 1)] # create a list corresponding to form_field variables including all choices # ---------------------------------------------------------------------------------------------------------- form_fields = ['choice_' + str(k) for k in indices] # create a list of letters # ---------------------------------------------------------------------------------------------------------- d_list = ['d'] * Constants.d_total b_list = ['b'] * Constants.b_total letters_list = d_list + b_list p.participant.vars['letters_choices'] = list( zip( indices, form_fields, letters_list ) ) p.participant.vars['letters_choices_made'] = [None for j in range(1, n + 1)] if 'treatment' in self.session.config: p.participant.vars['treatment'] = self.session.config['treatment'] else: p.participant.vars['treatment'] = random.choice(['ToolOfferDel', 'GameVersionDel']) p.participant.vars['endgame_second'] = 0 class Group(BaseGroup): pass class Player(BasePlayer): # create fields for the task # ---------------------------------------------------------------------------------------------------------- for j in range(1, Constants.total_letters + 1): locals()['choice_' + str(j)] = models.StringField(blank=True) del j # create fields for self_other questionnaire # ---------------------------------------------------------------------------------------------------------- self_other = models.IntegerField(initial=None) # create fields for trust measure # ---------------------------------------------------------------------------------------------------------- trust = models.IntegerField(initial=None) # create fields for fair offer questionnaire # ---------------------------------------------------------------------------------------------------------- fair_1 = models.IntegerField( choices=[-3, -2, -1, 0, 1, 2, 3], widget=widgets.RadioSelect ) fair_2 = models.IntegerField( choices=[-3, -2, -1, 0, 1, 2, 3], widget=widgets.RadioSelect ) fair_3 = models.IntegerField( choices=[-3, -2, -1, 0, 1, 2, 3], widget=widgets.RadioSelect ) # create fields for quality measure # ---------------------------------------------------------------------------------------------------------- quality_1 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) quality_2 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) # create fields for dispositional suspiciousness measure # ---------------------------------------------------------------------------------------------------------- suspicious_1 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_2 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_3 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_4 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_5 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_6 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_7 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_8 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) suspicious_9 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) # create fields for self efficacy # ---------------------------------------------------------------------------------------------------------- affect = models.StringField() # create fields for motivation and alertness # ---------------------------------------------------------------------------------------------------------- mot_alert1 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) mot_alert2 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) mot_alert3 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelect ) # create fields for reciprocity aversion # create fields for decision making process questionnaire # ---------------------------------------------------------------------------------------------------------- def make_field(label): return models.IntegerField( choices=[ [1, 'Definitely false'], [2, 'Mostly false'], [3, 'Undecided or equally true and false'], [4, 'Mostly true'], [5, 'Definitely true'], ], label=label, widget=widgets.RadioSelect, ) reciprocity_1 = make_field('I’ll never ask for help if I don’t have to, to avoid owing others.') reciprocity_2 = make_field('Usually I don’t accept favors unless I am sure I can pay back all the favors quickly.') reciprocity_3 = make_field('One should not ask for a favor from a friend if he/she is unable to pay it back.') reciprocity_4 = make_field('I avoid asking for favors if I cannot repay the favor.') reciprocity_5 = make_field('When someone offers to help me, I usually reject it if I cannot rid myself of the debt through reciprocation.') reciprocity_6 = make_field('I hesitate to ask for help because then I don’t need to think about what I might give in return.') reciprocity_7 = make_field('When I receive favors from someone, I worry about how to repay them.') reciprocity_8 = make_field('I am often afraid that I cannot reciprocate favors in time.') reciprocity_9 = make_field('I worry about what people will think of me if I fail to reciprocate the favors I received from others.') reciprocity_10 = make_field('Sometimes I think I am too concerned with reciprocating the favors.') reciprocity_11 = make_field('I’m restless and on edge when I owe someone.') # create fields for task time # ---------------------------------------------------------------------------------------------------------- task_timer = models.IntegerField(initial=Constants.task_timer) my_page_timeout_seconds = models.IntegerField(initial=Constants.decision_timer) # create fields for checking correctness of the task # ---------------------------------------------------------------------------------------------------------- d_crossed = models.IntegerField(initial=0) b_crossed = models.IntegerField(initial=0) total_correct = models.IntegerField(initial=0) correct = models.IntegerField(initial=0) is_correct = models.BooleanField(initial=False) # create field for the choice of a tool # ---------------------------------------------------------------------------------------------------------- tool = models.IntegerField(initial=None) # saving all participant vars and creating fields for treatment parameters # ---------------------------------------------------------------------------------------------------------- participant_vars_dump = models.LongStringField() bonus_prolific = models.CurrencyField() treatment = models.StringField() # comments to the study # ---------------------------------------------------------------------------------------------------------- comments = models.LongStringField(blank=True) reasons = models.LongStringField(blank=True) # function to get parameters for the assigned treatment # ---------------------------------------------------------------------------------------------------------- def get_treatment(self): self.treatment = self.participant.vars['treatment'] # function to count the numbers of d and b letters checked in the task # ---------------------------------------------------------------------------------------------------------- def count_effort(self): self.d_crossed = self.participant.vars['letters_choices_made'].count('d') self.b_crossed = self.participant.vars['letters_choices_made'].count('b') # function to check whether the matrix was solved correctly # ---------------------------------------------------------------------------------------------------------- def check_correctness(self): if self.participant.vars['letters_choices_made'].count('d') == Constants.d_total \ and self.participant.vars['letters_choices_made'].count('b') == 0: self.correct = 1 self.is_correct = True else: self.correct = 0 self.is_correct = False # calculating payoffs # ---------------------------------------------------------------------------------------------------------- def calculate_payoff(self): self.payoff = Constants.fixed_payoff + (self.participant.vars["total_correct"] * Constants.matrix_rate) self.bonus_prolific = self.participant.vars['total_correct'] * Constants.matrix_rate print(self.payoff, self.participant.vars['treatment'], self.participant.vars['tool']) # variable needed to display some screens only at the end of the game # ---------------------------------------------------------------------------------------------------------- def update_endgame_second(self): self.participant.vars['endgame_second'] = 1 print(self.participant.vars['endgame_second'])