from otree.api import * from django.utils.safestring import mark_safe doc = """ quiz """ class C(BaseConstants): NAME_IN_URL = 'quiz' PLAYERS_PER_GROUP = None NUM_ROUNDS = 12 FORM_TEMPLATE = __name__ + '/form.html' def make_boo_field(label): return models.BooleanField( choices=[[True, "a. True"], [False, "b. False"]], label=label, ) def make_currency_field(label): return models.FloatField( label=label, )#currency field does not work for some reason class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): quiz1 = make_boo_field("1. You are in a group with 11 other players.") quiz2 = make_boo_field(mark_safe("2. Your role (Seller or Buyer) will remain the same throughout the experiment.")) quiz3 = make_boo_field(mark_safe("3. A buyer is informed whether he/she has a major or minor problem " "before making any decisions.")) quiz4 = models.IntegerField( choices=[[0, mark_safe("a. A major treatment can solve either a major or minor problem. " "A minor treatment can solve only a minor problem.")], [1, mark_safe("b. A minor treatment can solve either a major or minor problem. " "A major treatment can solve only a minor problem.")], [2, mark_safe("c. A major treatment can solve only a major problem. " "A minor treatment can solve only a minor problem.")], [3, mark_safe("d. A minor treatment can solve only a major problem. " "A major treatment can solve only a minor problem.")]], widget=widgets.RadioSelect, label=mark_safe("4. A buyer may solve the problem by purchasing a treatment offered by a seller. " "Which of the following is correct?")) quiz5 = make_boo_field(mark_safe("5. A seller knows that he/she is the buyer’s first or second visit (seller 1 or seller 2)")) quiz6 = models.BooleanField(choices=[[True, "a. True"], [False, "b. False"]]) quiz7 = make_boo_field(mark_safe("7. Suppose the report indicates that the buyer has a major problem, a major treatment will be " "offered to the buyer regardless of the seller’s decision.")) quiz8 = make_boo_field(mark_safe("8. A buyer is paired with a seller in a different group.")) quiz9 = models.IntegerField( choices=[[0, mark_safe("a. Seller 1 sells a minor treatment to the buyer. ")], [1, mark_safe("b. Seller 1 sells a major treatment to the buyer. ")], [2, mark_safe("c. The buyer rejects a minor treatment from Seller 1, pays a search cost, and another seller " "(seller 2) is randomly drawn. Seller 2’s treatment is sold to the buyer. ")], [3, mark_safe("d. The buyer rejects a minor treatment from Seller 1, pays a search cost, " "and Seller 1 sells a major treatment to the buyer.")]], widget=widgets.RadioSelect, label=mark_safe("9. Suppose Seller 1 offers a minor treatment. A buyer accepts a major treatment but rejects " "a minor treatment. Which of the following is correct?") ) quiz10 = make_currency_field(mark_safe("10. Suppose a seller sells a major treatment to a buyer. How much does the seller earn?")) quiz11 = make_currency_field(mark_safe("11. Suppose a Buyer has a major problem, but he/she purchased a minor treatment " "from Seller 1. How much does the Buyer earn?")) quiz121 = make_currency_field(mark_safe("Seller 1 earns")) quiz122 = make_currency_field(mark_safe("Seller 2 earns")) quiz123 = make_currency_field(mark_safe("The Buyer earns")) incorrect_attempt = models.IntegerField(initial=0) def get_form_fields(player: Player): if player.round_number == 1: print('t') form_fields = ['quiz1'] elif player.round_number == 2: form_fields = ['quiz2'] else: form_fields = ['quiz3'] return form_fields def get_solutions(player: Player): if player.session.config['within'] == 1: return [dict(quiz1=True), dict(quiz2=True), dict(quiz3=False), dict(quiz4=0), dict(quiz5=False), dict(quiz6=True), dict(quiz7=True), dict(quiz8=False), dict(quiz9=2), dict(quiz10=2.5), dict(quiz11=-2), dict(quiz121=0), dict(quiz122=2.5), dict(quiz123=-0.10) ] elif player.session.config['within'] == 2: return [dict(quiz1=True), dict(quiz2=True), dict(quiz3=False), dict(quiz4=0), dict(quiz5=False), dict(quiz6=True), dict(quiz7=True), dict(quiz8=False), dict(quiz9=2), dict(quiz10=2.5), dict(quiz11=-2), dict(quiz121=0), dict(quiz122=2.5), dict(quiz123=5.90) ] elif player.session.config['within'] == 3: return [dict(quiz1=True), dict(quiz2=True), dict(quiz3=False), dict(quiz4=0), dict(quiz5=False), dict(quiz6=True), dict(quiz7=True), dict(quiz8=False), dict(quiz9=2), dict(quiz10=2.5), dict(quiz11=-2), dict(quiz121=0), dict(quiz122=2.5), dict(quiz123=-1.10) ] else: return [dict(quiz1=True), dict(quiz2=True), dict(quiz3=False), dict(quiz4=0), dict(quiz5=False), dict(quiz6=True), dict(quiz7=True), dict(quiz8=False), dict(quiz9=2), dict(quiz10=2.5), dict(quiz11=-2), dict(quiz121=0), dict(quiz122=2.5), dict(quiz123=4.90) ] def get_explanations(player:Player): if player.session.config['within'] == 1 or player.session.config['within'] == 3: #print('ha') return {1: mark_safe('
Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: "At the beginning of the experiment, ' 'you will be randomly placed into a group of 12 participants, you and 11 others' ' in the lab with you today."
'), 2: mark_safe('Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: "Your role ' 'and the members of your group will remain the same throughout the experiment.”
'), 3: mark_safe('Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: “However, the ' 'buyer does not know whether he/she has a major or minor problem before making any decisions.”
'), 4: mark_safe('Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: A major ' 'treatment can solve either a major or minor problem. A minor treatment can solve only a minor problem.”
'), 5: mark_safe('Your answer is incorrect. Please try again.
Hint: the instructions mention: “The seller does not know ' 'if he/she is the buyer’s first or second visit (Seller 1 or Seller 2, respectively) ' 'and does not know the identity of any buyers.”
'), 6: mark_safe('Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: “However, the ' 'report is only correct {} of the time. This means, out of every 100 reports received, '.format(player.session.config['beta']))+ mark_safe('on average, there are {} reports that show the buyer’s true problem '.format(player.session.config['beta']))+ mark_safe('and {} reports that is incorrect.”
'.format(100-player.session.config['beta'])), 7: mark_safe('Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions:' '“If the report shows that the buyer has a major problem, a major treatment will be offered to the ' 'buyer regardless of the seller’s decision.”
'), 8: mark_safe('Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: “Each buyer is' ' randomly paired with a seller in their group without knowing the seller’s identity.”
'), 9: mark_safe('Your answer is incorrect. Please try again.
Hint: A buyer rejects a minor treatment which is offered ' 'by Seller 1. The instructions mention: “Then he/she decides whether to accept the treatment ' 'offered to them by that seller (Seller 1).
' 'Your answer is incorrect. Please try again.
Hint: The instructions mention: “For each treatment' ' he/she offers, ' '
Your answer is incorrect. Please try again.
Hint: the instructions mention: “The buyer may earn the ' 'following earnings:
' 'Your answer here is incorrect. Please try again.
') } else: #print('hehe') return {1: mark_safe( 'Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: "At the beginning of the experiment, ' 'you will be randomly placed into a group of 12 participants, you and 11 others' ' in the lab with you today."
'), 2: mark_safe( 'Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: "Your role ' 'and the members of your group will remain the same throughout the experiment.”
'), 3: mark_safe( 'Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: “However, the ' 'buyer does not know whether he/she has a major or minor problem before making any decisions.”
'), 4: mark_safe( 'Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: A major ' 'treatment can solve either a major or minor problem. A minor treatment can solve only a minor problem.”
'), 5: mark_safe( 'Your answer is incorrect. Please try again.
Hint: the instructions mention: “The seller does not know ' 'if he/she is the buyer’s first or second visit (Seller 1 or Seller 2, respectively) ' 'and does not know the identity of any buyers.”
'), 6: mark_safe( 'Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: “However, the ' 'report is only correct {} of the time. This means, out of every 100 reports received, '.format( player.session.config['beta'])) + mark_safe('on average, there are {} reports that show the buyer’s true problem '.format( player.session.config['beta'])) + mark_safe('and {} reports that is incorrect.”
'.format(100 - player.session.config['beta'])), 7: mark_safe( 'Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions:' '“If the report shows that the buyer has a major problem, a major treatment will be offered to the ' 'buyer regardless of the seller’s decision.”
'), 8: mark_safe( 'Your answer is incorrect. Please try again.
Hint: as mentioned in the instructions: “Each buyer is' ' randomly paired with a seller in their group without knowing the seller’s identity.”
'), 9: mark_safe( 'Your answer is incorrect. Please try again.
Hint: A buyer rejects a minor treatment which is offered ' 'by Seller 1. The instructions mention: “Then he/she decides whether to accept the treatment ' 'offered to them by that seller (Seller 1).
' 'Your answer is incorrect. Please try again.
Hint: The instructions mention: “For each treatment' ' he/she offers, ' '
Your answer is incorrect. Please try again.
Hint: the instructions mention: “The buyer may earn the ' 'following earnings:
' 'Your answer here is incorrect. Please try again.
') } # PAGES class IntroQ(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Q1(Page): form_model = 'player' @staticmethod def get_form_fields(player: Player): all_fields = ['quiz1', 'quiz2', 'quiz3', 'quiz4', 'quiz5', 'quiz6', 'quiz7', 'quiz8', 'quiz9', 'quiz10', 'quiz11', 'quiz121', 'quiz122', 'quiz123' ] if player.round_number == 12: form_fields = ['quiz121', 'quiz122', 'quiz123'] else: form_fields = [all_fields[player.round_number - 1]] return form_fields @staticmethod def error_message(player: Player, values): all_solutions = get_solutions(player) all_explanations = get_explanations(player) explanation = all_explanations[player.round_number] if player.round_number == 12: if player.session.config['within'] == 1: solution = dict(quiz121=0, quiz122=2.5, quiz123=-0.1) con_earnings = -0.1 elif player.session.config['within'] == 2: solution = dict(quiz121=0, quiz122=2.5, quiz123=5.9) con_earnings = 5.9 elif player.session.config['within'] == 3: solution = dict(quiz121=0, quiz122=2.5, quiz123=-1.1) con_earnings = -1.1 else: solution = dict(quiz121=0, quiz122=2.5, quiz123=4.9) con_earnings = 4.9 #print(values,solution) errors = {f: explanation for f in solution if values[f] != solution[f]} a = mark_safe('Hint: For the seller, The instructions mention: “For each treatment' ' he/she offers,
' '