File size: 1,951 Bytes
3209e11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
from otree.api import (
models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer,
Currency as c, currency_range
)
from random import randint
class Constants(BaseConstants):
name_in_url = 'Ability_Load_Pilot'
players_per_group = None
num_rounds = 10
payoff_load = c(0.1)
payoff_incorrect = c(0.0)
load_string_list = ['56291554', '7749733', '22987883',
'8311343', '81174423', '8193613',
'9361795', '56424871', '5379763',
'45519286']
class Subsession(BaseSubsession):
def creating_session(self):
for p in self.get_players():
p.payoff = c(0)
# Cognitive Load Task
p.cognitive_load_rand_int = Constants.load_string_list[self.round_number - 1]
# In the first round create participant vars
if self.round_number == 1:
p.participant.vars['count_load_correct_ability'] = 0
p.participant.vars['number_rounds_ability_load'] = Constants.num_rounds
p.participant.vars['payoff_ability_load'] = Constants.payoff_load
class Group(BaseGroup):
pass
class Player(BasePlayer):
app = models.CharField(default='Ability_Load')
cognitive_load_rand_int = models.CharField()
cognitive_load_entry = models.CharField(blank=True)
# Define empty currency fields for payoffs.
payoff_load = models.FloatField(default=Constants.payoff_load)
payoff_incorrect = models.FloatField(default=Constants.payoff_incorrect)
load_correct = models.IntegerField(default=0)
def set_payoff(self):
if self.cognitive_load_entry == self.cognitive_load_rand_int:
self.load_correct = 1
self.payoff = Constants.payoff_load
else:
self.load_correct = 0
self.payoff = 0
self.participant.vars['count_load_correct_ability'] += self.load_correct
|