from otree.api import *
import random
doc = """
Your app description
"""
class C(BaseConstants):
NAME_IN_URL = 'consent'
PLAYERS_PER_GROUP = None
NUM_ROUNDS = 1
CORRECT_MATRIX_COUNT = 13 # The correct count of '1's in the matrix
CORRECT_TRANSCRIPTION = 'A1B2C3D4E5F6G7'
class Subsession(BaseSubsession):
pass
def creating_session(subsession: Subsession):
import itertools #For a equal sized treatmentgroups we loop through the given list of treatments. Assign evenly in a repeating sequence
if subsession.round_number == 1: # maintain consistent treatment assignments across the apps
treatments = itertools.cycle(['control', 'treatment1', 'treatment2'])
for player in subsession.get_players():
player.participant.vars['total_progress'] = 0
treatment_group = next(treatments)
player.participant.vars['treatment'] = treatment_group
player.treatment_group = treatment_group
class Group(BaseGroup):
pass
class Player(BasePlayer):
#----Consent-----
Consent_1 = models.BooleanField(label='I have read and understood this consent form.',
choices=[[True, 'Yes'], [False, 'No']],
widget=widgets.RadioSelectHorizontal)
Consent_2 = models.BooleanField(label='I agree to participate in this study.',
choices=[[True, 'Yes'], [False, 'No']],
widget=widgets.RadioSelectHorizontal)
test_matrix_answer = models.IntegerField(label='Please enter the total number of \'1\'s:')
test_transcription_answer = models.StringField(label='Please enter the transcription:')
prolific_id = models.StringField(default=str(" "))
treatment_group = models.StringField()
# PAGES
class ResultsWaitPage(WaitPage):
pass
class ConsentForm(Page):
form_model = 'player'
form_fields = ['Consent_1', 'Consent_2']
class NoConsent(Page):
@staticmethod
def is_displayed(player: Player):
# This page is displayed only if the player did not give consent.
return not (player.Consent_1 and player.Consent_2)
class Instructions(Page):
form_model = 'player'
form_fields = ['test_matrix_answer', 'test_transcription_answer']
@staticmethod
def error_message(player: Player, values):
errors = {}
if values["test_matrix_answer"] != C.CORRECT_MATRIX_COUNT:
errors['test_matrix_answer'] = ('Your answer is not correct, please count again. '
'This hint will not be shown in the main task.')
if values["test_transcription_answer"] != C.CORRECT_TRANSCRIPTION:
errors['test_transcription_answer'] = ('Your transcription is incorrect, please try again. '
'This hint will not be shown in the main task.')
return errors
@staticmethod
def vars_for_template(player: Player):
treatment = player.participant.vars.get('treatment', None)
return {
'treatment': treatment,
}
class Start(Page):
pass
page_sequence = [ConsentForm, NoConsent, Instructions]