import random import requests import json from otree.api import * from . import models author = 'Razvan' doc = """ Attention check """ class C(BaseConstants): NAME_IN_URL = 'Instructions' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 HINT_1 = 'The "Introduction" section of the instructions will help you answer this question. Please try answering the question again' HINT_2 = 'The "Introduction" section of the instructions will help you answer this question. Please try answering the question again' HINT_3 = 'The "Introduction" section of the instructions will help you answer this question. Please try answering the question again' HINT_4 = 'The "Employee decides how many winning balls to buy" section of the instructions will help you answer this question. Please try answering the question again' HINT_5 = 'The "Employee decides how many winning balls to buy" section of the instructions will help you answer this question. Please try answering the question again' HINT_6 = 'The "Employee decides how many winning balls to buy" section of the instructions will help you answer this question. Please try answering the question again' NUMBER_QUESTIONS = 6 ATTEMPTS = 1000 CORRECT_1 = 2 CORRECT_2 = 2 CORRECT_3 = 1 CORRECT_4 = 1 CORRECT_5 = 2 CORRECT_6 = 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): understanding_questions_wrong_attempts = models.PositiveIntegerField(initial=0) correct_answers = models.PositiveIntegerField(initial=0) question_1 = models.IntegerField( label="At the beginning of each period, I will be randomly assigned to the role of Employee or the role of Supervisor.", choices= [[1, 'True'], [2, 'False']], widget=widgets.RadioSelect, ) question_2 = models.IntegerField( label="I will be interacting with different other participants in each period.", choices= [[1, 'True'], [2, 'False']], widget=widgets.RadioSelect, ) question_3 = models.IntegerField( label="Each point that the Employee invests in any of the three projects increases the Supervisor’s payoff with three points.", choices= [[1, 'True'], [2, 'False']], widget=widgets.RadioSelect, ) question_4 = models.IntegerField( label="Regardless of what information they collect, the Supervisor will learn how many points the Employee invested in Project A every period.", choices= [[1, 'True'], [2, 'False']], widget=widgets.RadioSelect, ) question_5 = models.IntegerField( label="Regardless of what information they collect, the Supervisor will learn how many points the Employee invested in Project B every period.", choices= [[1, 'True'], [2, 'False']], widget=widgets.RadioSelect, ) question_6 = models.IntegerField( label="The Supervisor pays the Employee’s bonus from their own pocket.", choices= [[1, 'True'], [2, 'False']], widget=widgets.RadioSelect, ) question_1_incorrect_answers = models.PositiveIntegerField(initial=0) question_2_incorrect_answers = models.PositiveIntegerField(initial=0) question_3_incorrect_answers = models.PositiveIntegerField(initial=0) question_4_incorrect_answers = models.PositiveIntegerField(initial=0) question_5_incorrect_answers = models.PositiveIntegerField(initial=0) question_6_incorrect_answers = models.PositiveIntegerField(initial=0) # def question_1_error_message(player, value): # print('value is', value) # if value != C.CORRECT_1 and player.understanding_questions_wrong_attempts<4: # player.understanding_questions_wrong_attempts=player.understanding_questions_wrong_attempts+1 # return 'Cannot offer more than your remaining budget' # def question_2_error_message(player, value): # print('value is', value) # if value != C.CORRECT_2 and player.understanding_questions_wrong_attempts<4: # player.understanding_questions_wrong_attempts=player.understanding_questions_wrong_attempts+1 # return 'Cannot offer more than your remaining budget' # FUNCTIONS def creating_session(subsession: Subsession): if subsession.round_number == 1: for p in subsession.get_players(): if 'disaggregated' in subsession.session.config: p.participant.vars['disaggregated'] = subsession.session.config['disaggregated'] else: p.participant.vars['disaggregated'] = random.choice([0, 1]) if 'expensive' in subsession.session.config: p.participant.vars['expensive'] = subsession.session.config['expensive'] else: p.participant.vars['expensive'] = random.choice([0, 1]) # PAGES class Quiz(Page): template_name = 'attention/test.html' form_model = 'player' form_fields = ['question_1', 'question_2','question_3', 'question_4','question_5', 'question_6'] @staticmethod def error_message(player, values): solutions = dict( question_1=C.CORRECT_1, question_2=C.CORRECT_2, question_3=C.CORRECT_3, question_4=C.CORRECT_4, question_5=C.CORRECT_5, question_6=C.CORRECT_6, ) hints = dict( question_1=C.HINT_1, question_2=C.HINT_2, question_3=C.HINT_3, question_4=C.HINT_4, question_5=C.HINT_5, question_6=C.HINT_6, ) question_names = dict( question_1='question_1_incorrect_answers', question_2='question_2_incorrect_answers', question_3='question_3_incorrect_answers', question_4='question_4_incorrect_answers', question_5='question_5_incorrect_answers', question_6='question_6_incorrect_answers', ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name] and player.understanding_questions_wrong_attempts