from otree.api import * import timer_utils doc = """ """ class C(BaseConstants): NAME_IN_URL = 'Game' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): total_cost = models.IntegerField() QoB = models.StringField( choices=["Jan-Mar", "Apr-Jun", "Jul-Sep", "Oct-Dec"], label="Quarter of Birth") country_of_birth = models.StringField() first_language = models.StringField() genderSelect = models.StringField() top = models.StringField() hair = models.StringField() background = models.StringField() consent = models.StringField( label='I have read and agree to the terms above. I consent to the processing of my personal data for this study and to the reuse of my anonymized data for future scientific research.', choices=['Yes, I agree', 'No, I don’t agree'], widget=widgets.RadioSelectHorizontal ) # PAGES class Consent_pilot(Page): form_model = 'player' form_fields = ['consent'] @staticmethod def vars_for_template(player): participant = player.participant return dict( fee=participant.session.config['participation_fee'], time=participant.session.config['time'], token_rate = int(1 / participant.session.config['real_world_currency_per_point'])) def is_displayed(player): return player.session.config['who'] == 'dictator' and player.session.config.get('trail') == 1 def before_next_page(player, timeout_happened): # START THE GLOBAL TIMER HERE (Receivers) timer_utils.start_timer(player.participant) # player.Poor_first = random.choice([True, False]) player.participant.vars['rich_poor_treatment'] = "" def error_message(self, values): if values.get('consent') == "No, I don’t agree": return 'You cannot participate to this study unless you consent to these conditions!' class Consent_rec(Page): form_model = 'player' form_fields = ['consent'] @staticmethod def vars_for_template(player): participant = player.participant return dict( fee=participant.session.config['participation_fee'], time=participant.session.config['time'], token_rate = int(1 / participant.session.config['real_world_currency_per_point'])) def is_displayed(player): return player.session.config['who'] == 'receiver' def before_next_page(player, timeout_happened): # START THE GLOBAL TIMER HERE (Receivers) timer_utils.start_timer(player.participant) # player.Poor_first = random.choice([True, False]) player.participant.vars['rich_poor_treatment'] = "" def error_message(self, values): if values.get('consent') == "No, I don’t agree": return 'You cannot participate to this study unless you consent to these conditions!' class Avatar(Page): form_model = 'player' form_fields = ['QoB', 'country_of_birth', 'first_language', 'genderSelect', 'top', 'hair', 'background', 'total_cost'] # Only show timer if < 3 mins timer_text = "Time remaining:" def get_timeout_seconds(player): rem = timer_utils.get_remaining_time(player.participant) if rem < timer_utils.WARNING_SECONDS: return rem # Skip page if global time is up def is_displayed(player): return not timer_utils.is_time_up(player.participant) @staticmethod def error_message(player: Player, value): if value['total_cost'] > 50: return "Total cost can not be higher than 50 Tokens." def before_next_page(player: Player, timeout_happened): participant = player.participant participant.top = player.top participant.hair = player.hair participant.background = player.background.split('/')[-1] participant.QoB = player.QoB participant.country_of_birth = player.country_of_birth participant.first_language = player.first_language participant.genderSelect = player.genderSelect participant.payoff += 50 - player.total_cost class rec_end(Page): timer_text = "Time remaining:" @staticmethod def get_timeout_seconds(player): rem = timer_utils.get_remaining_time(player.participant) if rem < timer_utils.WARNING_SECONDS: return rem @staticmethod def is_displayed(player): return (not timer_utils.is_time_up(player.participant)) and player.session.config.get('who') == 'receiver' page_sequence = [Consent_pilot,Consent_rec, Avatar,rec_end]