from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import csv author = 'Your name here' doc = """ it will present the instructions about the procedure and ask three questions to make sure you understand it. """ class Constants(BaseConstants): name_in_url = 'quiz' players_per_group = None with open('UG_quiz/checkquestion.csv') as f: questions = list(csv.DictReader(f)) num_rounds = len(questions) players_per_group = None receiver = 1 sender = 1 # stimulated_players = 5 # G1players = receiver + stimulated_players # players_per_group = receiver + sender endowment = c(50) payoff_if_rejected = c(0) offer_increment = c(10) offer_choices = currency_range(0, endowment, offer_increment) pro_mean = 60 anti_mean = 20 TG_endowment = c(30) multiplication_factor = 2 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.session.vars['questions'] = Constants.questions ## ALTERNATIVE DESIGN: ## to randomize the order of the questions, you could instead do: # import random # randomized_questions = random.sample(Constants.questions, len(Constants.questions)) # self.session.vars['questions'] = randomized_questions ## and to randomize differently for each participant, you could use ## the random.sample technique, but assign into participant.vars ## instead of session.vars. for p in self.get_players(): question_data = p.current_question() p.question_id = question_data['id'] p.question = question_data['question'] p.solution = question_data['solution'] class Group(BaseGroup): pass class Player(BasePlayer): question_id = models.PositiveIntegerField() question = models.StringField() solution = models.StringField() submitted_answer = models.StringField(widget=widgets.RadioSelect()) is_correct = models.BooleanField() def current_question(self): return self.session.vars['questions'][self.round_number - 1] def check_correct(self): self.is_correct = self.submitted_answer == self.solution def G1role(self): if self.id_in_group % 2 == 0: return 'Observer' else: return 'Player 2'