from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from django.utils.safestring import mark_safe import csv author = 'Abdul Qadir Ibrahim' doc = """ Math Task Overest """ class Constants(BaseConstants): name_in_url = 'math_task' players_per_group = None with open('MathTask/questions.csv') as questions_file: questions = list(csv.DictReader(questions_file, delimiter=';')) num_rounds = len(questions) - 2 CHOICES = ( ('Gar nicht bemüht', mark_safe('🙁

Gar nicht bemüht

')), ('Eher weniger bemüht', mark_safe('😕

Eher weniger bemüht

')), ('Weder noch', mark_safe('😐

Weder noch

')), ('Ein bisschen bemüht', mark_safe('😊

Ein bisschen bemüht

')), ('Sehr bemüht', mark_safe('😀

Sehr bemüht

')), ) 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.int1 = question_data['int1'] p.int2 = question_data['int2'] p.int3 = question_data['int3'] p.int4 = question_data['int4'] p.solution = int(p.int1) + int(p.int2) + int(p.int3) + int(p.int4) class Group(BaseGroup): pass class Player(BasePlayer): def score_round(self): # update player payoffs if self.round_number > 4: if int(self.solution) == int(self.submitted_answer): self.is_correct = True self.payoff_score = 1 self.guess_math = 0 else: self.is_correct = False self.payoff_score = 0 self.guess_math = 0 elif self.round_number == 4: self.guess_math = self.guess_math self.session.vars['guess_math'] = self.guess_math else: self.is_correct = False self.payoff_score = 0 self.guess_math = 0 int1 = models.PositiveIntegerField( doc="this round's first int") int2 = models.PositiveIntegerField( doc="this round's second int") int3 = models.PositiveIntegerField( doc="this round's third int") int4 = models.PositiveIntegerField( doc="this round's fourth int") solution = models.PositiveIntegerField( doc="this round's correct summation") submitted_answer = models.StringField( widget=widgets.RadioSelectHorizontal) guess_math = models.IntegerField( widget=widgets.Slider(attrs={'step': '1.0', 'min': '1', 'max': '30'})) is_correct = models.BooleanField( doc="did the user get the task correct?") payoff_score = models.FloatField( doc='''score in this task''' ) total_score = models.FloatField( doc='''score in this task''' ) math_ambition = models.StringField( choices=Constants.CHOICES, widget=widgets.RadioSelectHorizontal) def current_question(self): return self.session.vars['questions'][self.round_number - 1]