from otree.api import * import numpy as np class C(BaseConstants): NAME_IN_URL = 'survey' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): q1 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Algorithm 1"], [2, "Algorithm 2"]], label="Which algorithm created the lists for rounds 1-10 of the experiment?") q2 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Algorithm 1"], [2, "Algorithm 2"]], label="Which algorithm created the lists for rounds 11-20 of the experiment?") q3 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Algorithm 1"], [2, "Algorithm 2"]], label="Which algorithm created the lists for rounds 21-30 of the experiment?") q4 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Not helpful at all"], [2, "Slightly helpful"], [3, "Moderately helpful"], [4, "Helpful"], [5, "Very helpful"]], label="How helpful did you find algorithm 1?") q5 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Not helpful at all"], [2, "Slightly helpful"], [3, "Moderately helpful"], [4, "Helpful"], [5, "Very helpful"]], label="How helpful did you find algorithm 1?") q6 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Not confident at all"], [2, "Somewhat confident"], [3, "Moderately confident"], [4, "Confident"], [5, "Completely confident"]], label = "How confident are you that you understand how algorithm 1 orders lotteries?") q7 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, "Not confident at all"], [2, "Somewhat confident"], [3, "Moderately confident"], [4, "Confident"], [5, "Completely confident"]], label = "How confident are you that you understand how algorithm 2 orders lotteries?") open1 = models.LongStringField(label = "What did you like/dislike about algorithm 1's way of ordering the list?") open2 = models.LongStringField(label = "What did you like/dislike about algorithm 2's way of ordering the list?") open3 = models.LongStringField(label = "What did you have in mind when you were asked to choose between algorithm 1 and algorithm 2?") open4 = models.LongStringField(label = "Please share any additional comments or suggestions you may have about the algorithms or the experiment in general.") class Survey(Page): form_model = "player" form_fields = ["q1", "q2", "q3", "q4", "q5", "q6", "q7"] def vars_for_template(player: Player): participant = player.participant if participant.algo_order[0]=="eu": col1 = participant.eu_col col2 = participant.steering_col else: col1 = participant.steering_col col2 = participant.eu_col return { "col1" : col1, "col2" : col2 } class Survey_open(Page): form_model = "player" form_fields = ["open1", "open2", "open3", "open4"] def vars_for_template(player: Player): participant = player.participant if participant.algo_order[0]=="eu": col1 = participant.eu_col col2 = participant.steering_col else: col1 = participant.steering_col col2 = participant.eu_col return { "col1" : col1, "col2" : col2 } def before_next_page(player: Player, timeout_happened): participant = player.participant participant.chosen_section = np.random.choice([1, 2, 3]) def display_lottery(lot, prizes): p3 = "P(" + str(prizes[2]) + ") = " + str(lot['p3']) + "%, " p2 = "P(" + str(prizes[1]) + ") = " + str(lot['p2']) + "%, " p1 = "P(" + str(prizes[0]) + ") = " + str(lot['p1']) + "%" return "[" + p3+p2+p1 + "]" class FinishExp(Page): # this should go after survey probably def vars_for_template(player: Player): participant = player.participant chosen_section = participant.chosen_section selected_round = "" selected_lottery = "" message = "" algo_wtp = "" outcome = "" if chosen_section==1: payoff = participant.payoff1 message = participant.message1 elif chosen_section==2: payoff = participant.payoff2 selected_round = str(participant.selected_round2) selected_lottery = display_lottery(participant.selected_lottery2, [0,5,10]) outcome = str(participant.outcome2) else: payoff = participant.payoff3 selected_round = participant.selected_round3 selected_lottery = display_lottery(participant.selected_lottery3, [0,5,10]) algo_wtp = participant.algo_wtp outcome = str(participant.outcome3) return { "chosen_section" : chosen_section, "selected_round" : selected_round, "selected_lottery" : selected_lottery, "outcome" : outcome, "algo_wtp" : algo_wtp, "message" : message, "payoff" : payoff } page_sequence = [Survey, Survey_open, FinishExp]