Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app_label = "otree"
index_together = ['session', 'mturk_worker_id', 'mturk_assignment_id']
session = models.ForeignKey(
'otree.Session', on_delete=models.CASCADE
)
label = models.CharField(
max_length=50, null=True, doc=(
"Label assigned by the experimenter. Can be assigned by passing a "
"GET param called 'participant_label' to the participant's start "
"URL"
)
)
id_in_session = models.PositiveIntegerField(null=True)
payoff = models.CurrencyField(default=0)
time_started = models.DateTimeField(null=True)
user_type_in_url = constants_internal.user_type_participant
mturk_assignment_id = models.CharField(
max_length=50, null=True)
mturk_worker_id = models.CharField(max_length=50, null=True)
_index_in_subsessions = models.PositiveIntegerField(default=0, null=True)
_index_in_pages = models.PositiveIntegerField(default=0, db_index=True)
def _id_in_session(self):
"""the human-readable version."""
return 'P{}'.format(self.id_in_session)
"""Base class for all Groups.
"""
class Meta:
abstract = True
index_together = ['session', 'id_in_subsession']
ordering = ['pk']
id_in_subsession = models.PositiveIntegerField(db_index=True)
session = models.ForeignKey(
'otree.Session', related_name='%(app_label)s_%(class)s',
on_delete=models.CASCADE
)
round_number = models.PositiveIntegerField(db_index=True)
def __unicode__(self):
return str(self.pk)
def get_players(self):
return list(self.player_set.order_by('id_in_group'))
def get_player_by_id(self, id_in_group):
try:
return self.player_set.get(id_in_group=id_in_group)
except django.core.exceptions.ObjectDoesNotExist:
raise ValueError(
'No player with id_in_group {}'.format(id_in_group)) from None
def get_player_by_role(self, role):
for p in self.get_players():
"GET param called 'participant_label' to the participant's start "
"URL"
)
)
id_in_session = models.PositiveIntegerField(null=True)
payoff = models.CurrencyField(default=0)
time_started = models.DateTimeField(null=True)
user_type_in_url = constants_internal.user_type_participant
mturk_assignment_id = models.CharField(
max_length=50, null=True)
mturk_worker_id = models.CharField(max_length=50, null=True)
_index_in_subsessions = models.PositiveIntegerField(default=0, null=True)
_index_in_pages = models.PositiveIntegerField(default=0, db_index=True)
def _id_in_session(self):
"""the human-readable version."""
return 'P{}'.format(self.id_in_session)
_waiting_for_ids = models.CharField(null=True, max_length=300)
code = models.CharField(
default=random_chars_8,
max_length=16,
# set non-nullable, until we make our CharField non-nullable
null=False,
# unique implies DB index
unique=True,
"main ViewList for sessions"
),
)
comment = models.TextField(blank=True)
_anonymous_code = models.CharField(
default=random_chars_10, max_length=10, null=False, db_index=True
)
is_demo = models.BooleanField(default=False)
_admin_report_app_names = models.TextField(default='')
_admin_report_num_rounds = models.CharField(default='', max_length=255)
num_participants = models.PositiveIntegerField()
def __unicode__(self):
return self.code
@property
def participation_fee(self):
'''This method is deprecated from public API,
but still useful internally (like data export)'''
return self.config['participation_fee']
@property
def real_world_currency_per_point(self):
'''This method is deprecated from public API,
but still useful internally (like data export)'''
return self.config['real_world_currency_per_point']
from otree.db import models
from otree.models.fieldchecks import ensure_field
from django.db import models as djmodels
class BasePlayer(models.Model):
"""
Base class for all players.
"""
class Meta:
abstract = True
index_together = ['participant', 'round_number']
ordering = ['pk']
id_in_group = models.PositiveIntegerField(
null=True,
db_index=True,
doc=("Index starting from 1. In multiplayer games, "
"indicates whether this is player 1, player 2, etc.")
)
# don't modify this directly! Set player.payoff instead
_payoff = models.CurrencyField(
null=True,
doc="""The payoff the player made in this subsession""",
default=0
)
participant = models.ForeignKey(
'otree.Participant', related_name='%(app_label)s_%(class)s',
on_delete=models.CASCADE
"""Base class for all Subsessions.
"""
class Meta:
abstract = True
ordering = ['pk']
index_together = ['session', 'round_number']
session = models.ForeignKey(
'otree.Session',
related_name='%(app_label)s_%(class)s',
null=True,
on_delete=models.CASCADE,
)
round_number = models.PositiveIntegerField(
db_index=True,
doc='''If this subsession is repeated (i.e. has multiple rounds), this
field stores the position of this subsession, among subsessions
in the same app.
''',
)
def in_round(self, round_number):
return in_round(type(self), round_number, session=self.session)
def in_rounds(self, first, last):
return in_rounds(type(self), first, last, session=self.session)
def in_previous_rounds(self):
return self.in_rounds(1, self.round_number - 1)
)
)
id_in_session = models.PositiveIntegerField(null=True)
payoff = models.CurrencyField(default=0)
time_started = models.DateTimeField(null=True)
user_type_in_url = constants_internal.user_type_participant
mturk_assignment_id = models.CharField(
max_length=50, null=True)
mturk_worker_id = models.CharField(max_length=50, null=True)
_index_in_subsessions = models.PositiveIntegerField(default=0, null=True)
_index_in_pages = models.PositiveIntegerField(default=0, db_index=True)
def _id_in_session(self):
"""the human-readable version."""
return 'P{}'.format(self.id_in_session)
_waiting_for_ids = models.CharField(null=True, max_length=300)
code = models.CharField(
default=random_chars_8,
max_length=16,
# set non-nullable, until we make our CharField non-nullable
null=False,
# unique implies DB index
unique=True,
doc=(
"Randomly generated unique identifier for the participant. If you "
null=True,
doc="""The payoff the player made in this subsession""",
default=0
)
participant = models.ForeignKey(
'otree.Participant', related_name='%(app_label)s_%(class)s',
on_delete=models.CASCADE
)
session = models.ForeignKey(
'otree.Session', related_name='%(app_label)s_%(class)s',
on_delete=models.CASCADE
)
round_number = models.PositiveIntegerField(db_index=True)
_gbat_arrived = models.BooleanField(default=False)
_gbat_grouped = models.BooleanField(default=False)
@property
def payoff(self):
return self._payoff
@payoff.setter
def payoff(self, value):
if value is None:
value = 0
delta = value - self._payoff
self._payoff += delta
self.participant.payoff += delta
# should save it because it may not be obvious that modifying
"would like to merge this dataset with those from another "
"subsession in the same session, you should join on this field, "
"which will be the same across subsessions."
)
)
visited = models.BooleanField(
default=False, db_index=True,
doc="""Whether this user's start URL was opened"""
)
ip_address = models.GenericIPAddressField(null=True)
# stores when the page was first visited
_last_page_timestamp = models.PositiveIntegerField(null=True)
_last_request_timestamp = models.PositiveIntegerField(null=True)
is_on_wait_page = models.BooleanField(default=False)
# these are both for the admin
# In the changelist, simply call these "page" and "app"
_current_page_name = models.CharField(max_length=200, null=True,
verbose_name='page')
_current_app_name = models.CharField(max_length=200, null=True,
verbose_name='app')
# only to be displayed in the admin participants changelist
_round_number = models.PositiveIntegerField(
null=True
)