from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'eel_start' players_per_group = None num_rounds = 1 fix_control = c(20) high_coin = c(80) low_coin = c(20) instructions_control = 'luck_start/Instruction_control.html' instructions_endo = 'luck_start/Instruction_endo.html' instructions_exo = 'luck_start/Instruction_exo.html' class Subsession(BaseSubsession): def creating_session(self): for player in self.get_players(): player.participant.vars['treatment'] = self.session.config['treatment'] player.treatment = self.session.config['treatment'] class Group(BaseGroup): pass class Player(BasePlayer): treatment = models.StringField() performance = models.IntegerField(initial=0) solutions = models.StringField(initial="") all_answers = models.StringField(initial="") mistakes = models.IntegerField(initial=0) second_tries = models.IntegerField(initial=0) third_tries = models.IntegerField(initial=0) quiz1 = models.CurrencyField() quiz2 = models.CurrencyField() quiz3 = models.CurrencyField() quiz4 = models.CurrencyField() def live_zeros(self, data): num_button = data['button'] answer = int(data['entry']) right_answer = data['solution'] difference = answer - right_answer print('data I got', num_button, answer, right_answer, difference) self.all_answers += str(answer) + ";" self.solutions += str(right_answer) + ";" #if num_button == 1: #current_button = 2 if num_button == 2: self.second_tries += 1 #current_button = 3 if num_button == 3: self.third_tries += 1 #current_button = 1 if answer == right_answer: correct = 1 self.performance += 1 else: correct = 0 self.mistakes += 1 response = { 'button': num_button, 'correct': correct, 'performance': self.performance } return {self.id_in_group: response}