from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import csv author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'reciprocity_survey' players_per_group = None with open('reciprocity_survey/reciprocity.csv') as f: questions = list(csv.DictReader(f, quoting=csv.QUOTE_NONNUMERIC)) for sub in questions: for key in sub: try: sub[key] = int(sub[key]) except ValueError: sub[key] = str(sub[key]) num_rounds = len(questions) class Subsession(BaseSubsession): def before_session_starts(self): if self.round_number == 1: self.session.vars['questions'] = Constants.questions for p in self.get_players(): question_data = p.current_question() p.question_id = question_data['id'] p.question = question_data['question'] class Group(BaseGroup): pass class Player(BasePlayer): question_id = models.PositiveIntegerField() question = models.CharField() submitted_answer = models.PositiveIntegerField(widget=widgets.RadioSelectHorizontal()) def current_question(self): return self.session.vars['questions'][self.round_number - 1]