from otree.api import *
c = cu
doc = 'Provides instructions for the spending task, with comprehension questions for additional understanding.'
class C(BaseConstants):
# built-in constants
NAME_IN_URL = 'Auction_instructions'
PLAYERS_PER_GROUP = 2
NUM_ROUNDS = 1
# user-defined constants
UW_TETON_BG_TEMPLATE = 'Auction_instructions/uw_teton_bg.html'
class Subsession(BaseSubsession):
pass
def after_all_players_arrive(subsession: Subsession):
session = subsession.session
# pull the matrix you stored in the code‐entry app
matrix = subsession.session.vars.get('couple_matrix')
if not matrix:
# safety check in case someone forgot to run grouping first
raise RuntimeError("No couple_matrix in session.vars")
# re‐apply it in this app's subsession
subsession.set_group_matrix(matrix)
class Group(BaseGroup):
budget = models.IntegerField()
def set_budget(group: Group):
# Gather players
players = group.get_players()
# Define the group budget from RET1
group.budget = players[0].participant.budget_1
# Set default for comprehension questions
for p in players:
p.cq_1 = "NA"
p.cq_1_try2 = "NA"
p.cq_2 = "NA"
p.cq_2_try2 = "NA"
p.cq_3 = "NA"
p.cq_3_try2 = "NA"
p.cq_4 = "NA"
p.cq_4_try2 = "NA"
# Set default for winner_X checks
for p in players:
p.participant.winner_1 = 0
p.participant.winner_2 = 0
class Player(BasePlayer):
cq_1 = models.StringField(choices=[['1', 'You pay the amount the computer bid'], ['2', 'You pay the amount you bid'], ['3', "You pay the average of your bid and the computer's bid"]], label='In this auction, if you win, how much do you pay?', widget=widgets.RadioSelect)
cq_1_try2 = models.StringField(choices=[['1', 'You pay the amount the computer bid'], ['2', 'You pay the amount you bid'], ['3', "You pay the average of your bid and the computer's bid"]], label='In this auction, if you win, how much do you pay?', widget=widgets.RadioSelect)
cq_2 = models.StringField(choices=[['1', 'You should bid more than $50'], ['2', 'You should bid exactly $50'], ['3', 'You should bid less than $50']], label='If you think an item is worth $50 to you, what amount should you bid in this auction?', widget=widgets.RadioSelect)
cq_2_try2 = models.StringField(choices=[['1', 'You should bid more than $50'], ['2', 'You should bid exactly $50'], ['3', 'You should bid less than $50']], label='If you think an item is worth $50 to you, what amount should you bid in this auction?', widget=widgets.RadioSelect)
cq_3 = models.StringField(choices=[['1', 'You lose the auction and pay nothing'], ['2', 'You win the auction and pay $75'], ['3', 'You win the auction and pay $60']], label='If you bid $75 and the computer randomly selects $60, what happens?', widget=widgets.RadioSelect)
cq_3_try2 = models.StringField(choices=[['1', 'You lose the auction and pay nothing'], ['2', 'You win the auction and pay $75'], ['3', 'You win the auction and pay $60']], label='If you bid $75 and the computer randomly selects $60, what happens?', widget=widgets.RadioSelect)
cq_4 = models.StringField(choices=[['1', 'You win the auction, get red chair, and you get $800 at the end of the study'], ['2', 'You win the auction, get red chair, and you get $400 and your partner gets $400 at the end of the study'], ['3', 'You lost the auction and you get $800 at the end of the study']], label='Now that you know how this auction works, let’s put this in the context of the study. You will be asked to bid on an item using money from the joint account with your partner. Imagine that you and your partner had $1,000 in the joint account. Remember, at the end of the study, anything that is not spent will be equally split between the two of you. Imagine that you bid $200 on the red chair, and the computer chooses $200. What is the outcome of the auction and your final payment for the study?', widget=widgets.RadioSelect)
cq_4_try2 = models.StringField(choices=[['1', 'You win the auction, get red chair, and you get $800 at the end of the study'], ['2', 'You win the auction, get red chair, and you get $400 and your partner gets $400 at the end of the study'], ['3', 'You lose the auction and you get $800 at the end of the study']], label='You will be asked to bid on an item using money from the joint account with your partner. Imagine that you and your partner had $1,000 in the joint account. Remember, at the end of the study, anything that is not spent will be equally split between the two of you. Imagine that you bid $200 on the red chair, and the computer chooses $200. What is the outcome of the auction and your final payment for the study?', widget=widgets.RadioSelect)
def custom_export(players):
# Header
yield [
'session_code',
'participant_id_in_session',
'participant_code',
'id_in_group',
'group_number',
'cq_1', 'cq_1_try2',
'cq_2', 'cq_2_try2',
'cq_3', 'cq_3_try2',
'cq_4', 'cq_4_try2',
]
# Rows
for p in players:
pp = p.participant
pg = p.group
ps = p.session
yield [
ps.code,
pp.id_in_session,
pp.code,
p.id_in_group,
pg.id_in_subsession,
p.cq_1, p.cq_1_try2,
p.cq_2, p.cq_2_try2,
p.cq_3, p.cq_3_try2,
p.cq_4, p.cq_4_try2
]
class GroupingWaitPage(WaitPage):
wait_for_all_groups = True
after_all_players_arrive = after_all_players_arrive
class AuctionInstructionsStartPage(WaitPage):
wait_for_all_groups = True
class SetBudgetWaitPage(WaitPage):
after_all_players_arrive = set_budget
class SpenderInstructions1(Page):
form_model = 'player'
form_fields = ['cq_1']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender, show them this page
return participant.spender == 1
class CQ_1(Page):
form_model = 'player'
form_fields = ['cq_1_try2']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender and got comprehension question wrong, show them this page
return participant.spender == 1 and player.cq_1 != "1"
class SpenderInstructions2(Page):
form_model = 'player'
form_fields = ['cq_2']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender, show them this page
return participant.spender == 1
class CQ_2(Page):
form_model = 'player'
form_fields = ['cq_2_try2']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender and got comprehension question wrong, show them this page
return participant.spender == 1 and player.cq_2 != "2"
class SpenderInstructions3(Page):
form_model = 'player'
form_fields = ['cq_3']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender, show them this page
return participant.spender == 1
class CQ_3(Page):
form_model = 'player'
form_fields = ['cq_3_try2']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender and got comprehension question wrong, show them this page
return participant.spender == 1 and player.cq_3 != "3"
class SpenderInstructions4(Page):
form_model = 'player'
form_fields = ['cq_4']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender, show them this page
return participant.spender == 1
class CQ_4(Page):
form_model = 'player'
form_fields = ['cq_4_try2']
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender and got comprehension question wrong, show them this page
return participant.spender == 1 and player.cq_4 != "2"
class SpenderInstructionsEnd(Page):
form_model = 'player'
@staticmethod
def is_displayed(player: Player):
participant = player.participant
# If participant is the spender, show them this page
return participant.spender == 1
class AuctionInstructionsEndPage(WaitPage):
wait_for_all_groups = True
title_text = 'Your partner is being given instructions for their next task. Please wait for your partner.'
page_sequence = [GroupingWaitPage, AuctionInstructionsStartPage, SetBudgetWaitPage, SpenderInstructions1, CQ_1, SpenderInstructions2, CQ_2, SpenderInstructions3, CQ_3, SpenderInstructions4, CQ_4, SpenderInstructionsEnd, AuctionInstructionsEndPage]