from otree.api import * import random doc = """ Demographic questionnaire and final results """ class Constants(BaseConstants): name_in_url = 'demographics_results' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): proceed_code = models.IntegerField(label="If you have been told the proceed code, please enter it here: ") # demographics exp_understand = models.StringField(choices=['' 'Strongly agree', 'Agree', 'Neither agree nor disagree', 'Disagree', 'Strongly disagree'], label="Please indicate how much you agree with the statement \"I found " "the instructions for the experiment easy to understand\"") game1_decision = models.StringField(label="Please briefly describe how you decided which choice to make in Game 1 " "as a citizen.") game2_decision = models.StringField(label="Please briefly describe how you decided which choice to make in Game 2 " "as a dictator.") open_ended_comment = models.StringField(label="Are there any other comments you would like to make about today's " "experiment?") risk_app = models.StringField( choices=['Very unwilling', 'Unwilling', 'Neutral', 'Willing', 'Very willing'], label='In general, how willing or unwilling are you to take risks?' ) age = models.IntegerField(min=0, label="What is your age in years?") gender = models.StringField( choices=['Male', 'Female', 'Other'], label="What is your gender?") field_of_study = models.StringField( choices=['Management / Business', 'Economics', 'Engineering', 'Education', 'Arts', 'Law', 'Science', 'Information technology', 'Medicine, nursing, or other health sciences', 'Social sciences', 'Other'], label="What is your main field of study at the university?") ugrad_grad = models.StringField( choices=['1st year', '2nd year', '3rd year', '4th year or above', 'Graduate student'], label='Are you an undergraduate student (which year?) or a graduate student?') GPA = models.StringField( choices=['Between 6.5-7', 'Between 6.0-6.49', 'Between 5.0-5.99', 'Between 4.0-4.99', 'Below 4', 'Not applicable as I am in my first semester at the university'], label='What is your cumulative GPA at the university?') birth_country = models.StringField( label='Where were you born?', choices=['Australia', 'New Zealand', 'Other Pacific nation', 'China', 'India', 'East Asia', 'South-East Asia', 'South Asia', 'Other Asia', 'Europe', 'United States or Canada', 'Central/South America', 'Africa']) living_in_aus = models.StringField( label="If you were not born in Australia, how long have you lived in Australia?", choices=['Less than a year', '1-2 years', '3-5 years', 'More than 5 years', 'Not applicable as I was born in Australia']) econ_experiments = models.StringField( label='How many economics experiments have you participated in before this one?', choices=['None', '1-2 previous', '3-5 previous', 'More than 5 previous experiments']) extra_win = models.IntegerField() random_round = models.IntegerField() # PAGES class PauseExit(Page): @staticmethod def is_displayed(player): if player.round_number == 1: return True else: return False form_model = 'player' form_fields = ['proceed_code'] @staticmethod def error_message(player: Player, values): ans = dict(proceed_code=714) errors = {f: 'The code you have entered is incorrect.' for f in ans if values[f] != ans[f]} if errors: return errors class Demographics(Page): form_model = 'player' form_fields = ['exp_understand', 'game1_decision', 'game2_decision', 'open_ended_comment', 'risk_app', 'age', 'gender', 'field_of_study', 'ugrad_grad', 'GPA', 'birth_country', 'living_in_aus', 'econ_experiments'] class ResultsIntro(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.random_round = random.choice([x for x in range(48)]) + 1 random_bonus_round = random.choice([x for x in range(5)]) + 1 player.extra_win = player.participant.bonus_outcomes[random_bonus_round - 1] class MainTaskResults(Page): @staticmethod def vars_for_template(player: Player): if player.random_round <= 24: game = 1 round_in_game = player.random_round else: game = 2 round_in_game = player.random_round - 24 total_outcomes = player.participant.main_1_outcomes + player.participant.main_2_outcomes player.participant.payoff = cu(total_outcomes[player.random_round - 1] + player.extra_win) return dict(random_game=game, random_round_num=round_in_game, participant_fee=player.session.config['participation_fee'], extra_payoff=cu(player.extra_win), main_payoff=cu(total_outcomes[player.random_round - 1]) ) class ThankYou(Page): pass page_sequence = [PauseExit, Demographics, ResultsIntro, MainTaskResults, ThankYou]