from otree.api import * import random import csv author = 'Lingguo Xu' doc = """ Prolific pilot--Survey """ class Constants(BaseConstants): name_in_url = 'Survey' players_per_group = None num_rounds = 1 ECUconversion = 100 participationfee = 3 ECUpercorrect = 10 nationalities = [ ['British', 'British'], ['Afghan', 'Afghan'], ['Albanian', 'Albanian'], ['Algerian', 'Algerian'], ['American', 'American'], ['Andorran', 'Andorran'], ['Angolan', 'Angolan'], ['Anguillan', 'Anguillan'], ['Argentine', 'Argentine'], ['Armenian', 'Armenian'], ['Australian', 'Australian'], ['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 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)'], ] nationality_list = nationalities.copy() countries = [ ['GB', 'United Kingdom of Great Britain and Northern Ireland'], ['AF', 'Afghanistan'], ['AL', 'Albania'], ['AU', 'Australia'], ['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'], ['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'], ['NZ', 'New Zealand'], ['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)'], ] country_born_list = countries.copy() class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Part1_Survey_Hypo Survey_Part1_1 = models.LongStringField( label="") Survey_Part1_2 = models.LongStringField( label="") Hypo2 = models.IntegerField(min=0, max=30, label="Please fill in a number between 0 and 30.") Hypo1 = models.IntegerField(label="") Difficulty_Part1 = models.IntegerField(label="") Difficulty_Part4 = models.IntegerField(label="") # Part3_Survey Part3_Survey1 = models.LongStringField( label="") Part3_Survey2 = models.LongStringField( label="") Part3_Survey3 = models.LongStringField( label="") Part3_Survey4 = models.LongStringField( label="") #Demographic year_birth = models.IntegerField( label="What is your year of birth?", min=1900, max=2005, ) gender = models.IntegerField( label="What is your gender?", choices=[ [0, 'Male'], [1, 'Female'], [2, 'Trans/Intersex/Other'], ] ) education = models.IntegerField( label="What is the highest education qualification you have attained?", choices = [ [0, "Did not complete Secondary School"], [1, "GCSEs or equivalent"], [2, "A-Level or equivalent"], [3, "Bachelor’s Degree"], [4, "Master’s Degree"], [5, "PhD or higher"] ] ) colleglevel = models.IntegerField( label="Are you currently a university student? If yes, what is your current level of study at university?", 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="If you are currently enrolled in a university or have graduated from a university, what is your average grade?", choices=[ [0, "Not applicable"], [1, "Pass"], [2, "3rd class"], [3, "2nd-lower class"], [4, "2nd-upper class"], [5, "First class"], ] ) major = models.StringField(label="If you are currently enrolled in a university or have graduated from a university, what is/was your area of study? Please put N/A if not applicable.") profession = models.StringField(label="If you are currently working, what is your profession? Please put N/A if not applicable.") ethnicity = models.IntegerField( label="What is your ethnicity?", choices=[ [0, 'White'], [1, 'Asian/Asian British'], [2, 'Black/African/Caribbean/Black British'], [3, 'Mixed/Multiple ethnic groups'], [4, 'Other ethnic group'], ] ) nationality = models.StringField( label="What is your nationality?", choices=Constants.nationality_list, ) other_nationality = models.StringField( label='', blank=True, ) country_born = models.StringField( label="In what country were you born?", choices=Constants.country_born_list ) other_country_born = models.StringField( label='', blank=True, ) yearsinuk = models.IntegerField( label="If you were not born in the UK, how many years have you lived in the UK? (Enter 99 if born in the UK)", min=0, max=100, ) ProlificID = models.StringField(label="") # Receiving feedback, final payoff computation and ProlificID # Receivefeedback = models.BooleanField() PaymentPart = models.IntegerField() bonuspayoff = models.IntegerField() finalpayoff = models.FloatField() payoff_part4 = models.IntegerField() # FUNCTIONS def creating_session(subsession): for player in subsession.get_players(): player.PaymentPart = random.choice([1, 2, 3, 4]) print('set player.PaymentPart to', player.PaymentPart) # PAGES class Part1_Survey(Page): form_model = 'player' form_fields = ['Survey_Part1_1', 'Survey_Part1_2'] # Compute Part 4 payoff @staticmethod def before_next_page(player, timeout_happened): # Compute player payoff in Part 4 player.payoff_part4 = Constants.ECUpercorrect * player.participant.correctanswer_R2 player.participant.part4payoff = player.payoff_part4 # Compute bonuspayoff and finalpayoff # Determine bonus payoff based on random draw from PaymentPart (TBD) if player.PaymentPart == 1: player.bonuspayoff = player.participant.part1payoff elif player.PaymentPart == 2: player.bonuspayoff = player.participant.part2payoff elif player.PaymentPart == 3: player.bonuspayoff = player.participant.part3payoff else: player.bonuspayoff = player.payoff_part4 #Player final payment in real world currecy-prolific edition player.finalpayoff = player.bonuspayoff/Constants.ECUconversion+Constants.participationfee class Part1_Survey_Hypo2(Page): form_model = 'player' form_fields = ['Hypo2'] class Part1_Survey_Hypo1(Page): form_model = 'player' form_fields = ['Hypo1'] class Part1_4_Survey_Difficulty(Page): form_model = 'player' form_fields = ['Difficulty_Part1', 'Difficulty_Part4'] class Part3_Survey1(Page): form_model = 'player' form_fields = ['Part3_Survey1'] class Part3_Survey2(Page): form_model = 'player' form_fields = ['Part3_Survey2', 'Part3_Survey3'] class Demographic(Page): form_model = 'player' form_fields = [ 'year_birth', 'gender', 'education', 'colleglevel', 'gpa', 'major', 'profession', 'ethnicity', 'nationality', 'other_nationality', 'country_born', 'other_country_born', 'yearsinuk', ] class ProlificID(Page): form_model = 'player' form_fields = ['ProlificID'] class FinalPage(Page): pass # page_sequence = [Part1_Survey, Part1_Survey_Hypo2, Part1_Survey_Hypo1, Part3_Survey1, Part3_Survey2, cProlificID, FinalPage] page_sequence = [Part1_Survey, Part1_Survey_Hypo1, Part1_4_Survey_Difficulty, Part3_Survey1, Part3_Survey2, Demographic, ProlificID, FinalPage] # page_sequence = [FinalPage]