import random from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import json import os class Constants(BaseConstants): name_in_url = 'baseline_' players_per_group = None num_rounds = 1 countries = ["Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Côte d'Ivoire", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo (Congo-Brazzaville)", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia", "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Holy See", "Honduras", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "North Korea", "North Macedonia", "Norway", "Oman", "Pakistan", "Palau", "Palestine State", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Korea", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Sweden", "Switzerland", "Syria", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States of America", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Yemen"] states=["I don't live in the U.S.", "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def duplicateChoice(x): y = [] for e in x: y = y + [[e, e]] return y def duplicateChoiceEmpty(x): y = [] for e in x: y = y + [[e, ' ']] return y class Player(BasePlayer): log = models.LongStringField(label='', blank=True) error_log = models.LongStringField(label='', blank=True) def live_handler(self, data): # handles logs if isinstance(self.log, type(None)): self.log = '' self.log = self.log + ';' + json.dumps(data) if 'USERNAME' in os.environ and os.environ['USERNAME'] == 'moehring': print('\n\n\n\n') print(data) # Models twitterHandle = models.StringField(label="Twitter Handle", initial='@', help_text="example: @Oprah") yearBirth = models.IntegerField(label='What year were you born?', min=1911, max=2003, blank=True) gender = models.StringField(label='What is your gender?', choices=duplicateChoice(['Male', 'Female', 'Nonbinary', 'Prefer not to say']), widget=widgets.RadioSelectHorizontal, blank=True) education = models.StringField(label='What is the highest degree or level of schooling that you have completed?', choices=duplicateChoice(['Less than a high school diploma', 'High school diploma or equivalent (for example: GED)', 'Some college but no degree', "Associate's degree", "Bachelor's degree", "Graduate degree (for example: MA, MBA, JD,PhD)"]), blank=True) ethnicity = models.StringField(label='Race / Ethnicity', choices=duplicateChoice(['American Indian or Alaska Native', 'Asian', 'Black or African American', 'Hispanic', 'White / Caucasian', 'Other']), blank=True) ideology = models.StringField(label='Yourself', choices=duplicateChoiceEmpty(['Extremely liberal', 'Liberal', 'Slightly liberal', 'Moderate', 'Slightly conservative', 'Conservative', 'Extremely conservative']), widget=widgets.RadioSelectHorizontal, blank=True) ideologyTwitterFollowers = models.StringField(label='People that are following you on Twitter', choices=duplicateChoiceEmpty(['Extremely liberal', 'Liberal', 'Slightly liberal', 'Moderate', 'Slightly conservative', 'Conservative', 'Extremely conservative']), widget=widgets.RadioSelectHorizontal, blank=True) ideologyTwitterFollow = models.StringField(label='People that you follow on Twitter', choices=duplicateChoiceEmpty(['Extremely liberal', 'Liberal', 'Slightly liberal', 'Moderate', 'Slightly conservative', 'Conservative', 'Extremely conservative']), widget=widgets.RadioSelectHorizontal, blank=True) timeFamily = models.StringField(label='...spending time with family?', choices=duplicateChoiceEmpty(['0 minutes', 'Between 1 and 30 minutes', 'Between 31 minutes and 1 hour', 'Between 1 and 2 hours', 'Between 2 and 3 hours', 'More than 3 hours']), widget=widgets.RadioSelectHorizontal, blank=True) timeFriends = models.StringField(label='...spending time with friends?', choices=duplicateChoiceEmpty(['0 minutes', 'Between 1 and 30 minutes', 'Between 31 minutes and 1 hour', 'Between 1 and 2 hours', 'Between 2 and 3 hours', 'More than 3 hours']), widget=widgets.RadioSelectHorizontal, blank=True) timeTwitter = models.StringField(label='...using Twitter?', choices=duplicateChoiceEmpty( ['0 minutes', 'Between 1 and 30 minutes', 'Between 31 minutes and 1 hour', 'Between 1 and 2 hours', 'Between 2 and 3 hours', 'More than 3 hours']), widget=widgets.RadioSelectHorizontal, blank=True) timeSocialMedia = models.StringField(label='...using social media apps other than Twitter?', choices=duplicateChoiceEmpty( ['0 minutes', 'Between 1 and 30 minutes', 'Between 31 minutes and 1 hour', 'Between 1 and 2 hours', 'Between 2 and 3 hours', 'More than 3 hours']), widget=widgets.RadioSelectHorizontal, blank=True) timeNews = models.StringField(label='...reading or listening to news about politics and current affairs?', choices=duplicateChoiceEmpty( ['0 minutes', 'Between 1 and 30 minutes', 'Between 31 minutes and 1 hour', 'Between 1 and 2 hours', 'Between 2 and 3 hours', 'More than 3 hours']), widget=widgets.RadioSelectHorizontal, blank=True) timeAlone = models.StringField(label=' ...watching TV or movies by yourself?', choices=duplicateChoiceEmpty( ['0 minutes', 'Between 1 and 30 minutes', 'Between 31 minutes and 1 hour', 'Between 1 and 2 hours', 'Between 2 and 3 hours', 'More than 3 hours']), widget=widgets.RadioSelectHorizontal, blank=True) closeParty = models.StringField(label='Do you usually think of yourself as close to any particular party?', choices=duplicateChoice(['No, I am Independent', 'Yes, the Republican Party', 'Yes, the Democratic Party', 'Yes, another party']), blank=True) thermometerDemocratic = models.StringField(label='Democratic Party', choices=duplicateChoiceEmpty(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']), widget=widgets.RadioSelectHorizontal, blank=True) thermometerRepublican = models.StringField(label='Republican Party', choices=duplicateChoiceEmpty( ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']), widget=widgets.RadioSelectHorizontal, blank=True) thermometerBiden = models.StringField(label='Joe Biden (46th U.S. President)', choices=duplicateChoiceEmpty( ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']), widget=widgets.RadioSelectHorizontal, blank=True) thermometerTrump = models.StringField(label='Donald Trump (45th U.S. President)', choices=duplicateChoiceEmpty( ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']), widget=widgets.RadioSelectHorizontal, blank=True) trueBidenCovid = models.StringField( label='President Joe Biden tested Positive For COVID-19 and was hospitalized just before taking charge', choices=duplicateChoiceEmpty(['True', 'False', "Don't know"]), widget=widgets.RadioSelectHorizontal, blank=True) trueBidenFacebook = models.StringField( label='Biden administration has repeatedly made statements criticizing Facebook and other platforms due to the spread of vaccine disinformation', choices=duplicateChoiceEmpty(['True', 'False', "Don't know"]), widget=widgets.RadioSelectHorizontal, blank=True) trueBeatty = models.StringField( label='Representative Joyce Beatty, was arrested on Capitol Hill along with eight activists who were demonstrating for voting rights', choices=duplicateChoiceEmpty(['True', 'False', "Don't know"]), widget=widgets.RadioSelectHorizontal, blank=True) trueMerkel = models.StringField( label='Far-left candidate Angela Merkel recently won an election to become the President of France until 2030', choices=duplicateChoiceEmpty(['True', 'False', "Don't know"]), widget=widgets.RadioSelectHorizontal, blank=True) trueShooting = models.StringField( label='Nationals Game in Washington was recently halted after shooting outside stadium and fans poured out of Nationals Park', choices=duplicateChoiceEmpty(['True', 'False', "Don't know"]), widget=widgets.RadioSelectHorizontal, blank=True) followsPolitics = models.StringField(label='Thinking back over the last month, how closely did you follow US politics?', choices=duplicateChoice(['Not at all closely', 'Somewhat closely', 'Very closely']), widget=widgets.RadioSelectHorizontal, blank=True) trustOthers = models.StringField(label='If you have to chose, would you say that in general most people can be trusted or that you need to be careful in dealing with people?' , choices=duplicateChoice(['People can be trusted', 'I need to be careful in dealing with people']), widget=widgets.RadioSelectHorizontal, blank=True) othersFairness = models.StringField(label='Do you think that most people would try to take advantage of you if they got the chance, or would they try to be fair?', choices=duplicateChoice(['Most people would try to take advantage of me', 'Most people would try to be fair']), widget=widgets.RadioSelect, blank=True) loneliness = models.StringField( label='How often did you feel isolated from others over the past week?', choices=duplicateChoice(['Hardly ever', 'Some of the time', 'Often']), widget=widgets.RadioSelectHorizontal, blank=True) voteLikely = models.StringField(label="How likely are you to vote in the 2024 US presidential election", choices=duplicateChoice(["Extremely unlikely", "Unlikely", "Likely", 'Extremely likely']), widget=widgets.RadioSelectHorizontal, blank=True) # # newsBiden = models.IntegerField(label='Thinking back over the last month, how closely did you follow news about Joe Biden?',choices=[[0, 'Not at all closely'], [1, 'Somewhat closely'], [2, 'Rather closely'], [3, 'Very closely']],widget=widgets.RadioSelect) # interestPolitics = models.IntegerField(label='How interested would you say you are in politics are you?', choices=[[0, 'Not at all interested'], [1, 'Hardly interested'], [2, 'Quite interested'], [3, 'Very interested']], widget=widgets.RadioSelect) # ownSlant = models.IntegerField(label='In politics people sometimes talk of left and right. Where would you place yourself on a scale from 0 to 10 where 0 means the left and 10 means the right?', min=0, max=10, widget=widgets.RadioSelect) # # # trustMedia = models.IntegerField(label='In general, how much trust and confidence do you have in the mass media when it comes to reporting the news fully, accurately, and fairly?',choices=[[0, 'Not at all'], [1, 'Hardly'],[2, 'Somehow'], [3, 'Very much']],widget=widgets.RadioSelect) # freedomExpression = models.IntegerField(label='How much would you say the political system in the United States allows people like you to have a say in what the government does?') # internetUsage = models.IntegerField(label='On a typical day, about how much time do you spend using the internet on a computer, tablet, smartphone or other device, whether for work or personal use? Please give your answer in hours and minutes (hours, minutes)') # activeRole = models.IntegerField(label='How able do you think you are to take an active role in a group involved with political issues?') # # trueFalseHaiti = models.StringField(label='The Haitian President Jovenel Moise was shot dead in July and according to Haitian officials, he was assassinated by a band of foreign mercenaries', # choices=[['True', 'True'], ['False', 'False'] , ['Uncertain', 'Uncertain']], widget=widgets.RadioSelectHorizontal) # # voted = models.IntegerField(label='Did you vote in the last [country] national election in November of 2020?', # choices=[[0, 'No'], [1, 'Yes'], [2, 'Not elegible to vote']], # widget=widgets.RadioSelect) # # # trueFalseYellen = models.StringField(label='Janet Yellen, the Treasury secretary said that the China trade deal made by the Trump administration, had failed to address fundamental problems between the two countries', choices=[['True', 'True'], ['False', 'False'], ['Uncertain', 'Uncertain']], widget=widgets.RadioSelectHorizontal) # trueFalseDemocratsTexasVoting = models.StringField(label='Texas Democrats recently meet with Chuck Schumer and Elizabeth Warren as they try to pressure Congress to pass federal voting legislation', choices=[['True', 'True'], ['False', 'False'], ['Uncertain', 'Uncertain']], widget=widgets.RadioSelectHorizontal) # trueFalsePowell = models.StringField(label='Jerome H. Powell, the Federal Reserve chair, recently testified before House and Senate lawmakers and acknowledged to senators that inflation was likely to be out of control unless interest rates increased by the end of the year', choices=[['True', 'True'], ['False', 'False'], ['Uncertain', 'Uncertain']], widget=widgets.RadioSelectHorizontal) # trueFalseIvy = models.StringField(label='Most than half of the Ivy league universities recently stood trial for allegedly discriminating against African-American applicants in its admission process', choices=[['True', 'True'], ['False', 'False'], ['Uncertain', 'Uncertain']], widget=widgets.RadioSelectHorizontal) # trueFalseWarren = models.StringField(label="Senator Elizabeth Warren's DNA test results show that she has no native American ancestry",choices=[['True', 'True'], ['False', 'False'], ['Uncertain', 'Uncertain']],widget=widgets.RadioSelectHorizontal) # country = models.StringField(label="In which country do you currently reside?", choices=duplicateChoice(Constants.countries))