from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random debug = True author = "Marco Gutierrez" doc = """ Quiz dinamico para testear el entendimiento. Preguntas aleatorizadas. """ #TODO: randomize question order class Constants(BaseConstants): """ Description: Inherits oTree Class BaseConstants. Defines constants for the experiment these will remain unchanged """ players_per_group = None instructions_template = "C:/Users/Dana/paper2/initial_quiz/templates/initial_quiz/instructions.html" contact_template = "C:/Users/Dana/paper2/initial_quiz/templates/initial_quiz/Contactenos.html" instructions_button = "C:/Users/Dana/paper2/initial_quiz/templates/initial_quiz/instructions_button.html" num_rounds = 1 timer = 20 payment_per_answer = c(1) name_in_url = 'Quiz_inicial' # name in webbrowser # Initial amount allocated to each player endowment = c(3) n_rounds = 3 # for using it on the instructions in initial quiz '''Quiz Answers''' # Answers according to the code quiz_fields = dict( question_1_response=0, question_2_response=1, question_3_response=0, question_4_response=3, ) quiz_questions = ['¿Cuántos será el monto total que recibirá usted por participación su completa en este experimento?', '¿De cuántas rondas constará el experimento?', '¿Cuáles son los roles de los jugadores 1 y 2?', '¿Qué características cumplen todos los jugadores en este juego?'] # Displayed answers quiz_answers = ['S/.5 (participación) + monto en test de comprensión + monto de UNA de las tres rondas (aleatorio)', '3 rondas y 2 "breaks" de 1 minuto cada uno', 'J2: decide sobre la dotación de ambos. J1: espera mientras J2 decide.', 'Todas las anteriores'] # Write here your possible choices as [number, string_with_choice] q1_choices = [[0, 'S/.5 (participación) + monto en test de comprensión + monto de UNA de las tres rondas (aleatorio)'], [1, 'S/.10 soles'], [2, 'S/.5 (participación) + monto en test de comprensión'], [3, 'S/.6 (participación) + suma de los montos de las rondas']] q2_choices = [[0, '6 rondas'], [1, '3 rondas y 2 "breaks" de 1 minuto cada uno'], [2, '2 rondas']] q3_choices = [[0, 'J2: decide sobre la dotación de ambos. J1: espera mientras J2 decide.'], [1, 'Ambos J1 y J2 deciden en cada ronda sobre la dotación del otro']] q4_choices = [[0, 'Anonimato durante y después del experimento'], [1, 'Los roles de J1 y J2 se eligen aleatoriamente cada ronda'], [2, 'Juegan con diferentes jugadores cada ronda'], [3, 'Todas las otras opciones']] # To randomize the order in which the answers are presented random.SystemRandom().shuffle(q1_choices) random.SystemRandom().shuffle(q2_choices) random.SystemRandom().shuffle(q3_choices) random.SystemRandom().shuffle(q4_choices) class Subsession(BaseSubsession): """ Description: Inherits oTree Class BaseSubsession. Defines subsession for the experiment. Input: None Output: None """ def creating_session(self): for p in self.get_players(): p.participant.vars['final_payoff'] = 0 p.participant.vars['quiz_payoff'] = 0 p.participant.vars['quiz_earnings'] = 0 class Group(BaseGroup): """ Description: Inherits BaseGroup oTree class. Assigns group characteristics. Input: None Output: None """ class Player(BasePlayer): """ Description: Inherits oTree class BasePlayer. Defines player characteristics. Input: None Output: None """ time_spent_on_instructions = models.FloatField(initial=0) def current_field(self): return 'question_{}_response'.format(self.quiz_page_counter + 1) quiz_incorrect_answer = models.StringField(initial=None) quiz_respuesta_incorrecta = models.StringField(initial=None) quiz_real = models.FloatField(initial=None) # IP field player_ip = models.StringField() current_practice_page = models.IntegerField(initial=0) '''Quiz''' # Counter of the questions answered correctly on the first try num_correct = models.IntegerField(initial=0) quiz_page_counter = models.IntegerField(initial=0) # Inc Attemp per question q_incorrect_attempts = models.IntegerField(initial=0) q_timeout = models.IntegerField(initial=0) q_validation = models.IntegerField(initial=0) q_attempts = models.IntegerField(initial=0) error_sequence = models.CharField(initial='') timeout_sequence = models.CharField(initial='') question_1_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect, choices=Constants.q1_choices) question_2_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect, choices=Constants.q2_choices) question_3_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect, choices=Constants.q3_choices) question_4_response = models.IntegerField(verbose_name='', widget=widgets.RadioSelect, choices=Constants.q4_choices) quiz_earnings = models.CurrencyField(initial=0) # Hidden Field for detecting bots quiz_dec_2 = models.LongStringField(blank=True)