from otree.api import * import random import csv author = 'Lingguo Xu' doc = """ Part 0: PLS & consent, overview, and practice rounds """ class Constants(BaseConstants): name_in_url = 'Part0' players_per_group = None payment_per_correct_answer = 1 num_rounds = 1 ECUpercorrect = 40 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): consent = models.IntegerField(label="", choices=[[1, 'I agree']], widget=widgets.RadioSelect ) treatment = models.IntegerField(initial = 0) practice1 = models.StringField(label="Please fill in a single lower-case letter.") practice2 = models.StringField(label="Please fill in a single lower-case letter.") practice3 = models.StringField(label="Please fill in a single lower-case letter.") practice1_correct = models.BooleanField() practice2_correct = models.BooleanField() practice3_correct = models.BooleanField() practice_performance = models.IntegerField() # FUNCTIONS def creating_session(subsession): for player in subsession.get_players(): player.participant.is_dropout = False print('set player.participant.is_dropout', player.participant.is_dropout) import time player.participant.expiry = time.time() + player.session.config['task_round_timeout_seconds'] print('set player.participant.expiry', player.participant.expiry) # PAGES class Attention_pledge(Page): pass class PLS_Consent(Page): form_model = 'player' form_fields = ['consent'] @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True player.treatment = player.session.config['treatment'] player.participant.treatment = player.session.config['treatment'] class Part0_waitpage_ASU(Page): def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] # Manually advance players in this page, does not consider as dropout @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = False class Overview_ASU(Page): def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] # Manually advance players in this page, does not consider as dropout @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = False class Instruction1(Page): def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True class Instruction2_1(Page): form_model = 'player' form_fields = ['practice1'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def error_message(player, value): print('You typed in', value) if value['practice1'] not in ["a", "b", "c", "d", "e", "f"]: return 'Please enter a single lower-case letter, from the a list of "a", "b", "c", "d", "e", and "f".' @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True class Instruction2_2(Page): def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True class Instruction2_3(Page): form_model = 'player' form_fields = ['practice2'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def error_message(player, value): print('You typed in', value) if value['practice2'] not in ["a", "b", "c", "d", "e", "f"]: return 'Please enter a single lower-case letter, from the a list of "a", "b", "c", "d", "e", and "f".' @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True class Instruction2_4(Page): def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True class Instruction2_5(Page): form_model = 'player' form_fields = ['practice3'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def error_message(player, value): print('You typed in', value) if value['practice3'] not in ["a", "b", "c", "d", "e", "f"]: return 'Please enter a single lower-case letter, from the a list of "a", "b", "c", "d", "e", and "f".' @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): player.practice_performance = (player.practice1 == 'e') + (player.practice2 == 'e') + (player.practice3 == 'a') player.practice1_correct = (player.practice1 == 'e') player.practice2_correct = (player.practice2 == 'e') player.practice3_correct = (player.practice3 == 'a') participant = player.participant if timeout_happened: participant.is_dropout = True class Instruction2_6(Page): def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): participant = player.participant if participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant if timeout_happened: participant.is_dropout = True # page_sequence = [PLS_Consent] page_sequence = [Attention_pledge, PLS_Consent, Part0_waitpage_ASU, Overview_ASU, Instruction1, Instruction2_1, Instruction2_2, Instruction2_3, Instruction2_4, Instruction2_5, Instruction2_6]