from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import csv author = 'Your name here' doc = """ A quiz app that reads its questions from a spreadsheet (see quiz.csv in this directory). There is 1 Survey per page; the number of pages in the game is determined by the number of questions in the CSV. See the comment below about how to randomize the order of pages. """ class Constants(BaseConstants): name_in_url = 'TGquiz' players_per_group = None with open('TGquiz/squiz.csv') as e: questions2 = list(csv.DictReader(e)) num_rounds = len(questions2) endowment = c(100) 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 = 3 class Subsession(BaseSubsession): def before_session_starts(self): if self.round_number == 1: self.session.vars['questions2'] = Constants.questions2 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['key'] class Group(BaseGroup): pass class Player(BasePlayer): question_id = models.PositiveIntegerField() question = models.CharField() solution = models.CharField() submitted_answer = models.CharField(widget=widgets.RadioSelect()) is_correct = models.BooleanField() def current_question(self): return self.session.vars['questions2'][self.round_number - 1] def check_correct(self): self.is_correct = self.submitted_answer == self.solution def role(self): if self.id_in_group % 2 == 0: return 'Sender' else: return 'Receiver'