from otree.api import *
# Import risk params
from input.riskParams import expParts
from random import randint
doc = """
Your app description
"""
# MARK: Change study number here to make pages visible
thisStudyId = "binaryChoice"
# Function to make feedback field
def make_field(label):
return models.LongStringField(
blank=True,
label=label,
)
class Constants(BaseConstants):
name_in_url = 'expPart'
players_per_group = None
num_rounds = 1
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
# Select fixed amount
randomStudy = models.StringField() # Save name of randomly selected study
study = models.IntegerField()
compQuestion_risk_1 = models.StringField()
compQuestion_risk_2 = models.StringField()
choice_Instruction = models.IntegerField(
choices=[
[1, "Option 1 (The risk)."],
[2, "Option 2 (The amount)."],
],
label='Your instruction: Please give me',
blank=True,
)
choice_Study1 = models.IntegerField(
choices=[
[1, "Option 1 (The risk)."],
[2, "Option 2 (The amount)."],
],
label='Your instruction: Please give me',
)
viewOrder = models.IntegerField()
# Internal Feedback
feedback_generalTask = make_field("Feedback commentary:")
feedback_option1 = make_field("Feedback commentary:")
feedback_option2 = make_field("Feedback commentary:")
feedback_attentionScreen = make_field("Feedback commentary:")
feedback_task = make_field("Feedback commentary:")
# PAGES
class taskExplain(Page):
form_model = "player"
form_fields = [
"feedback_generalTask",
]
@staticmethod
def is_displayed(player):
# Only in the first round and correct study
return (player.round_number == 1) and (player.participant.studyName == thisStudyId)
@staticmethod
def js_vars(player: Player):
return dict(
testing = player.session.config["testing"],
)
@staticmethod
def vars_for_template(player: Player):
return dict(
testing = player.session.config["testing"]
)
class option1(Page):
form_model = "player"
form_fields = [
"feedback_option1"
]
@staticmethod
def is_displayed(player: Player):
# Only in the first round and correct study
return (player.round_number == 1) and (player.participant.studyName == thisStudyId)
@staticmethod
def js_vars(player: Player):
return dict(
#payoffs = ['🍐', '🍒'],
payoffs = ['£1.10', '£0.90'],
treatment = player.participant.treatment
)
@staticmethod
def vars_for_template(player: Player):
return dict(
testing = player.session.config["testing"],
)
class option2(Page):
form_model = "player"
form_fields = [
"feedback_option2"
]
@staticmethod
def is_displayed(player: Player):
# Only in the first round and correct study
return (player.round_number == 1) and (player.participant.studyName == thisStudyId)
@staticmethod
def vars_for_template(player: Player):
return dict(
fixedAmount = '£1.00',
testing = player.session.config["testing"],
)
class attentionScreen(Page):
form_model = "player"
form_fields = [
"feedback_attentionScreen"
]
@staticmethod
def is_displayed(player: Player):
# Only in the first round and correct study
return (player.round_number == 1) and (player.participant.studyName == thisStudyId)
@staticmethod
def vars_for_template(player: Player):
return dict(
testing = player.session.config["testing"],
)
@staticmethod
def before_next_page(player, timeout_happened):
studyList = list(expParts.keys())
## Differentiate by Treatment
if player.participant.treatment == 0:
idx = (player.session.choicePageReached_verify % 3)
player.session.choicePageReached_verify += 1
else:
idx = (player.session.choicePageReached_noVerify % 3)
player.session.choicePageReached_noVerify += 1
player.randomStudy = studyList[idx]
player.study = list(expParts.keys()).index(player.randomStudy)
# Randomly determine whether Option1 is shown left or right
player.viewOrder = randint(0,1)
player.participant.study = player.study
class task(Page):
form_model = "player"
form_fields = [
"feedback_task",
"choice_Study1"
]
@staticmethod
def is_displayed(player: Player):
# Only in the first round and correct study
print(player.participant.study)
return (player.round_number == 1) and (player.participant.studyName == thisStudyId)
@staticmethod
def js_vars(player: Player):
studyKey = list(expParts.keys())[player.participant.study]
studyProps = expParts[studyKey]
payoffs = []
probabilities = []
for elem in studyProps[2]:
payoffs.append(elem[0])
probabilities.append(elem[1])
return dict(
payoffs = payoffs,
probabilities = probabilities,
fixedAmount = "£" + '%.2f' %studyProps[-1],
)
@staticmethod
def vars_for_template(player: Player):
return dict(
randomOrder = player.viewOrder,
testing = player.session.config["testing"],
)
@staticmethod
def app_after_this_page(player, upcoming_apps):
# Always go to risk resolution
return 'riskResolution'
@staticmethod
def before_next_page(player, timeout_happened):
player.participant.singleChoice = player.choice_Study1
page_sequence = [
taskExplain,
option1,
option2,
attentionScreen,
task
]