from otree.api import (
models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
Currency as c, currency_range
)
from django.utils.safestring import mark_safe
import csv
from datetime import datetime
from django.db import models as djmodels
import time
author = 'Abdul Qadir Ibrahim'
doc = """
IAT
"""
class Constants(BaseConstants):
name_in_url = 'iat'
players_per_group = None
task_timer = 10
with open('IAT/questions.csv') as questions_file:
questions = list(csv.DictReader(questions_file, delimiter=';'))
num_rounds = len(questions)
CHOICES = (
('Mädchenname', mark_safe('←
Mädchenname
')),
('Bube', mark_safe('→
Bube
')),
)
CHOICES_1 = (
('Mathematik', mark_safe('←
Mathematik
')),
('Deutsch', mark_safe('→
Deutsch
')),
)
CHOICES_2 = (
('Mädchen Deutsch', mark_safe('←
Mädchen,
Deutsch
')),
('Bube Mathe', mark_safe('→
Bube,
Mathe
')),
)
CHOICES_3 = (
('Mädchen Mathe', mark_safe('←
Mädchen,
Mathe
')),
('Bube Deutsch', mark_safe('→
Bube,
Deutsch
')),
)
class Subsession(BaseSubsession):
def creating_session(self):
if self.round_number == 1:
self.session.vars['questions'] = Constants.questions.copy()
# randomized_questions = random.sample(Constants.questions, len(Constants.questions))
# self.session.vars['questions'] = randomized_questions
for p in self.get_players():
question_data = p.current_question()
p.question = question_data['question']
p.solution = question_data['solution']
p.type = question_data['type']
class Group(BaseGroup):
pass
class Player(BasePlayer):
def score_round(self):
# update player payoffs
if self.solution == str(self.submitted_answer):
self.is_correct = True
self.payoff_score = 1
else:
self.is_correct = False
self.payoff_score = 0
start_time = models.DateTimeField(default=datetime.now)
is_correct = models.BooleanField(
doc="did the user get the task correct?")
ret_final_score = models.IntegerField(
doc="player's total score up to this round")
payoff_score = models.FloatField(
doc = '''score in this task'''
)
question = models.StringField()
type = models.StringField()
solution = models.StringField()
submitted_answer = models.StringField(
widget=widgets.RadioSelectHorizontal)
finish_time = models.DateTimeField()
time_difference = djmodels.DurationField(null=True)
def current_question(self):
return self.session.vars['questions'][self.round_number - 1]