from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random debug = True author = "Marco Gutierrez" doc = """ Dynamic Quiz for Understanding of a Design """ class Constants(BaseConstants): """ Description: Inherits oTree Class BaseConstants. Defines constants for the experiment these will remain unchanged """ players_per_group = None players_per_group_pg = 4 num_rounds = 1 num_rounds_pg = 10 timer = 20 payment_per_answer = c(1) name_in_url = 'Initial_Quiz' # name in webbrowser # """Amount allocated to each player""" endowment = c(10) multiplier = 2 instructions_template = 'initial_quiz/instructions.html' '''Quiz Answers''' # TODO: Edit questions and answers (coded and displayed answers) # Answers according to the code quiz_fields = dict( question_1_response=False, question_2_response=20, question_3_response=4, ) quiz_questions = ['Is it compulsory to give a part of your money into the public account?', 'Which is the multiplication factor?', 'How many participants are needed to form a group?'] preguntas_quiz = ['¿Es obligatorio que des parte de tu dinero a una cuenta pública?', 'Si todos aportan 10 a la cuenta pública, ¿Cuál es la ganancia que obtendría cada jugador?', '¿Cuántos participantes hay por grupo?'] # Displayed answers quiz_answers = [False, 20, 4] respuestas_quiz = ['Falso', 20, 4] # Possible choices q1_choices = [[True, 'True'], [False, 'False']] q1_respuestas = [[True, 'Verdadero'], [False, 'Falso']] q2_choices = [[10, '10'], [20, '20'], [30, '30'], [4, '40']] q3_choices = [[1, '1'], [2, '2'], [3, '3'], [4, '4']] # 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) 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) # 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.BooleanField(verbose_name='', widget=widgets.RadioSelect, choices=Constants.q1_respuestas) question_1_respuesta = models.BooleanField(verbose_name='', widget=widgets.RadioSelect, choices=Constants.q1_respuestas) 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) quiz_earnings = models.CurrencyField(initial=0) # For detecting bots quiz_dec_2 = models.LongStringField(blank=True)