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 = """
German Task Overest
"""
class Constants(BaseConstants):
name_in_url = 'german_task_overest'
players_per_group = None
with open('GermanTask/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.question = question_data['question'] p.solution = question_data['solution'] class Group(BaseGroup): pass class Player(BasePlayer): def score_round(self): # update player payoffs if self.round_number > 4: if str(self.solution) == str(self.submitted_answer): self.is_correct = True self.payoff_score = 1 self.guess_german = 0 else: self.is_correct = False self.payoff_score = 0 self.guess_german = 0 elif self.round_number == 4: self.guess_german = self.guess_german self.session.vars['guess_german'] = self.guess_german else: self.is_correct = False self.payoff_score = 0 self.guess_german = 0 question = models.LongStringField( doc="this round's first question") solution = models.StringField( doc="this round's correct solution") submitted_answer = models.StringField( widget=widgets.RadioSelectHorizontal) guess_german = 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''' ) german_ambition = models.StringField( choices= Constants.CHOICES, widget=widgets.RadioSelectHorizontal) def current_question(self): return self.session.vars['questions'][self.round_number - 1]