import random from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'news_prosumers_6' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): for p in subsession.get_players(): TASK = random.randint(1, 3) PART = random.randint(1, 2) print(PART, TASK) p.PAY_chosen_part = PART p.PAY_chosen_task = TASK participant = p.participant participant.prolific_link = subsession.session.config['prolific_link'] class Group(BaseGroup): pass class Player(BasePlayer): PAY_chosen_task = models.IntegerField() PAY_chosen_part = models.IntegerField() PAY_endowment_left = models.CurrencyField() PAY_chosen_task_totalernings = models.CurrencyField() PAY_chosen_task_earnings = models.CurrencyField() # Questionnaire Q1 = models.IntegerField(min=1920, max=2006) Q2 = models.StringField(choices=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]) Q3 = models.StringField(widget=widgets.RadioSelect, choices=["Male", "Female", "Intersex", "I prefer not to say"]) Q4 = models.StringField(widget=widgets.RadioSelect, choices=["Man", "Woman", "Transgender", "Gender fluid", "Gender neutral", "Gender neutral", "Non-binary", "I prefer not to say"]) Q5 = models.StringField(widget=widgets.RadioSelect, choices=["Nothing", "Elementary", "High school", "University Degree", "PhD", "Other"], label="• What is your level of education?") Q6 = models.StringField(widget=widgets.RadioSelect, choices=["0 – $ 15.000", "$ 15.001 – $ 30.000", "$ 30.001 – $ 50.000", "$ 50.001 – $ 70.000", "$ 70.001 – $ 100.000", "Above $ 100.000"], label="• What is your annual personal income after taxes?") Q7 = models.StringField(widget=widgets.RadioSelect, choices=["Retired", "Unemployed (searching work)", "Unemployed (not searching work)", "Self-employed", "Employee", "Student", "Housewife", "Other"], label="• What is your occupation?") Q8 = models.FloatField() Q9 = models.FloatField() Q10 = models.FloatField() Q11 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Risk Averse)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Fully prepared to take risks)"]], label="11. How do you see yourself: are you generally a " "person who is fully prepared to take risks or do you try " "to avoid taking risks? Please choose the value on the scale," " where the value 0 means: “risk averse” and the value 10 " "means: “fully prepared to take risks”") Q12_driving = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Risk Averse)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Fully prepared to take risks)"]], label="Driving:") Q12_financial = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Risk Averse)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Fully prepared to take risks)"]], label="Financial") Q12_leisure = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Risk Averse)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Fully prepared to take risks)"]], label="Leisure") Q12_occupation = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Risk Averse)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Fully prepared to take risks)"]], label="Occupation") Q12_health = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Risk Averse)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Fully prepared to take risks)"]], label="Health") Q12_faith = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Risk Averse)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Fully prepared to take risks)"]], label="Faith") Q13 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Very Impatient)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Very patient)"]], label="• How would you describe yourself: are you generally an impatient person, " "or someone who always shows great patience? Please choose the value on " "the scale, where the value 0 means: 'Very impatient' and the value " "10 means: 'Very patient'.") Q14 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Not at all Impulsive)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Very impulsive)"]], label='• Do you generally think things over for a long time before acting – ' 'in other words, are you not impulsive at all? Or do you generally act ' 'without thinking things over for long time - in other words, are you ' 'very impulsive? Please choose the value on the scale, where the value ' '0 means: “Not at all Impulsive” and the value 10 means: “Very impulsive”.') Q15 = models.FloatField(min=0, max=1000, label="• Imagine the following situation: Today you unexpectedly " "received 1,000 Euro. How much of this amount would you donate " "to a good cause? (Values between 0 and 1,000 are allowed)") Q16 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Completely unwilling to do so)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Very willing to do so)"]], label="• How willing are you to give to good causes without expecting " "anything in return? Please indicate your answer on a scale from " "0 to 10, where 0 means you are 'completely unwilling to do so' " "and a 10 means you are 'very willing to do so'.") Q17 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0, "0 (Not helpful at all)"], [1, "1"], [2, "2"], [3, "3"], [4, "4"], [5, "5"], [6, "6"], [7, "7"], [8, "8"], [9, "9"], [10, "10 (Very helpful)"]], label='• How much do you think you could improve the performance of other ' 'participants in the coin recognition task by sharing your knowledge? Please' ' choose the value on the scale, where the value 0 means: “Not helpful at ' 'all” and the value 10 means: “Very helpful”. ') Q18 = models.StringField(widget=widgets.RadioSelect, choices=["Never", "Rarely", "Sometimes", "Often", "Usually", "Always"], label="• How often have you been using Euro coins in your life?") comments = models.LongStringField(blank=True, label="Do you have any comments and suggestions?") check_slider_one = models.BooleanField() check_slider_two = models.BooleanField() check_slider_three = models.BooleanField() check_slider_four = models.BooleanField() check_slider_five = models.BooleanField() check_slider_six = models.BooleanField() guess_first_own = models.IntegerField() leavescreen_40 = models.IntegerField(blank=True) leavescreen_41 = models.IntegerField(blank=True) leavescreen_42 = models.IntegerField(blank=True) leavescreen_43 = models.IntegerField(blank=True) leavescreen_44 = models.IntegerField(blank=True) leavescreen_45 = models.IntegerField(blank=True) leavescreen_46 = models.IntegerField(blank=True) leavescreen_47 = models.IntegerField(blank=True) leavescreen_48 = models.IntegerField(blank=True) leavescreen_49 = models.IntegerField(blank=True) leavescreen_50 = models.IntegerField(blank=True) leavescreen_51 = models.IntegerField(blank=True) leavescreen_52 = models.IntegerField(blank=True) leavescreen_53 = models.IntegerField(blank=True) # PAGES class Final_Instructions(Page): form_model = 'player' form_fields = ['leavescreen_40'] class Questionnaire_1(Page): form_model = 'player' form_fields = ['Q1', 'Q2', 'Q3', 'Q4', 'leavescreen_41'] class Questionnaire_2(Page): form_model = 'player' form_fields = ['Q5', 'Q6', 'Q7', 'leavescreen_42'] class Questionnaire_3(Page): form_model = 'player' form_fields = ['Q8', 'Q9', 'Q10', 'leavescreen_43'] class Questionnaire_4a(Page): form_model = 'player' form_fields = ['Q11', 'check_slider_one', 'leavescreen_44'] def error_message(self, value): if value["check_slider_one"] == 0: return 'Please answer a question to move forward' @staticmethod def live_method(player: Player, data): id_slider1 = player.Q11 print(id_slider1) return dict(id_slider1=id_slider1) class Questionnaire_4b(Page): form_model = 'player' form_fields = ['Q12_driving', 'Q12_financial', 'Q12_leisure', 'Q12_occupation', 'Q12_health', 'Q12_faith', 'check_slider_one', 'check_slider_two', 'check_slider_three', 'check_slider_four', 'check_slider_five', 'check_slider_six', 'leavescreen_45'] def error_message(self, value): if value["check_slider_one"] == 0 or value["check_slider_two"] == 0 or value["check_slider_three"] == 0 \ or value["check_slider_four"] == 0 or value["check_slider_five"] == 0 or value["check_slider_six"] == 0: return 'Please answer one or more questions to move forward' class Questionnaire_5a(Page): form_model = 'player' form_fields = ['Q13', 'check_slider_one', 'leavescreen_46'] def error_message(self, value): if value["check_slider_one"] == 0: return 'Please answer a question to move forward' class Questionnaire_5b(Page): form_model = 'player' form_fields = ['Q14', 'check_slider_one', 'leavescreen_47'] def error_message(self, value): if value["check_slider_one"] == 0: return 'Please answer a question to move forward' class Questionnaire_6a(Page): form_model = 'player' form_fields = ['Q15', 'leavescreen_48'] class Questionnaire_6b(Page): form_model = 'player' form_fields = ['Q16', 'check_slider_one', 'leavescreen_49'] def error_message(self, value): if value["check_slider_one"] == 0: return 'Please answer a question to move forward' class Questionnaire_7a(Page): form_model = 'player' form_fields = ['Q17', 'check_slider_one', 'leavescreen_50'] def error_message(self, value): if value["check_slider_one"] == 0: return 'Please answer a question to move forward' class Questionnaire_7b(Page): form_model = 'player' form_fields = ['Q18', 'leavescreen_51'] class Comments(Page): form_model = 'player' form_fields = ['comments', 'leavescreen_52'] @staticmethod def before_next_page(player: Player, timeout_happened): player.PAY_endowment_left = 1.20 - player.participant.NEWS_total_cost if player.PAY_chosen_task == 1: if player.PAY_chosen_part == 1: player.PAY_chosen_task_earnings = player.participant.RET_first_earnings else: player.PAY_chosen_task_earnings = player.participant.RET_second_earnings else: if player.PAY_chosen_task == 2: if player.PAY_chosen_part == 1: player.PAY_chosen_task_earnings = player.participant.GUESS_own_first_earnings else: player.PAY_chosen_task_earnings = player.participant.GUESS_own_second_earnings else: player.PAY_chosen_task_earnings = 0 player.guess_first_own = player.participant.GUESS_own_first player.PAY_chosen_task_totalernings = player.PAY_chosen_task_earnings + player.PAY_endowment_left class Ending(Page): form_model = 'player' form_fields = ['leavescreen_53'] @staticmethod def vars_for_template(player: Player): # import locale # Set the locale to a region that uses "," as decimal separator # locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') news_cost = player.participant.NEWS_total_cost costf = round(news_cost, 2) # cost = locale.format_string("%.2f", costf, grouping=True) earnings = round(player.PAY_chosen_task_earnings, 2) return dict(cost=costf, earnings=earnings) @staticmethod def js_vars(player: Player): link = player.participant.prolific_link return dict(link=link) page_sequence = [ Final_Instructions, Questionnaire_1, Questionnaire_2, Questionnaire_3, Questionnaire_4a, Questionnaire_4b, Questionnaire_5a, Questionnaire_5b, Questionnaire_6a, Questionnaire_6b, Questionnaire_7a, Questionnaire_7b, Comments, Ending ]