from otree.api import * import random import csv author = 'Lingguo Xu' doc = """ Survey """ class Constants(BaseConstants): name_in_url = 'Survey' players_per_group = None num_rounds = 1 ECUconversion = 50 participationfee = 5 ECUpercorrect = 40 risk_preference = 100 Survey_bonus = 150 nationalities = [ ['Australian', 'Australian'], ['New Zealander', 'New Zealander'], ['Afghan', 'Afghan'], ['Albanian', 'Albanian'], ['Algerian', 'Algerian'], ['American', 'American'], ['Andorran', 'Andorran'], ['Angolan', 'Angolan'], ['Anguillan', 'Anguillan'], ['Argentine', 'Argentine'], ['Armenian', 'Armenian'], ['Austrian', 'Austrian'], ['Azerbaijani', 'Azerbaijani'], ['Bahamian', 'Bahamian'], ['Bahraini', 'Bahraini'], ['Bangladeshi', 'Bangladeshi'], ['Barbadian', 'Barbadian'], ['Belarusian', 'Belarusian'], ['Belgian', 'Belgian'], ['Belizean', 'Belizean'], ['Beninese', 'Beninese'], ['Bermudian', 'Bermudian'], ['Bhutanese', 'Bhutanese'], ['Bolivian', 'Bolivian'], ['Botswanan', 'Botswanan'], ['Brazilian', 'Brazilian'], ['British', 'British'], ['British Virgin Islander', 'British Virgin Islander'], ['Bruneian', 'Bruneian'], ['Bulgarian', 'Bulgarian'], ['Burkinan', 'Burkinan'], ['Burmese', 'Burmese'], ['Burundian', 'Burundian'], ['Cambodian', 'Cambodian'], ['Cameroonian', 'Cameroonian'], ['Canadian', 'Canadian'], ['Cape Verdean', 'Cape Verdean'], ['Cayman Islander', 'Cayman Islander'], ['Central African', 'Central African'], ['Chadian', 'Chadian'], ['Chilean', 'Chilean'], ['Chinese', 'Chinese'], ['Citizen of Antigua and Barbuda', 'Citizen of Antigua and Barbuda'], ['Citizen of Bosnia and Herzegovina', 'Citizen of Bosnia and Herzegovina'], ['Citizen of Guinea-Bissau', 'Citizen of Guinea-Bissau'], ['Citizen of Kiribati', 'Citizen of Kiribati'], ['Citizen of Seychelles', 'Citizen of Seychelles'], ['Citizen of the Dominican Republic', 'Citizen of the Dominican Republic'], ['Citizen of Vanuatu', 'Citizen of Vanuatu'], ['Colombian', 'Colombian'], ['Comoran', 'Comoran'], ['Congolese (Congo)', 'Congolese (Congo)'], ['Congolese (DRC)', 'Congolese (DRC)'], ['Cook Islander', 'Cook Islander'], ['Costa Rican', 'Costa Rican'], ['Croatian', 'Croatian'], ['Cuban', 'Cuban'], ['Cymraes', 'Cymraes'], ['Cymro', 'Cymro'], ['Cypriot', 'Cypriot'], ['Czech', 'Czech'], ['Danish', 'Danish'], ['Djiboutian', 'Djiboutian'], ['Dominican', 'Dominican'], ['Dutch', 'Dutch'], ['East Timorese', 'East Timorese'], ['Ecuadorean', 'Ecuadorean'], ['Egyptian', 'Egyptian'], ['Emirati', 'Emirati'], ['English', 'English'], ['Equatorial Guinean', 'Equatorial Guinean'], ['Eritrean', 'Eritrean'], ['Estonian', 'Estonian'], ['Ethiopian', 'Ethiopian'], ['Faroese', 'Faroese'], ['Fijian', 'Fijian'], ['Filipino', 'Filipino'], ['Finnish', 'Finnish'], ['French', 'French'], ['Gabonese', 'Gabonese'], ['Gambian', 'Gambian'], ['Georgian', 'Georgian'], ['German', 'German'], ['Ghanaian', 'Ghanaian'], ['Gibraltarian', 'Gibraltarian'], ['Greek', 'Greek'], ['Greenlandic', 'Greenlandic'], ['Grenadian', 'Grenadian'], ['Guamanian', 'Guamanian'], ['Guatemalan', 'Guatemalan'], ['Guinean', 'Guinean'], ['Guyanese', 'Guyanese'], ['Haitian', 'Haitian'], ['Honduran', 'Honduran'], ['Hong Konger', 'Hong Konger'], ['Hungarian', 'Hungarian'], ['Icelandic', 'Icelandic'], ['Indian', 'Indian'], ['Indonesian', 'Indonesian'], ['Iranian', 'Iranian'], ['Iraqi', 'Iraqi'], ['Irish', 'Irish'], ['Israeli', 'Israeli'], ['Italian', 'Italian'], ['Ivorian', 'Ivorian'], ['Jamaican', 'Jamaican'], ['Japanese', 'Japanese'], ['Jordanian', 'Jordanian'], ['Kazakh', 'Kazakh'], ['Kenyan', 'Kenyan'], ['Kittitian', 'Kittitian'], ['Kosovan', 'Kosovan'], ['Kuwaiti', 'Kuwaiti'], ['Kyrgyz', 'Kyrgyz'], ['Lao', 'Lao'], ['Latvian', 'Latvian'], ['Lebanese', 'Lebanese'], ['Liberian', 'Liberian'], ['Libyan', 'Libyan'], ['Liechtenstein citizen', 'Liechtenstein citizen'], ['Lithuanian', 'Lithuanian'], ['Luxembourger', 'Luxembourger'], ['Macanese', 'Macanese'], ['Macedonian', 'Macedonian'], ['Malagasy', 'Malagasy'], ['Malawian', 'Malawian'], ['Malaysian', 'Malaysian'], ['Maldivian', 'Maldivian'], ['Malian', 'Malian'], ['Maltese', 'Maltese'], ['Marshallese', 'Marshallese'], ['Martiniquais', 'Martiniquais'], ['Mauritanian', 'Mauritanian'], ['Mauritian', 'Mauritian'], ['Mexican', 'Mexican'], ['Micronesian', 'Micronesian'], ['Moldovan', 'Moldovan'], ['Monegasque', 'Monegasque'], ['Mongolian', 'Mongolian'], ['Montenegrin', 'Montenegrin'], ['Montserratian', 'Montserratian'], ['Moroccan', 'Moroccan'], ['Mosotho', 'Mosotho'], ['Mozambican', 'Mozambican'], ['Namibian', 'Namibian'], ['Nauruan', 'Nauruan'], ['Nepalese', 'Nepalese'], ['New Zealander', 'New Zealander'], ['Nicaraguan', 'Nicaraguan'], ['Nigerian', 'Nigerian'], ['Nigerien', 'Nigerien'], ['Niuean', 'Niuean'], ['North Korean', 'North Korean'], ['Northern Irish', 'Northern Irish'], ['Norwegian', 'Norwegian'], ['Omani', 'Omani'], ['Pakistani', 'Pakistani'], ['Palauan', 'Palauan'], ['Palestinian', 'Palestinian'], ['Panamanian', 'Panamanian'], ['Papua New Guinean', 'Papua New Guinean'], ['Paraguayan', 'Paraguayan'], ['Peruvian', 'Peruvian'], ['Pitcairn Islander', 'Pitcairn Islander'], ['Polish', 'Polish'], ['Portuguese', 'Portuguese'], ['Prydeinig', 'Prydeinig'], ['Puerto Rican', 'Puerto Rican'], ['Qatari', 'Qatari'], ['Romanian', 'Romanian'], ['Russian', 'Russian'], ['Rwandan', 'Rwandan'], ['Salvadorean', 'Salvadorean'], ['Sammarinese', 'Sammarinese'], ['Samoan', 'Samoan'], ['Sao Tomean', 'Sao Tomean'], ['Saudi Arabian', 'Saudi Arabian'], ['Scottish', 'Scottish'], ['Senegalese', 'Senegalese'], ['Serbian', 'Serbian'], ['Sierra Leonean', 'Sierra Leonean'], ['Singaporean', 'Singaporean'], ['Slovak', 'Slovak'], ['Slovenian', 'Slovenian'], ['Solomon Islander', 'Solomon Islander'], ['Somali', 'Somali'], ['South African', 'South African'], ['South Korean', 'South Korean'], ['South Sudanese', 'South Sudanese'], ['Spanish', 'Spanish'], ['Sri Lankan', 'Sri Lankan'], ['St Helenian', 'St Helenian'], ['St Lucian', 'St Lucian'], ['Stateless', 'Stateless'], ['Sudanese', 'Sudanese'], ['Surinamese', 'Surinamese'], ['Swazi', 'Swazi'], ['Swedish', 'Swedish'], ['Swiss', 'Swiss'], ['Syrian', 'Syrian'], ['Taiwanese', 'Taiwanese'], ['Tajik', 'Tajik'], ['Tanzanian', 'Tanzanian'], ['Thai', 'Thai'], ['Togolese', 'Togolese'], ['Tongan', 'Tongan'], ['Trinidadian', 'Trinidadian'], ['Tristanian', 'Tristanian'], ['Tunisian', 'Tunisian'], ['Turkish', 'Turkish'], ['Turkmen', 'Turkmen'], ['Turks and Caicos Islander', 'Turks and Caicos Islander'], ['Tuvaluan', 'Tuvaluan'], ['Ugandan', 'Ugandan'], ['Ukrainian', 'Ukrainian'], ['Uruguayan', 'Uruguayan'], ['Uzbek', 'Uzbek'], ['Vatican citizen', 'Vatican citizen'], ['Venezuelan', 'Venezuelan'], ['Vietnamese', 'Vietnamese'], ['Vincentian', 'Vincentian'], ['Wallisian', 'Wallisian'], ['Welsh', 'Welsh'], ['Yemeni', 'Yemeni'], ['Zambian', 'Zambian'], ['Zimbabwean', 'Zimbabwean'], ['OTHER', 'Other (please state below)'], ['NOTGIVEN', 'Prefer not to say'], ] nationality_list = nationalities.copy() countries = [ ['AU', 'Australia'], ['NZ', 'New Zealand'], ['AF', 'Afghanistan'], ['AL', 'Albania'], ['DZ', 'Algeria'], ['AD', 'Andorra'], ['AO', 'Angola'], ['AG', 'Antigua and Barbuda'], ['AR', 'Argentina'], ['AM', 'Armenia'], ['AT', 'Austria'], ['AZ', 'Azerbaijan'], ['BS', 'Bahamas'], ['BH', 'Bahrain'], ['BD', 'Bangladesh'], ['BB', 'Barbados'], ['BY', 'Belarus'], ['BE', 'Belgium'], ['BZ', 'Belize'], ['BJ', 'Benin'], ['BT', 'Bhutan'], ['BO', 'Bolivia (Plurinational State of)'], ['BA', 'Bosnia and Herzegovina'], ['BW', 'Botswana'], ['BR', 'Brazil'], ['BN', 'Brunei Darussalam'], ['BG', 'Bulgaria'], ['BF', 'Burkina Faso'], ['BI', 'Burundi'], ['CV', 'Cabo Verde'], ['KH', 'Cambodia'], ['CM', 'Cameroon'], ['CA', 'Canada'], ['CF', 'Central African Republic'], ['TD', 'Chad'], ['CL', 'Chile'], ['CN', 'China'], ['CO', 'Colombia'], ['KM', 'Comoros'], ['CG', 'Congo'], ['CK', 'Cook Islands'], ['CR', 'Costa Rica'], ['HR', 'Croatia'], ['CU', 'Cuba'], ['CY', 'Cyprus'], ['CZ', 'Czechia'], ['CI', 'Côte d\'Ivoire'], ['KP', 'Democratic People\'s Republic of Korea'], ['CD', 'Democratic Republic of the Congo'], ['DK', 'Denmark'], ['DJ', 'Djibouti'], ['DM', 'Dominica'], ['DO', 'Dominican Republic'], ['EC', 'Ecuador'], ['EG', 'Egypt'], ['SV', 'El Salvador'], ['GB', 'United Kingdom of Great Britain and Northern Ireland'], ['GQ', 'Equatorial Guinea'], ['ER', 'Eritrea'], ['EE', 'Estonia'], ['SZ', 'Eswatini'], ['ET', 'Ethiopia'], ['FO', 'Faroe Islands'], ['FJ', 'Fiji'], ['FI', 'Finland'], ['FR', 'France'], ['GA', 'Gabon'], ['GM', 'Gambia'], ['GE', 'Georgia'], ['DE', 'Germany'], ['GH', 'Ghana'], ['GR', 'Greece'], ['GD', 'Grenada'], ['GT', 'Guatemala'], ['GN', 'Guinea'], ['GW', 'Guinea-Bissau'], ['GY', 'Guyana'], ['HT', 'Haiti'], ['HN', 'Honduras'], ['HU', 'Hungary'], ['IS', 'Iceland'], ['IN', 'India'], ['ID', 'Indonesia'], ['IR', 'Iran (Islamic Republic of)'], ['IQ', 'Iraq'], ['IE', 'Ireland'], ['IL', 'Israel'], ['IT', 'Italy'], ['JM', 'Jamaica'], ['JP', 'Japan'], ['JO', 'Jordan'], ['KZ', 'Kazakhstan'], ['KE', 'Kenya'], ['KI', 'Kiribati'], ['KW', 'Kuwait'], ['KG', 'Kyrgyzstan'], ['LA', 'Lao People\'s Democratic Republic'], ['LV', 'Latvia'], ['LB', 'Lebanon'], ['LS', 'Lesotho'], ['LR', 'Liberia'], ['LY', 'Libya'], ['LT', 'Lithuania'], ['LU', 'Luxembourg'], ['MG', 'Madagascar'], ['MW', 'Malawi'], ['MY', 'Malaysia'], ['MV', 'Maldives'], ['ML', 'Mali'], ['MT', 'Malta'], ['MH', 'Marshall Islands'], ['MR', 'Mauritania'], ['MU', 'Mauritius'], ['MX', 'Mexico'], ['FM', 'Micronesia (Federated States of)'], ['MC', 'Monaco'], ['MN', 'Mongolia'], ['ME', 'Montenegro'], ['MA', 'Morocco'], ['MZ', 'Mozambique'], ['MM', 'Myanmar'], ['NA', 'Namibia'], ['NR', 'Nauru'], ['NP', 'Nepal'], ['NL', 'Netherlands'], ['NI', 'Nicaragua'], ['NE', 'Niger'], ['NG', 'Nigeria'], ['NU', 'Niue'], ['MK', 'North Macedonia'], ['NO', 'Norway'], ['OM', 'Oman'], ['PK', 'Pakistan'], ['PW', 'Palau'], ['PA', 'Panama'], ['PG', 'Papua New Guinea'], ['PY', 'Paraguay'], ['PE', 'Peru'], ['PH', 'Philippines'], ['PL', 'Poland'], ['PT', 'Portugal'], ['QA', 'Qatar'], ['KR', 'Republic of Korea'], ['MD', 'Republic of Moldova'], ['RO', 'Romania'], ['RU', 'Russian Federation'], ['RW', 'Rwanda'], ['KN', 'Saint Kitts and Nevis'], ['LC', 'Saint Lucia'], ['VC', 'Saint Vincent and the Grenadines'], ['WS', 'Samoa'], ['SM', 'San Marino'], ['ST', 'Sao Tome and Principe'], ['SA', 'Saudi Arabia'], ['SN', 'Senegal'], ['RS', 'Serbia'], ['SC', 'Seychelles'], ['SL', 'Sierra Leone'], ['SG', 'Singapore'], ['SK', 'Slovakia'], ['SI', 'Slovenia'], ['SB', 'Solomon Islands'], ['SO', 'Somalia'], ['ZA', 'South Africa'], ['SS', 'South Sudan'], ['ES', 'Spain'], ['LK', 'Sri Lanka'], ['SD', 'Sudan'], ['SR', 'Suriname'], ['SE', 'Sweden'], ['CH', 'Switzerland'], ['SY', 'Syrian Arab Republic'], ['TJ', 'Tajikistan'], ['TH', 'Thailand'], ['TL', 'Timor-Leste'], ['TG', 'Togo'], ['TK', 'Tokelau'], ['TO', 'Tonga'], ['TT', 'Trinidad and Tobago'], ['TN', 'Tunisia'], ['TR', 'Turkey'], ['TM', 'Turkmenistan'], ['TV', 'Tuvalu'], ['UG', 'Uganda'], ['UA', 'Ukraine'], ['AE', 'United Arab Emirates'], ['TZ', 'United Republic of Tanzania'], ['US', 'United States of America'], ['UY', 'Uruguay'], ['UZ', 'Uzbekistan'], ['VU', 'Vanuatu'], ['VE', 'Venezuela (Bolivarian Republic of)'], ['VN', 'Viet Nam'], ['YE', 'Yemen'], ['ZM', 'Zambia'], ['ZW', 'Zimbabwe'], ['OTHER', 'Other (please state below)'], ['NOTGIVEN', 'Prefer not to say'], ] country_born_list = countries.copy() class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): #Demographic year_birth = models.IntegerField( label="What is your year of birth?", min=1900, max=2005, blank=True, ) gender = models.IntegerField( label="What is your gender?", choices=[ [0, 'Male'], [1, 'Female'], [2, 'Trans/Intersex/Other'], [3, 'Prefer not to say'], ] ) major = models.StringField( label="What is your main field of study at the University?", choices=[ 'Agriculture', 'Arts/ Social Sciences', 'Biomedicine', 'Commerce (non-Economics)', 'Commerce (Economics)', 'Dentistry/ Oral Health', 'Education', 'Engineering', 'Environments', 'Fine Arts', 'Law', 'Medicine', 'Music', 'Nursing', 'Pharmacy', 'Psychology', 'Science', 'Veterinary Science', 'Other', 'Not a student', ] ) colleglevel = models.IntegerField( label="Are you an undergraduate or a graduate student?", choices = [ [0, "Not a student"], [1, "1st-year undergraduate"], [2, "2nd-year undergraduate"], [3, "3rd-year undergraduate"], [4, "Master’s"], [5, "PhD"], ] ) gpa = models.IntegerField( label="What is your (current) average GPA?", choices=[ [6, 'H1 (80%-100%)'], [5, 'H2A (75%-79%)'], [4, 'H2B (70%-74%)'], [3, 'H3 (65%-69%)'], [2, 'P (50%-64%)'], [1, 'N (0%-49%)'], [99, 'Not applicable (first semester at University or not a student)'] ] ) employment = models.IntegerField( label="Do you currently hold a paying part-time job?", choices=[ [1, 'Yes'], [0, 'No'], ] ) ethnicity = models.IntegerField( label="What is your ethnic background?", choices=[ [1, "Australian or New Zealander"], [2, "Indigenous Australian or Torres Strait Islander"], [3, "East Asian"], [4, "Southeast Asian"], [5, "Indian"], [6, "Middle Eastern"], [7, "European"], [8, "North American"], [9, "South American"], [10, "African"], [11, "Other]"], ] ) nationality = models.StringField( label="What is your nationality?", choices=Constants.nationality_list, ) other_nationality = models.StringField( label='If you selected "Other", please specify in here.', blank=True, ) country_born = models.StringField( label="In what country were you born?", choices=Constants.country_born_list ) other_country_born = models.StringField( label='If you selected "Other", please specify in here.', blank=True, ) yearsinau = models.IntegerField( label="How long have you lived in Australia?", choices=[ [99, 'Born in Australia'], [4, 'More than 5 years'], [3, '2-5 years'], [2, '1-2 years'], [1, 'Less than 1 year'], ] ) past_experiments = models.IntegerField( label="How many economics experiments have you participated in before this one?", min=0, max=999, ) decisions_clear = models.StringField( label = "", choices = [ "Strongly Disagree", "Disagree", "Agree", "Strongly Agree" ], widget=widgets.RadioSelectHorizontal ) earnings_clear = models.StringField( label = "", choices = [ "Strongly Disagree", "Disagree", "Agree", "Strongly Agree" ], widget=widgets.RadioSelectHorizontal ) comments_unclear = models.LongStringField(label = "") # Part1_Survey_Hypo # Survey_Part1_1 = models.LongStringField(label="") # Survey_Part1_2 = models.LongStringField(label="") Effort_ability = models.IntegerField(label="") Difficulty_Part1 = models.IntegerField(label="") Difficulty_Part4 = models.IntegerField(label="", initial = 0) noise_guess_performance = models.IntegerField(min=0, max=30, label="number of puzzles you solved correctly") noise_guess_x = models.IntegerField( choices=[-3, -2, -1, 0, 1, 2, 3], label="random number X") # Part3_Survey Part3_Survey0_Pref1 = models.IntegerField( choices=[[5, 'Rank 1-20 (top performance)'], [4, 'Rank 21-40 (above average)'], [3, 'Rank 41-60 (average performance)'], [2, 'Rank 61-80 (below average)'], [1, 'Rank 81-100 (bottom performance)'], [0, 'Not interested'], [-1, 'Not interested']], label="", initial=-1, widget=widgets.RadioSelect, ) Part3_Survey_Pref1Reason = models.LongStringField( label="") Part3_Survey_WTPsReason = models.LongStringField( label="", blank = True ) # Measuring Risk attitude Invest = models.IntegerField(min=0, max=100, label="Please fill in a number between 0 and 100.") Keep = models.IntegerField(min=0, max=100, label="Please fill in a number between 0 and 100.") payoff_risk = models.IntegerField(label="") # Measuring social comparison tentency (Buunk, Gibbons, et al, 1999, 2005, 2006) def make_field(): return models.IntegerField( choices=[[1, 'I disagree strongly'], [2, 'I disagree '], [3, 'I neither agree nor disagree'], [4, 'I agree'], [5, 'I strongly agree']], label="", widget=widgets.RadioSelect, ) soc_comp_1 = make_field() soc_comp_2 = make_field() soc_comp_3 = make_field() soc_comp_4 = make_field() soc_comp_5 = make_field() # soc_comp_6 = make_field() # ProlificID = models.StringField(label="") PayID1 = models.StringField(label="") PayID2 = models.StringField(label="") Email = models.StringField(label="") # Receiving feedback, final payoff computation and ProlificID # Receivefeedback = models.BooleanField() PaymentPart = models.IntegerField() bonuspart = models.IntegerField() bonuspayoff = models.IntegerField() bonuspayment = models.FloatField() finalpayoff = models.FloatField() # A player level variable for participatn.dropout for data cleaning player_dropout = models.BooleanField() # FUNCTIONS def creating_session(subsession): for player in subsession.get_players(): player.PaymentPart = random.choice([1, 2, 4]) print('set player.PaymentPart to', player.PaymentPart) player.player_dropout = player.participant.is_dropout print('Current dropout status', player.player_dropout) # PAGES class Introduction(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 Demographic(Page): form_model = 'player' form_fields = [ 'year_birth', 'gender', 'colleglevel', 'gpa', 'major', 'employment', 'ethnicity', 'nationality', 'other_nationality', 'country_born', 'other_country_born', 'yearsinau', 'past_experiments', ] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True class General(Page): form_model = 'player' form_fields = ["decisions_clear", "earnings_clear", "comments_unclear"] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True class Part1_Survey(Page): form_model = 'player' form_fields = ['Survey_Part1_1', 'Survey_Part1_2'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True class Part1_Survey_Hypo2(Page): form_model = 'player' form_fields = ['Hypo2'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True class Part1_Survey_effort_ability(Page): form_model = 'player' form_fields = ['Effort_ability'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True class Part1_4_Survey_Difficulty(Page): form_model = 'player' form_fields = ['Difficulty_Part1', 'Difficulty_Part4'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True player.Part3_Survey0_Pref1 = player.participant.Pref1_survey if player.participant.treatment == 1: player.Difficulty_Part4 = 0 class Part2_guess_noise(Page): form_model = 'player' form_fields = ['noise_guess_performance', 'noise_guess_x'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True @staticmethod def error_message(player, values): print('values is', values) if values['noise_guess_performance'] + values['noise_guess_x'] != player.participant.score: return 'The two numbers must add up to your score.' class Part3_Survey2(Page): form_model = 'player' form_fields = ['Part3_Survey_Pref1Reason', 'Part3_Survey_WTPsReason'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True class Social_comparison(Page): form_model = 'player' form_fields = ['soc_comp_1', 'soc_comp_2', 'soc_comp_3', 'soc_comp_4', 'soc_comp_5'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True class Risk_preference(Page): form_model = 'player' form_fields = ['Invest', 'Keep'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.participant.is_dropout: return 1 # instant timeout, 1 second else: return player.session.config['my_page_timeout_seconds'] @staticmethod def error_message(player, values): print('values is', values) if values['Invest'] + values['Keep'] != Constants.risk_preference: return 'The numbers must add up to 100.' @staticmethod def before_next_page(player, timeout_happened): # Compute risk preference payoff if random.choice([1, 2]) == 1: player.payoff_risk = player.Invest * 3 else: player.payoff_risk = Constants.risk_preference - player.Invest # Compute bonuspayoff and finalpayoff # Determine bonus payoff based on random draw from PaymentPart (TBD) if player.participant.treatment == 1: player.PaymentPart = random.choice([1, 2]) if player.PaymentPart == 1: player.bonuspart = player.participant.part1payoff else: player.bonuspart = player.participant.part2payoff else: if player.PaymentPart == 1: player.bonuspart = player.participant.part1payoff elif player.PaymentPart == 2: player.bonuspart = player.participant.part2payoff else: player.bonuspart = player.participant.part4payoff player.bonuspayoff = player.bonuspart + player.payoff_risk + player.participant.part3payoff player.bonuspayment = player.bonuspayoff/Constants.ECUconversion #Player final payment in real world currecy-prolific edition player.finalpayoff = round(player.bonuspayoff/Constants.ECUconversion + Constants.participationfee + Constants.Survey_bonus/Constants.ECUconversion, 2) player.player_dropout = player.participant.is_dropout if timeout_happened: player.participant.is_dropout = True class PayID(Page): form_model = 'player' form_fields = ['PayID1', 'PayID2', 'Email'] def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True @staticmethod def error_message(player, values): if values['PayID1'] != values['PayID2']: return 'Please make sure you enter the same email address or phone number.' class Results(Page): def is_displayed(player): return player.participant.is_dropout == False @staticmethod def get_timeout_seconds(player): if player.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): if timeout_happened: player.participant.is_dropout = True @staticmethod def js_vars(player): return dict( finalpayoff = player.finalpayoff, ) class DropoutPage(Page): def is_displayed(player): return player.participant.is_dropout == True @staticmethod def get_timeout_seconds(player): return 60 @staticmethod def before_next_page(player, timeout_happened): player.player_dropout = player.participant.is_dropout class FinalPage(Page): pass page_sequence = [Introduction, Demographic, General, Part1_Survey_effort_ability, Part1_4_Survey_Difficulty, Part2_guess_noise, Part3_Survey2, Social_comparison, Risk_preference, PayID, Results, DropoutPage, FinalPage] # page_sequence = [Part1_4_Survey_Difficulty]