from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import csv author = 'Lingguo Xu' doc = """ Prolific-Part4 """ class Constants(BaseConstants): name_in_url = 'Part4' players_per_group = None payment_per_correct_answer = 1 score_per_correct_answer = 1 with open('Part4/Part4_asnwerkey.csv') as questions_file: questions = list(csv.DictReader(questions_file)) # num_rounds = len(questions) num_rounds = 30 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.session.vars['questions'] = Constants.questions.copy() for p in self.get_players(): question_data = p.current_question() p.solution = question_data['solution'] p.round_number = self.round_number class Group(BaseGroup): pass class Player(BasePlayer): solution = models.StringField() task_answers = models.StringField(label="Please fill in a single lower-case letter:", initial="") is_correct = models.BooleanField(initial=0) def task_answers_error_message(player, value): print('You typed in', value) if value not in ["a", "b", "c", "d", "e", "f"]: return 'Please enter a single lower-case letter, from the a list of "a", "b", "c", "d", "e", and "f".' def current_question(self): return self.session.vars['questions'][self.round_number - 1] def check_correct(self): if self.task_answers: self.is_correct = (self.task_answers.lower() == self.solution.lower()) self.payoff = c(20) * self.is_correct attempts_R2 = models.IntegerField() success_R2 = models.IntegerField()