from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import re author = 'S. Chang' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'tg2021' players_per_group = None num_rounds = 1 instructions_template0 = 'tg2021/Example0.html' instructions_template = 'tg2021/Example1.html' instructions_template2 = 'tg2021/Example2.html' instructions_template3 = 'tg2021/Example3.html' intro = 'tg2021/intro_template.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): mturkID = models.StringField( label="" ) def mturkID_error_message(self, value): print('value is', value) if not re.match('^[A]', value): return 'Please enter a valid MTurk Worker ID beginning with the letter "A".' age = models.StringField( choices=['18–24 years', '25–29 years', '30–34 years', '35–39 years', '40–44 years', '45–49 years', '50–54 years', '55–59 years', '60–64 years', '65 years or older'], label='How old are you?', widget=widgets.RadioSelect) gender = models.StringField( choices=['Male', 'Female', 'Something else'], label='What is your gender?', widget=widgets.RadioSelect) race1 = models.StringField( choices=['White', 'Black or African American', 'Hispanic/Latino(a/x)', 'American Indian or Alaska Native', 'Asian', 'Native Hawaiian or Pacific Islander', 'Middle Eastern or North African', 'Something else'], label='With which of these groups do you most identify?', widget=widgets.RadioSelect) income = models.StringField( choices=['less than $10,000', '$10,000–$19,999', '$20,000–$29,999', '$30,000–$39,999', '$40,000–$49,999', '$50,000–$59,999', '$60,000–$69,999', '$70,000–$79,999', '$80,000–$89,999', '$90,000–$99,999', '$100,000–$149,999', '$150,000 or more'], label='In which of these groups did your total family income, from all sources, fall last year (2021), before taxes?', widget=widgets.RadioSelect ) correct = models.IntegerField() quiz1_max = models.CurrencyField( label='What is the maximum amount Player A can send Player B?', min=0, max=10, blank=True ) quiz2_min = models.CurrencyField( label='What is the minimum amount Player A can send Player B?', min=0, max=10, blank=True ) quiz3_calc = models.CurrencyField( label='If Player A sends §5, how much does Player B receive?', min=0, max=100, blank=True ) quiz3_rule = models.StringField( choices=['(a) You will not be able to link other participants to their contributions', '(b) Other participants will not be able to link you to your contributions', '(c) Both (a) and (b)', '(d) Neither (a) nor (b)'], label='Which of the following statements is true?', widget=widgets.RadioSelect ) contribution = models.CurrencyField( choices=[c(0),c(5),c(10)], widget=widgets.RadioSelect, label='How much money do you want to send the other participant?', ) guess_playerA_r1 = models.CurrencyField( choices=[c(0),c(5),c(10)], widget=widgets.RadioSelect, label='I think Player A will send', ) guess_playerA_r2 = models.CurrencyField( choices=[c(0),c(5),c(10)], widget=widgets.RadioSelect, label='I think Player A will send', ) contribution_round2 = models.CurrencyField( choices=[c(0),c(5),c(10)], widget=widgets.RadioSelect, label='How much money do you want to send the other participant?', ) total_bonus = models.FloatField() check4xamount = models.CurrencyField( min=0, max=50, label="" ) check4xamount_round2 = models.CurrencyField( min=0, max=50, label="" ) guess_alter_1a = models.StringField( label="I think the other participant will", choices=['keep §20 and send back §0', 'keep §8 and send back §12'], widget=widgets.RadioSelect ) guess_alter_1b = models.StringField( label="I think the other participant will", choices=['keep §40 and send back §0', 'keep §18 and send back §22'], widget=widgets.RadioSelect ) guess_alter_2a = models.StringField( label="I think the other participant will", choices=['keep §20 and send back §0', 'keep §8 and send back §12'], widget=widgets.RadioSelect ) guess_alter_2b = models.StringField( label="I think the other participant will", choices=['keep §40 and send back §0', 'keep §18 and send back §22'], widget=widgets.RadioSelect ) reason_contribution = models.LongStringField( label="", blank=True ) # The below objects are variables used in surveys to store personal information # They can be edited by changing choices or label # The characters in label will be displayed as a question # The choices will be displayed as choices of the question party = models.StringField( choices=['Republican', 'Independent', 'Democrat', 'Something else'], label='Generally speaking, do you consider yourself a Republican, ' 'an independent, a Democrat or something else?', widget=widgets.RadioSelect) party_strength = models.StringField( choices=['Strong','Not very strong'], widget=widgets.RadioSelect) party_closer = models.StringField( choices=['Closer to the Republican Party', 'Neither', 'Closer to the Democratic Party'], label='Do you think of yourself as closer to the Republican or Democratic Party?', widget=widgets.RadioSelect) vote = models.StringField( choices=['Donald Trump', 'Joe Biden', 'I voted for someone else', 'I did not vote for president in 2020'], label='For whom did you vote for president in 2020?', widget=widgets.RadioSelect) born = models.StringField( choices=['United States', 'U.S. Territory (e.g., Puerto Rico)', 'Some other country'], label='Where were you born?', widget=widgets.RadioSelect) educ = models.StringField( choices=['Less than high school', 'High school/GED', 'Some college', "2-year degree (Associate's)", "4-year degree(Bachelor's)", 'Graduate of professional degree'], label='What is the highest level of education you have completed?', widget=widgets.RadioSelect) fin_sat = models.StringField( choices=['Pretty well satisfied', 'More or less satisfied', 'Not satisfied at all'], label='So far as you and your family are concerned, would you say that you are pretty well satisfied with your present financial situation, more or less satisfied, or not satisfied at all?', widget=widgets.RadioSelect) zipcode = models.StringField( label="" ) def zipcode_error_message(self, value): print('value is', value) if not re.match('^[0-9]{5}$', value): return 'Please enter your 5-digit zipcode.' # The next few questions are about the group activity you took part in along with three other people. Think back to this activity. act_purpose = models.LongStringField( label='What do you think was the purpose of the activities? Please write your response in the space below.', blank=True ) act_reaction = models.LongStringField( label='Was there anything strange or surprising about the activities? Were you suspicious about anything during the activities? Please write your response in the space below.', blank=True ) mem_r1_age = models.StringField( choices=['18–24 years', '25–29 years', '30–34 years', '35–39 years', '40–44 years', '45–49 years', '50–54 years', '55–59 years', '60–64 years', '65 years and older'], label="", widget=widgets.RadioSelect) mem_r1_gender = models.StringField( choices=['Male', 'Female', 'Something else'], label="", widget=widgets.RadioSelect) mem_r1_race = models.StringField( choices=['White', 'Black or African American', 'Hispanic', 'American Indian or Alaska Native', 'Asian', 'Native Hawaiian or Pacific Islander', 'Middle Eastern or North African', 'Something else'], label="", widget=widgets.RadioSelect) mem_r1_income = models.StringField( choices=['less than $10,000', '$10,000–$19,999', '$20,000–$29,999', '$30,000–$39,999', '$40,000–$49,999', '$50,000–$59,999', '$60,000–$69,999', '$70,000–$79,999', '$80,000–$89,999', '$90,000–$99,999', '$100,000–$149,999', '$150,000 or more'], label='', widget=widgets.RadioSelect ) mem_r2_age = models.StringField( choices=['18–24 years', '25–29 years', '30–34 years', '35–39 years', '40–44 years', '45–49 years', '50–54 years', '55–59 years', '60–64 years', '65 years and older'], label='', widget=widgets.RadioSelect) mem_r2_gender = models.StringField( choices=['Male', 'Female', 'Something else'], label='', widget=widgets.RadioSelect) mem_r2_race = models.StringField( choices=['White', 'Black or African American', 'Hispanic', 'American Indian or Alaska Native', 'Asian', 'Native Hawaiian or Pacific Islander', 'Middle Eastern or North African', 'Something else'], label='', widget=widgets.RadioSelect) mem_r2_income = models.StringField( choices=['less than $10,000', '$10,000–$19,999', '$20,000–$29,999', '$30,000–$39,999', '$40,000–$49,999', '$50,000–$59,999', '$60,000–$69,999', '$70,000–$79,999', '$80,000–$89,999', '$90,000–$99,999', '$100,000–$149,999', '$150,000 or more'], label='', widget=widgets.RadioSelect ) label = models.StringField() role_round1 = models.StringField() role_round2 = models.StringField() playerA_sends_r1 = models.CurrencyField() playerA_sends_r2 = models.CurrencyField() playerB_race = models.StringField() playerB_gender = models.StringField() playerB_age = models.StringField() playerB_income = models.StringField() playerB_contribution = models.CurrencyField() playerC_race = models.StringField() playerC_gender = models.StringField() playerC_age = models.StringField() playerC_income = models.StringField() playerC_contribution = models.CurrencyField() pick_round = models.IntegerField() ego_payoff = models.IntegerField() ego_payoff_USD = models.FloatField() ego_kept_r1 = models.IntegerField() ego_kept_r2 = models.IntegerField() final_conversion = models.FloatField() guess_gap_B = models.IntegerField() guess_gap_C = models.IntegerField() guessed_B = models.IntegerField() guessed_C = models.IntegerField() total_correct_guesses = models.IntegerField() payoff_correct_guesses = models.FloatField() text_correct_guesses = models.StringField() contribution_dp = models.IntegerField() contribution_4x = models.IntegerField() contribution_round2_dp = models.IntegerField() contribution_round2_4x = models.IntegerField() B_r1_c5_sent = models.IntegerField() B_r1_c5_kept = models.IntegerField() B_r1_c10_sent = models.IntegerField() B_r1_c10_kept = models.IntegerField() B_r2_c5_sent = models.IntegerField() B_r2_c5_kept = models.IntegerField() B_r2_c10_sent = models.IntegerField() B_r2_c10_kept = models.IntegerField() chosen_alter1_race = models.StringField() chosen_alter1_gender = models.StringField() chosen_alter1_age = models.StringField() chosen_alter1_income = models.StringField() chosen_alter2_race = models.StringField() chosen_alter2_gender = models.StringField() chosen_alter2_age = models.StringField() chosen_alter2_income = models.StringField() player_choice = models.StringField( choices=['Participant 1','Participant 2'], label='Please, tell us which participant you would like to be paired with:', widget=widgets.RadioSelect) selection = models.IntegerField() mturk_ID1 = models.StringField( label = "To receive the compensation HIT, please enter your Amazon Mechanical Turk ID here:", blank = True ) mturk_ID2 = models.StringField( label = "To receive the compensation HIT, please enter your Amazon Mechanical Turk ID here:", blank = True ) q_lf1 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf2 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf3 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf4= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf5 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf6 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf7 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf8 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf9 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf10= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf11 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lf12 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm1 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm2 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm3 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm4= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm5 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm6 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm7 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm8 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm9 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm10= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm11 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_lm12 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf1 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf2 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf3 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf4= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf5 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf6 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf7 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf8 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf9 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf10= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf11 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wf12 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm1 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm2 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm3 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm4= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm5 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm6 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm7 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm8 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm9 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm10= models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm11 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) q_wm12 = models.StringField( choices=['Yes','No'], label='Did you see this person earlier?', widget=widgets.RadioSelect) wallet = models.StringField( choices=['Extremely likely','Moderately likely','Slightly likely','Neither likely nor unlikely', 'Slightly unlikely','Moderately unlikely','Extremely unlikely'], label='', widget=widgets.RadioSelect) risk = models.StringField(choices=['1 - very unwilling', '2', '3', '4', '5', '6','7','8','9','10 - very willing'], label='On a scale of 1 to 10, with 1 being very unwilling, and 10 being very willing, how willing are you to take risks, in general?', widget=widgets.RadioSelectHorizontal) show_lf1 = models.IntegerField() show_lf2 = models.IntegerField() show_lf3 = models.IntegerField() show_lf4 = models.IntegerField() show_lf5 = models.IntegerField() show_lf6 = models.IntegerField() show_lf7 = models.IntegerField() show_lf8 = models.IntegerField() show_lf9 = models.IntegerField() show_lf10 = models.IntegerField() show_lf11 = models.IntegerField() show_lf12 = models.IntegerField() show_lm1 = models.IntegerField() show_lm2 = models.IntegerField() show_lm3 = models.IntegerField() show_lm4 = models.IntegerField() show_lm5 = models.IntegerField() show_lm6 = models.IntegerField() show_lm7 = models.IntegerField() show_lm8 = models.IntegerField() show_lm9 = models.IntegerField() show_lm10 = models.IntegerField() show_lm11 = models.IntegerField() show_lm12 = models.IntegerField() show_wf1 = models.IntegerField() show_wf2 = models.IntegerField() show_wf3 = models.IntegerField() show_wf4 = models.IntegerField() show_wf5 = models.IntegerField() show_wf6 = models.IntegerField() show_wf7 = models.IntegerField() show_wf8 = models.IntegerField() show_wf9 = models.IntegerField() show_wf10 = models.IntegerField() show_wf11 = models.IntegerField() show_wf12 = models.IntegerField() show_wm1 = models.IntegerField() show_wm2 = models.IntegerField() show_wm3 = models.IntegerField() show_wm4 = models.IntegerField() show_wm5 = models.IntegerField() show_wm6 = models.IntegerField() show_wm7 = models.IntegerField() show_wm8 = models.IntegerField() show_wm9 = models.IntegerField() show_wm10 = models.IntegerField() show_wm11 = models.IntegerField() show_wm12 = models.IntegerField() ask_lf1 = models.IntegerField() ask_lf2 = models.IntegerField() ask_lf3 = models.IntegerField() ask_lf4 = models.IntegerField() ask_lf5 = models.IntegerField() ask_lf6 = models.IntegerField() ask_lf7 = models.IntegerField() ask_lf8 = models.IntegerField() ask_lf9 = models.IntegerField() ask_lf10 = models.IntegerField() ask_lf11 = models.IntegerField() ask_lf12 = models.IntegerField() ask_lm1 = models.IntegerField() ask_lm2 = models.IntegerField() ask_lm3 = models.IntegerField() ask_lm4 = models.IntegerField() ask_lm5 = models.IntegerField() ask_lm6 = models.IntegerField() ask_lm7 = models.IntegerField() ask_lm8 = models.IntegerField() ask_lm9 = models.IntegerField() ask_lm10 = models.IntegerField() ask_lm11 = models.IntegerField() ask_lm12 = models.IntegerField() ask_wf1 = models.IntegerField() ask_wf2 = models.IntegerField() ask_wf3 = models.IntegerField() ask_wf4 = models.IntegerField() ask_wf5 = models.IntegerField() ask_wf6 = models.IntegerField() ask_wf7 = models.IntegerField() ask_wf8 = models.IntegerField() ask_wf9 = models.IntegerField() ask_wf10 = models.IntegerField() ask_wf11 = models.IntegerField() ask_wf12 = models.IntegerField() ask_wm1 = models.IntegerField() ask_wm2 = models.IntegerField() ask_wm3 = models.IntegerField() ask_wm4 = models.IntegerField() ask_wm5 = models.IntegerField() ask_wm6 = models.IntegerField() ask_wm7 = models.IntegerField() ask_wm8 = models.IntegerField() ask_wm9 = models.IntegerField() ask_wm10 = models.IntegerField() ask_wm11 = models.IntegerField() ask_wm12 = models.IntegerField() if20 = models.StringField( choices=['Keep §20 and send §0 back to Player A.','Keep §8 and send §12 back to Player A.'], label='If I receive §20, I will', widget=widgets.RadioSelect) if40 = models.StringField( choices=['Keep §40 and send §0 back to Player A.','Keep §18 and send §22 back to Player A.'], label='If I receive §40, I will', widget=widgets.RadioSelect) if20_r2 = models.StringField( choices=['Keep §20 and send §0 back to Player A.','Keep §8 and send §12 back to Player A.'], label='If I receive §20, I will', widget=widgets.RadioSelect) if40_r2 = models.StringField( choices=['Keep §40 and send §0 back to Player A.','Keep §18 and send §22 back to Player A.'], label='If I receive §40, I will', widget=widgets.RadioSelect)