from otree.api import * import random import itertools import time from random import choice doc = """ """ class C(BaseConstants): NAME_IN_URL = 'dictator' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 typo10 = 10 typo30 = 30 endow = 7 class Subsession(BaseSubsession): pass def creating_session(subsession): # treatments for p in subsession.get_players(): p.Prolific_ID = p.participant.label if p.id_in_subsession: pressures = itertools.cycle([0,0,1,1,2,2]) for player in subsession.get_players(): player.code_treatment = next(pressures) if p.code_treatment == 0: p.treatment = "notypo" elif p.code_treatment == 1: p.treatment = "typo10" elif p.code_treatment == 2: p.treatment = "typo30" for p in subsession.get_players(): if p.id_in_subsession: pressures2 = itertools.cycle([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10,]) for player in subsession.get_players(): player.codetext = next(pressures2) if player.codetext == 1: player.text = 1 elif player.codetext == 2: player.text = 2 elif player.codetext == 3: player.text = 3 elif player.codetext == 4: player.text = 4 elif player.codetext == 5: player.text = 5 elif player.codetext == 6: player.text = 6 elif player.codetext == 7: player.text = 7 elif player.codetext == 8: player.text = 8 elif player.codetext == 9: player.text = 9 elif player.codetext == 10: player.text = 10 for player in subsession.get_players(): if player.id_in_group == 1: player.type = 'sender' elif player.id_in_group == 2: player.type = 'receiver' # treatment in player section class Group(BaseGroup): pass class Player(BasePlayer): inputvalue = models.LongStringField() calc_page_start = models.FloatField() calc_page_duration = models.FloatField() belief = models.FloatField(label='', min=0, max=7) allocate = models.FloatField(label='', min=0, max=7) endowment = models.IntegerField() t_rand = models.FloatField() correct = models.IntegerField(initial=0) wrong = models.IntegerField(initial=0) blank = models.IntegerField(initial=0) code_treatment = models.IntegerField() treatment = models.StringField() codetext = models.IntegerField() text = models.IntegerField() type = models.StringField() Prolific_ID = models.StringField( label="Prolific ID", ) control_question = models.StringField( choices=[ ['1', 'I agree to take part. Take me to the study.'], ['2', 'I do not agree to take part in this study. Take me back to Prolific.'], ], label="Do you agree to participate in this study?", widget=widgets.RadioSelect ) gender = models.StringField( choices=[ ['1', 'Male'], ['2', 'Female'], ['3', 'Other'], ], label="1. What is your gender?", widget=widgets.RadioSelect ) age = models.IntegerField( label="2. What is your age?", min=0, max=120 ) language = models.StringField( choices=[ ['1', 'Yes'], ['2', 'No'], ], label="3. Is English your first language?", widget=widgets.RadioSelect ) max_income = models.StringField( choices=[ ['1', 'Very important'], ['2', 'Important'], ['3', 'Indifferent'], ['4', 'Not important'], ['5', 'Not important at all'], ], label="4. How important was it for you to maximise your own income during the experiment?", widget=widgets.RadioSelect ) trust = models.StringField( choices=[ ['1', 'Most people can be trusted'], ['2', 'You need to be very careful in dealing with people'], ], label="5. Generally speaking, would you say that most people can be trusted or that you need to be very " "careful in dealing with people?", widget=widgets.RadioSelect ) risk = models.StringField( choices=[ ['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', ''], ['8', ''], ['9', ''], ['10', ''], ], label="", widget=widgets.RadioSelectHorizontal ) instructions = models.StringField( choices=[ ['1', 'Very difficult'], ['2', 'Difficult'], ['3', 'Neutral'], ['4', 'Easy'], ['5', 'Very easy'], ], label="7. How did you find the instructions?", widget=widgets.RadioSelect ) econ_exp = models.IntegerField( label="8. How many economics experiments have you participated in before this one? ", ) feedback = models.StringField( blank=True, label="9. Do you have any other comments or feedback regarding this experiment?", ) def control_question_error_message(player,value): correct_answer = '1' if value != correct_answer: error_message = "If you do not agree to take part in this study, please close your browser tab." return error_message def allocate_error_message(player, value): if value != round(value,1): return "The number you input is up to 1 decimal" def belief_error_message(player, value): if value != round(value,1): return "The number you input is up to 1 decimal" class Welcome(Page): form_model = 'player' form_fields = ['control_question'] class ProlificID(Page): form_model = 'player' form_fields = ['Prolific_ID'] class General_Instructions(Page): pass class Instructions(Page): pass class countdown(Page): form_model = 'player' timer_text = 'Your task will begin in' @staticmethod def get_timeout_seconds(player): session = player.session return session.config['timePreTask'] / 1000 def before_next_page(player: Player, timeout_happened): player.participant.vars['expiry'] = time.time() + (2 * 30) @staticmethod def before_next_page(player, timeout_happened): import time player.calc_page_start = time.time() class Task(Page): form_model = 'player' timer_text = 'Time remaining' def get_timeout_seconds(player): session = player.session return session.config['timeGlobal'] / 1000 @staticmethod def live_method(player, data): # Check the type of count in the data count_type = data.get('count_type', None) if count_type == 'correct': # Update the correct count player.correct = data.get('count_value', 0) elif count_type == 'wrong': # Update the wrong count player.wrong = data.get('count_value', 0) elif count_type == 'blank': # Update the blank count player.blank = data.get('count_value', 0) input_value = data.get('input_value', None) player.inputvalue = input_value @staticmethod def before_next_page(player, timeout_happened): import time player.calc_page_duration = time.time() - player.calc_page_start def vars_for_template(player: Player): if player.treatment == "notypo": player.endowment = C.endow class Feedback(Page): def is_displayed(player: Player): if player.treatment == "typo10" or player.treatment == "typo30": return True else: return False def vars_for_template(player: Player): if player.treatment == "typo10": proportion = player.correct / C.typo10 if proportion >= 0.7: player.endowment = C.endow else: player.endowment = 0 elif player.treatment == "typo30": proportion = player.correct / C.typo30 if proportion >= 0.7: player.endowment = C.endow else: player.endowment = 0 class Sender(Page): form_model = 'player' form_fields = ['allocate' ] def is_displayed(player: Player): if player.type == 'sender' and player.endowment>0: return True else: return False class Receiver(Page): form_model = 'player' form_fields = ['belief', ] def is_displayed(player: Player): if player.type == 'receiver': return True else: return False class Questionnaire(Page): form_model = 'player' form_fields = ['gender', 'age', 'language', 'max_income', 'trust', 'risk', 'instructions', 'econ_exp', 'feedback'] class Thanks(Page): pass page_sequence = [Welcome,ProlificID,General_Instructions,Instructions,countdown,Task,Feedback,Sender,Receiver, Questionnaire,Thanks]