from otree.api import *
import random
doc = """
Risk, Loss, Ambiguity, and CRT tests
"""
class Constants(BaseConstants):
name_in_url = 'social_preference_test'
players_per_group = None
num_rounds = 1
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
#risk aversion
risk_1 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 10% chance and $0.1 with 90% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_2 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 20% chance and $0.1 with 80% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_3 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 30% chance and $0.1 with 70% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_4 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 40% chance and $0.1 with 60% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_5 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 50% chance and $0.1 with 50% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_6 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 60% chance and $0.1 with 40% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_7 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 70% chance and $0.1 with 30% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_8 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 80% chance and $0.1 with 20% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_9 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 90% chance and $0.1 with 10% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_10 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 100% chance and $0.1 with 0% chance'],
[2, 'B: $1.5 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
risk_payoff = models.FloatField(
initial=0,
)
risk_random = models.IntegerField(
initial=0,
)
## loss aversion
loss_1 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 50% chance and -$0.5 with 50% chance'],
[2, 'B: $0.0 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
loss_2 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 50% chance and -$1.0 with 50% chance'],
[2, 'B: $0.0 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
loss_3 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 50% chance and -$1.5 with 50% chance'],
[2, 'B: $0.0 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
loss_4 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 50% chance and -$2.0 with 50% chance'],
[2, 'B: $0.0 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
loss_5 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 50% chance and -$2.5 with 50% chance'],
[2, 'B: $0.0 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
loss_6 = models.IntegerField(
choices=[
[1, 'A: $3.0 with 50% chance and -$3.0 with 50% chance'],
[2, 'B: $0.0 for sure'],
],
widget=widgets.RadioSelectHorizontal
)
loss_payoff = models.FloatField(
initial=0,
)
loss_random = models.IntegerField(
initial=0,
)
## ambiguity aversion
ambiguity_1 = models.IntegerField(
label='Question 1: Choose Urn A containing 20 red and blue balls with unknown fraction OR '
'choose Urn B containing 16 red balls and 4 blue balls.',
choices=[
[1, 'Urn A'],
[2, 'Urn B']
],
widget=widgets.RadioSelect
)
ambiguity_2 = models.IntegerField(
label='Question 2: Choose Urn A containing 20 red and blue balls with unknown fraction OR '
'choose Urn B containing 14 red balls and 6 blue balls.',
choices=[
[1, 'Urn A'],
[2, 'Urn B']
],
widget=widgets.RadioSelect
)
ambiguity_3 = models.IntegerField(
label='Question 3: Choose Urn A containing 20 red and blue balls with unknown fraction OR '
'choose Urn B containing 12 red balls and 8 blue balls.',
choices=[
[1, 'Urn A'],
[2, 'Urn B']
],
widget=widgets.RadioSelect
)
ambiguity_4 = models.IntegerField(
label='Question 4: Choose Urn A containing 20 red and blue balls with unknown fraction OR '
'choose Urn B containing 10 red balls and 10 blue balls.',
choices=[
[1, 'Urn A'],
[2, 'Urn B']
],
widget=widgets.RadioSelect
)
ambiguity_5 = models.IntegerField(
label='Question 5: Choose Urn A containing 20 red and blue balls with unknown fraction OR '
'choose Urn B containing 8 red balls and 12 blue balls.',
choices=[
[1, 'Urn A'],
[2, 'Urn B']
],
widget=widgets.RadioSelect
)
ambiguity_6 = models.IntegerField(
label='Question 6: Choose Urn A containing 20 red and blue balls with unknown fraction OR '
'choose Urn B containing 6 red balls and 14 blue balls.',
choices=[
[1, 'Urn A'],
[2, 'Urn B']
],
widget=widgets.RadioSelect
)
ambiguity_7 = models.IntegerField(
label='Question 7: Choose Urn A containing 20 red and blue balls with unknown fraction OR '
'choose Urn B containing 4 red balls and 16 blue balls.',
choices=[
[1, 'Urn A'],
[2, 'Urn B']
],
widget=widgets.RadioSelect
)
ambiguity_payoff = models.FloatField(
initial=0,
)
ambiguity_random = models.IntegerField(
initial=0,
)
## CRT test
CRT_1 = models.IntegerField(label='Your answer', min=0, max=9999 )
CRT_2 = models.IntegerField(label='Your answer', min=0, max=9999 )
CRT_3 = models.IntegerField(label='Your answer', min=0, max=9999 )
CRT_corrected = models.IntegerField( initial=0,)
CRT_payoff = models.FloatField(
initial=0.0,
)
## FUNCTIONS
#def set_risk_payoff(player: Player):
# participant = player.participant
# participant.vars['risk_random'] = random.randint(1, 12)
# if participant.risk_random == 1 and player.risk_1 ==1:
# player.risk_payoff = 0
# elif participant.risk_random ==2 and player.risk_2==1:
# player.risk_payoff = 0
# elif participant.risk_random ==3 and player.risk_3==1:
# player.risk_payoff = 0
# elif participant.risk_random ==4 and player.risk_4==1:
# player.risk_payoff = 0
# elif participant.risk_random ==5 and player.risk_5==1:
# player.risk_payoff = 3
# elif participant.risk_random ==6 and player.risk_6==1:
# player.risk_payoff = 3
# elif participant.risk_random ==7 and player.risk_7==1:
# player.risk_payoff = 3
# elif participant.risk_random ==8 and player.risk_8==1:
# player.risk_payoff = 3
# elif participant.risk_random ==9 and player.risk_9==1:
# player.risk_payoff = 3
# elif participant.risk_random ==10 and player.risk_10==1:
# player.risk_payoff = 3
# else:
# player.risk_payoff =1.5
# PAGES
class Risk_aversion(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
form_model = 'player'
form_fields = ['risk_1',
'risk_2',
'risk_3',
'risk_4',
'risk_5',
'risk_6',
'risk_7',
'risk_8',
'risk_9',
'risk_10',
]
def before_next_page(player: Player, timeout_happened):
import random
participant = player.participant
participant.vars['risk_random'] = random.randint(1, 10)
if participant.risk_random == 1 and player.risk_1 == 1:
player.risk_payoff = 0.1
elif participant.risk_random == 2 and player.risk_2 == 1:
player.risk_payoff = 0.1
elif participant.risk_random == 3 and player.risk_3 == 1:
player.risk_payoff = 0.1
elif participant.risk_random == 4 and player.risk_4 == 1:
player.risk_payoff = 0.1
elif participant.risk_random == 5 and player.risk_5 == 1:
player.risk_payoff = 3
elif participant.risk_random == 6 and player.risk_6 == 1:
player.risk_payoff = 3
elif participant.risk_random == 7 and player.risk_7 == 1:
player.risk_payoff = 3
elif participant.risk_random == 8 and player.risk_8 == 1:
player.risk_payoff = 3
elif participant.risk_random == 9 and player.risk_9 == 1:
player.risk_payoff = 3
elif participant.risk_random == 10 and player.risk_10 == 1:
player.risk_payoff = 3
else:
player.risk_payoff = 1.5
participant.vars['risk_payoff'] = player.risk_payoff
class Loss_aversion(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
form_model = 'player'
form_fields = ['loss_1',
'loss_2',
'loss_3',
'loss_4',
'loss_5',
'loss_6',
]
def before_next_page(player: Player, timeout_happened):
import random
participant = player.participant
participant.vars['loss_random'] = random.randint(1, 6)
if participant.loss_random == 1 and player.loss_1 == 1:
player.loss_payoff = 3
elif participant.loss_random == 2 and player.loss_2 == 1:
player.loss_payoff = -1
elif participant.loss_random == 3 and player.loss_3 == 1:
player.loss_payoff = 3
elif participant.loss_random == 4 and player.loss_4 == 1:
player.loss_payoff = -2
elif participant.loss_random == 5 and player.loss_5 == 1:
player.loss_payoff = 3
elif participant.loss_random == 6 and player.loss_6 == 1:
player.loss_payoff = 3
else:
player.loss_payoff = 0
participant.vars['loss_payoff'] = player.loss_payoff
class Ambiguity_aversion(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
form_model = 'player'
form_fields = ['ambiguity_1',
'ambiguity_2',
'ambiguity_3',
'ambiguity_4',
'ambiguity_5',
'ambiguity_6',
'ambiguity_7',
]
def before_next_page(player: Player, timeout_happened):
import random
participant = player.participant
participant.vars['ambiguity_random'] = random.randint(1, 7)
if participant.ambiguity_random == 1 and player.ambiguity_1 == 1:
player.ambiguity_payoff = 3
elif participant.ambiguity_random == 1 and player.ambiguity_1 == 2:
player.ambiguity_payoff = 3
elif participant.ambiguity_random == 2 and player.ambiguity_2 == 1:
player.ambiguity_payoff = 1
elif participant.ambiguity_random == 2 and player.ambiguity_2 == 2:
player.ambiguity_payoff = 3
elif participant.ambiguity_random == 3 and player.ambiguity_3 == 1:
player.ambiguity_payoff = 1
elif participant.ambiguity_random == 3 and player.ambiguity_3 == 2:
player.ambiguity_payoff = 3
elif participant.ambiguity_random == 4 and player.ambiguity_4 == 1:
player.ambiguity_payoff = 3
elif participant.ambiguity_random == 4 and player.ambiguity_4 == 2:
player.ambiguity_payoff = 3
elif participant.ambiguity_random == 5 and player.ambiguity_5 == 1:
player.ambiguity_payoff = 1
elif participant.ambiguity_random == 5 and player.ambiguity_5 == 2:
player.ambiguity_payoff = 1
elif participant.ambiguity_random == 6 and player.ambiguity_6 == 1:
player.ambiguity_payoff = 3
elif participant.ambiguity_random == 6 and player.ambiguity_6 == 2:
player.ambiguity_payoff = 1
elif participant.ambiguity_random == 7 and player.ambiguity_7 == 1:
player.ambiguity_payoff = 1
elif participant.ambiguity_random == 7 and player.ambiguity_7 == 2:
player.ambiguity_payoff = 1
participant.vars['ambiguity_payoff'] = player.ambiguity_payoff
class CRT_test(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
form_model = 'player'
form_fields = ['CRT_1',
'CRT_2',
'CRT_3',
]
def before_next_page(player: Player, timeout_happened):
participant = player.participant
if player.CRT_1 == 5:
player.CRT_corrected = player.CRT_corrected+1
if player.CRT_2 == 5:
player.CRT_corrected = player.CRT_corrected+1
if player.CRT_3 == 47:
player.CRT_corrected = player.CRT_corrected+1
player.CRT_payoff = 0.5*player.CRT_corrected
participant.vars['CRT_payoff'] = player.CRT_payoff
participant.vars['CRT_corrected'] = player.CRT_corrected
class Part3_summary(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
class Part3_Cover (Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
page_sequence = [Part3_Cover,
Risk_aversion,
Loss_aversion,
Ambiguity_aversion,
CRT_test,
Part3_summary,
]