import random from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Jakob Moeller' doc = """ Delegation decision. """ import statistics class Constants(BaseConstants): name_in_url = 'main' players_per_group = None num_rounds = 1 scoringrule_template = 'main/scoringrule.html' scoringrule_other_template = 'main/scoringrule_other.html' histogram_template = 'main/histogram.html' old_session_scores = [13, 8, 5, 5, 8, 3, 10, 8, 9, 8, 6, 10, 8, 12, 10, 7, 7, 8, 9, 7, 11, 7, 15, 12, 2, 8, 12, 6, 6, 13, 8, 7, 4, 5, 7] old_session_median = statistics.median(old_session_scores) percentile = 80 class Subsession(BaseSubsession): def creating_session(self): # Set treatment if 'treatment' in self.session.config: for p in self.get_players(): p.treatment = self.session.config['treatment'] else: print("Randomly assigning treatments.") import itertools seq = ['before', 'after'] random.shuffle(seq) treatments = itertools.cycle(seq) for p in self.get_players(): p.treatment = next(treatments) # Set order of answers to delegation question. print("Setting answer order.") import itertools seq = ['A', 'A', 'B', 'B'] orders = itertools.cycle(seq) for p in self.get_players(): p.order = next(orders) # Randomly pick question that will be paid. print("Determining payoff-relevant question.") num_questions = 8 if Constants.percentile < 50: questions = range(1, num_questions + 1) else: questions = [1, 2, 3, 4, 6, 7, 8] # Question 5 will not be answered. for p in self.get_players(): p.payoff_question = random.choice(questions) print("Payoff-relevant question is question number", p.payoff_question) class Group(BaseGroup): pass def make_field(label): return models.CharField( choices=['Yes', 'No'], label=label, widget=widgets.RadioSelect, ) def make_field2(label): return models.IntegerField( choices=[ [1, "Your performance"], [2, "Counterpart's performance"], ], label=label, widget=widgets.RadioSelectHorizontal, ) class Player(BasePlayer): treatment = models.CharField(initial='') order = models.CharField(initial='') payoff_question = models.IntegerField() final_score = models.IntegerField() estimate1 = models.IntegerField(label='', min=0, max=20) estimate_other = models.IntegerField(label='', min=0, max=20) estimate2 = models.IntegerField(label='', min=0, max=20) prob_top50_1 = models.IntegerField() prob_top50_other = models.IntegerField() prob_top50_2 = models.IntegerField() read_scoringrule1 = models.BooleanField(initial=False) has_read_scoringrule1 = models.BooleanField(initial=False) read_scoringrule2 = models.BooleanField(initial=False) has_read_scoringrule2 = models.BooleanField(initial=False) read_scoringrule3 = models.BooleanField(initial=False) has_read_scoringrule3 = models.BooleanField(initial=False) click_time1 = models.FloatField(blank=True) click_time2 = models.FloatField(blank=True) click_time3 = models.FloatField(blank=True) score_other = models.IntegerField() top50_other = models.BooleanField() choice = models.IntegerField(label='', widget=widgets.RadioSelect) delegate = models.BooleanField() threshold = models.IntegerField() determine_payoff_later = models.BooleanField(initial=False) q1 = make_field("Did you know before estimating the counterpart's performance that there will be a chance to be paid based on the performance of your counterpart?") q2 = make_field("Did you expect feedback at the end of the experiment on how well you performed in counting 1s?") q3 = models.IntegerField( choices=[ [1, "This person will play again and you will be paid based on this performance?"], [2, "You will be paid based on his/her earlier session?"] ], label="If you decided that you will be paid based on the performance of the counterpart, does this mean that:", widget=widgets.RadioSelect ) q4 = models.LongStringField( label="Were there any parts of the instruction that you found unclear or confusing? If yes, could you describe the problem:", initial="", blank=True, ) q5 = make_field("Have you used pen and paper or other tools for the task?") q6 = make_field("Were there any matrices where you just simply guessed the number?") q7 = make_field("Did you make the mistake of counting 0s instead of 1s?") q8 = models.IntegerField( choices=range(1, 6), widget=widgets.RadioSelectHorizontal, label="You had 5 minutes to work on the task. How many minutes did you actually work?" ) q9 = models.IntegerField( choices=[ [1, "1: very easy"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9: very difficult"] ], widget=widgets.RadioSelectHorizontal, label='How difficult was the counting ones task for you?' ) q10 = models.IntegerField( choices=[ [1, "1: not confident"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9: very confident"] ], widget=widgets.RadioSelectHorizontal, label='How confident are you that you remember the number of matrices you have tried?' ) q11 = models.IntegerField( min=0, label="How many matrices do you think you have tried to solve?" ) q12 = models.IntegerField( choices=[ [1, "1: very poorly"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9: very well"] ], widget=widgets.RadioSelectHorizontal, label='How well do you think you perform on intelligence tasks in general? ' ) q13 = models.LongStringField( label="Walk us through your thought-process of guessing your performance." ) q14 = models.LongStringField( label="Is there anything else you would like to share with us?", initial="", blank=True, ) q15 = models.LongStringField( label="How did you decide whether you want to be paid based on the performance of your counterpart or not?" ) q16 = models.CharField( choices=[ "10%?", "20%?", "30%?", "40%?", "60%?", "80%?", "I don't remember", ], label="Your counterpart was chosen from a group who performed among the best. Was this group with the best:", widget=widgets.RadioSelect ) q17 = make_field2("Your counterpart is drawn from the best 10%") q18 = make_field2("Your counterpart is drawn from the best 20%") q19 = make_field2("Your counterpart is drawn from the best 30%") q20 = make_field2("Your counterpart is drawn from the best 40%") q21 = make_field2("Your counterpart is drawn from the best 50%") q22 = make_field2("Your counterpart is drawn from the best 60%") q23 = make_field2("Your counterpart is drawn from the best 70%") q24 = make_field2("Your counterpart is drawn from the best 80%") q25 = make_field2("Your counterpart is drawn from the best 90%") q26 = make_field2("Your counterpart is drawn from the best 100%") q27 = models.IntegerField( choices=[ [1, "is in charge."], [2, "following the ideas of others."] ], label="In a group I am usually the one who:", widget=widgets.RadioSelect ) def choice_choices(self): if self.order == 'A': choices = [ [1, 'I want to be paid based on the previous performance of the counterpart.'], [2, 'I want to be paid based on my own previous performance.'], ] else: choices = [ [2, 'I want to be paid based on my own previous performance.'], [1, 'I want to be paid based on the previous performance of the counterpart.'], ] return choices def set_error_message_slider(self, value): slider = list(value.items())[1][1] print('Slider value:', slider) text = 'Please indicate how confident you are that your performance is among the top 50% of all the performances.' if slider == 999: print("Saving slider error to participant vars.") self.participant.vars['forgot_slider'] = True return text else: self.participant.vars['read_scoringrule1'] = self.read_scoringrule1 self.participant.vars['read_scoringrule2'] = self.read_scoringrule2 self.participant.vars['read_scoringrule3'] = self.read_scoringrule3