import random
import numpy as np
import itertools
from otree.api import *
doc = """
Informational Cost of Interventions - baseline & deterministic app with 10 rounds.
In base its 5 Part 1s, 1 Part 2, 5 Part 1s and 1 Part 2.
In Det its 5 Treatments, 5 Part 1s, and 1 Part 2.
"""
class C(BaseConstants):
NAME_IN_URL = 'informational_cost'
PLAYERS_PER_GROUP = None
PARAMETERIZATIONS = list(range(1, 11))
NUM_ROUNDS = len(PARAMETERIZATIONS)
# OUTSIDE_OPTION = cu(1.5)
OUTSIDE_OPTION = cu(2.2)
PROBABILITY_OF_SWITCH = 0.25
REVIEW_INSTRUCTIONS = 'informational_cost/reviewInstructions.html'
COMPUTER_INTRO_TYPES = 'informational_cost/computerTypes.html'
COMPUTER_INTRO_TYPES_INTRO = 'intro/computerTypes.html'
PART1_TEMPLATE = 'intro/part1.html' # this comes from the other app
PART2_TEMPLATE = 'informational_cost/part2.html'
BONUS_PART1_TEMPLATE = 'informational_cost/bonus_part1.html'
BONUS_PART2_TEMPLATE = 'informational_cost/bonus_part2.html'
INSTRUCTIONS1_TEMPLATE = 'informational_cost/instructions1_template.html'
PART1_INTRO_TEMPLATE = 'intro/part1.html'
PART2_INTRO_TEMPLATE = 'intro/part2.html'
BONUS_INTRO_TEMPLATE = 'intro/bonus.html'
# Each of the 5 stages corresponds to our parameterization as in the overleaf document
LABEL_POOL = ['Green', 'Blue', 'Orange', 'Purple', 'Gray', 'Black', 'Gold', 'Silver', 'Navy', 'Indigo']
LABEL_SEP = ['Yellow', 'Red', 'Violet', 'Pink', 'Brown', 'Beige', 'White', 'Maroon', 'Burgundy', 'Olive']
class Subsession(BaseSubsession):
pass
def creating_session(subsession: Subsession):
if subsession.round_number == 1:
treatments = itertools.cycle(['deterministic', 'salient', 'strategy', 'plan'])
# treatments = itertools.cycle(['deterministic'])
for p in subsession.get_players():
p.participant.det = False
p.participant.base = False
p.participant.salient = False
p.participant.strategy = False
# a = list(range(1, int(C.NUM_ROUNDS + 1)))
a = list(range(3, int(C.NUM_ROUNDS + 1)))
random.shuffle(a)
param_rounds = [1]+a+[2]
# param_rounds maps rounds to parameterizations. (so it says, for each round -which is the index in the
# tuple- which parametrization applies -which is the value the tuple takes in that position)
print('param_rounds is', param_rounds)
p.participant.param_rounds = param_rounds
p.participant.compType = np.random.randint(2, size=C.NUM_ROUNDS) # array of C.NUM_ROUNDS 0s and 1s, one per round; compType=1 is good type
# label 1 is the environment that pools
p.participant.environment_choice = []
p.participant.part1_payoffs = []
p.participant.part2_payoffs = []
# Pick one decision to count from decisions 1-5:
p.participant.treatment = next(treatments)
# p.participant.treatment = random.choices(['base', 'deterministic', 'salient', 'strategy', 'plan'],
# weights=subsession.session.config['weights'])[0]
if p.participant.treatment == 'deterministic':
p.participant.det = True
# p.participant.chosen_decisions = (random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) # in Deterministic, we pick only one decision from stages 1 & 2
elif p.participant.treatment == 'salient':
p.participant.salient = True
# p.participant.chosen_decisions = (random.choice([1, 2, 3, 4, 5]))
elif p.participant.treatment == 'strategy':
p.participant.strategy = True
# p.participant.chosen_decisions = (random.choice([1, 2, 3, 4, 5]))
elif p.participant.treatment == 'plan':
p.participant.plan = True
else:
p.participant.base = True
# p.participant.chosen_decisions = (random.choice([1, 2, 3, 4, 5]))
print('DET:', p.participant.det, 'Salient:', p.participant.salient, 'Base:', p.participant.base)
# each round is: [part1_pool, part1_good_sep, part1_bad_sep, part2_good, part2_bad]
# r1 = [0.3, 0.3, 0.15, 2.5, 1.25]
# r2 = [0.3, 0.3, 0, 2.5, 0]
# r3 = [0.3, 0.15, 0, 2.75, 0]
# r4 = [0.15, 0.15, 0, 2.75, 0]
# r5 = [0.3, 0.15, 0, 1.75, 0]
r1 = [0.05, 0.05, 0.0, 4.3, 0.05]
r2 = [0.05, 0.05, 0.0, 4.45, 0.1]
r3 = [0.2, 0.2, 0.15, 4.3, 0.1]
r4 = [0.05, 0.05, 0.0, 4.45, 0.1]
r5 = [0.05, 0.05, 0.0, 4.35, 0.1]
# r6 = [0.5, 0.35, 0.25, 0.45, 0.15]
r6 = [0.05, 0.05, 0.0, 4.5, 0.1]
r7 = [0.4, 0.25, 0.05, 0.2, 0.05]
r8 = [0.5, 0.3, 0.05, 0.6, 0.5]
r9 = [0.1, 0.05, 0.0, 0.2, 0.05]
r10 = [0.45, 0.4, 0.1, 0.55, 0.15]
subsession.session.parameterization = (r1, r2, r3, r4, r5, r6, r7, r8, r9, r10)
class Group(BaseGroup):
pass
class Player(BasePlayer):
timeSpent = models.FloatField() # one unit is 100 milliseconds (a decimal of a second): 96 means 9.6 secs
timeSpentBonus = models.FloatField() # one unit is 100 milliseconds (a decimal of a second): 96 means 9.6 secs
cq1_intro = models.IntegerField(blank=True,
choices=[
[1, 'It does not do anything.'],
[2, 'It solves different tasks.'],
[3, 'It decides what task it solves.']
],
widget=widgets.RadioSelect,
label='What does the computer do?'
)
cq2_intro = models.IntegerField(blank=True,
choices=[
[1, 'Only one, which can be of Good or the Bad quality.'],
[2, 'Two, one of Good quality and one of Bad quality.'],
[3, 'There are no computers.']
],
widget=widgets.RadioSelect,
label='How many computers are there in this decision?'
)
cq3_intro = models.IntegerField(blank=True,
choices=[
[1, 'Yes, there is only one computer which solves tasks in both part 1 '
'and part 2, but the computer can be of a different quality in part 1 and part 2.'],
[2, 'No, there are two computers, one for each part.'],
[3, 'Yes, there is only one computer in this decision which solves tasks in both '
'part 1 and part 2, and the computer is of the same quality in both parts.']
],
widget=widgets.RadioSelect,
label='Is the computer that solves the task in part 1 the same as the one that '
'solves the task in part 2 in this decision?'
)
cq1_intro_det = models.IntegerField(blank=True,
choices=[
[1, 'They do not do anything.'],
[2, 'They solve tasks.'],
[3, 'They decide what task they solve.']
],
widget=widgets.RadioSelect,
label='What do the computers do?'
)
cq2_intro_det = models.IntegerField(blank=True,
choices=[
[1, 'Only one, which can be of Good or the Bad quality.'],
[2, 'Two, one of Good quality and one of Bad quality.'],
[3, 'There are no computers.']
],
widget=widgets.RadioSelect,
label='How many computers are there in this decision?'
)
cq3_intro_det = models.IntegerField(blank=True,
choices=[
[1, 'Yes, there are two computers which solve tasks in both part 1 '
'and part 2, but the computers can be of different quality in part 1 and part 2.'],
[2, 'No, there are four computers, two for each part.'],
[3,
'Yes, there are two computers in this decision which solve tasks in both '
'part 1 and part 2, and the computers are of the same quality in both parts.']
],
widget=widgets.RadioSelect,
label='Are the computers that solve the task in part 1 the same as the ones '
'that solve the task in part 2 in this decision?'
)
# cq4_intro = models.IntegerField(blank=True,
# choices=[
# [1, 'Only one.'],
# [2, 'Five decisions.'],
# [3, 'I do not have to make any decisions.']
# ],
# widget=widgets.RadioSelect,
# label='How many decisions will you face in this stage?'
# )
cq1 = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
label='In part 2 of this decision, which type of task does the computer solve?'
)
cq2 = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
label='How is your bonus determined in this decision?'
)
cq_part2 = models.IntegerField(blank=True,
widget=widgets.RadioSelect)
for j in range(1, 6):
locals()['cq' + str(j) + '_intro_mistakes'] = models.IntegerField(blank=True, initial=0)
del j
for j in range(1, 6):
locals()['cq' + str(j) + '_intro_det_mistakes'] = models.IntegerField(blank=True, initial=0)
del j
intro_cq_mistakes = models.IntegerField(blank=True)
for j in range(1, 4):
locals()['cq' + str(j) + '_mistakes'] = models.IntegerField(blank=True, initial=0)
del j
cq_part2_mistakes = models.IntegerField(blank=True, initial=0)
info_cost_cq_mistakes = models.IntegerField(blank=True, initial=0)
bonusChoice = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
label='How do you want your bonus for part 2 to be determined '
'(according to the reminder above)?')
environment_choice = models.BooleanField(
widget=widgets.RadioSelect,
blank=True)
message = models.LongStringField(blank=True, label='What approach did you use in the last 5 decisions?')
explain = models.LongStringField(blank=True)
approach = models.LongStringField(blank=True, label= 'Throughout this study, what was your approach to '
'choosing the task? Did it change over time?')
advice = models.IntegerField(blank=True,
widget=widgets.RadioSelect
)
change = models.IntegerField(blank=True,
choices=[
[1, 'Yes'],
[2, 'No']
],
widget=widgets.RadioSelect
)
sep_task = models.IntegerField(blank=True,
widget=widgets.RadioSelect
)
bonus_guess_plan = models.FloatField(blank=True, label='Average bonus of participants with the planning tool:')
bonus_guess_no_plan = models.FloatField(blank=True, label='Average bonus of participants without the planning tool:')
# FUNCTIONS
def environment_choice_choices(player):
if player.participant.salient:
choices = [
[True, C.LABEL_POOL[player.round_number-1] +" task. We will not tell you the computers' quality"],
[False, C.LABEL_SEP[player.round_number-1] +" task. We will tell you the computers' quality"]
]
else:
choices = [
[True, C.LABEL_POOL[player.round_number - 1]+' task.'],
[False, C.LABEL_SEP[player.round_number - 1]+' task.']
]
random.shuffle(choices)
return choices
def sep_task_choices(player):
choices = [
[1, C.LABEL_SEP[-1]],
[2, C.LABEL_POOL[-1]]
]
random.shuffle(choices)
return choices
def cq_part2_choices(player):
pp = player.participant
if not pp.treatment == 'base':
choices = [
[1, 'No, I will never learn exactly how much each computer produced.'],
[2, 'Yes, I will learn about it, but only once the experiment ends and I get my bonus payment.'],
[3, 'Yes, I will learn how much each computer produced before part 2.']
]
elif pp.treatment == 'salient':
if player.environment_choice:
choices = [
[3, "No, we will not tell you the computer's quality."],
[2, "Yes, we will tell you the computer's quality, but only once the experiment ends and you get "
"your bonus payment."],
[1, "Yes, we will tell you the computer's quality before part 2."],
]
else:
choices = [
[1, "No, we will not tell you the computer's quality."],
[2, "Yes, we will tell you the computer's quality, but only once the experiment ends and you get "
"your bonus payment."],
[3, "Yes, we will tell you the computer's quality before part 2."],
]
else:
choices = [
[1, 'No, I will never learn exactly how much the computer produced.'],
[2, 'Yes, I will learn about it, but only once the experiment ends and I get '
'my bonus payment.'],
[3, 'Yes, I will learn how much the computer produced before part 2.'],
]
return choices
def cq_part2_error_message(player, value):
if not player.session.config['development']:
if value is None:
return 'Please, answer the question.'
elif value != 3:
player.cq_part2_mistakes += 1
return 'Your answer is incorrect.'
def cq1_choices(player):
pp = player.participant
if not pp.base:
choices = [
[1, 'They solve the ' + C.LABEL_POOL[player.round_number-1] + ' task, and the '
+ C.LABEL_SEP[player.round_number-1] + ' task, for a total of two tasks.'],
[2, 'It has not yet been decided. It is my task to decide it.'],
[3, 'They solve the ' + C.LABEL_SEP[player.round_number-1] + ' task.'],
[4, 'They solve the ' + C.LABEL_POOL[player.round_number - 1] + ' task.']
]
else:
choices = [
[1, 'It solves the ' + C.LABEL_POOL[player.round_number-1] + ' task, and the '
+ C.LABEL_SEP[player.round_number-1] + ' task, for a total of two tasks.'],
[2, 'It has not yet been decided. It is my task to decide it.'],
[3, 'It solves the ' + C.LABEL_SEP[player.round_number-1] + ' task.'],
[4, 'It solves the ' + C.LABEL_POOL[player.round_number - 1] + ' task.']
]
random.shuffle(choices)
return choices
def cq1_error_message(player, value):
if not player.session.config['development']:
if value is None:
return 'Please, answer the question.'
elif value != 3:
player.cq1_mistakes += 1
return 'Your answer is incorrect. Please review the instructions for this decision.'
def cq2_choices(player):
pp = player.participant
if not pp.base:
choices = [
[1, 'For each task that the computers solve, I get ' +
str(cu(player.session.parameterization[player.participant.param_rounds[player.round_number-1] - 1][0])
) + '. This applies to both tasks.'],
[2, "In part 1, I get whatever amount the computers produce in that part's tasks. "
"I can choose my bonus for part 2 to be whatever amount the computer of my choice"
" produces in that part's task or a fixed bonus of " + str(C.OUTSIDE_OPTION) + '.'],
[3, 'For each task the computers solve, I get the amount they produce.'
' This applies to both tasks, and I get ' + str(C.OUTSIDE_OPTION) + ' on top of it.']
]
else:
choices = [
[1, 'For each task that the computer solves, I get ' +
str(cu(player.session.parameterization[player.participant.param_rounds[player.round_number-1] - 1][0])
) + '. This applies to both tasks.'],
[2, "In part 1, I get whatever amount the computer produces in that part's task. "
"I can choose my bonus for part 2 to be whatever amount the computer produces in that part's "
"task or a fixed bonus of " + str(C.OUTSIDE_OPTION) + '.'],
[3, 'For each task the computer solves, I get the amount it produces.'
' This applies to both tasks, and I get ' + str(C.OUTSIDE_OPTION) + ' on top of it.']
]
random.shuffle(choices)
return choices
def cq2_error_message(player, value):
if not player.session.config['development']:
if value is None:
return 'Please, answer the question.'
elif value != 2:
player.cq2_mistakes += 1
return 'Your answer is incorrect. Please review the instructions for this decision.'
def bonusChoice_choices(player):
pp = player.participant
# chosen_decision_index = pp.chosen_decisions
if not pp.treatment == 'base':
if player.environment_choice:
payoff_part1_indiv = player.participant.part1_payoffs[player.round_number-1]/2
x = player.participant.pool_choice[player.round_number - 1]
choices = [
[x,
'Both computers produced '+ str(cu(payoff_part1_indiv)) +' in part 1. I want to get what one of them, chosen randomly, produces in part 2 as my bonus.'],
# [2,
# 'This computer produced '+ str(cu(payoff_part1_indiv)) +' in part 1. I want to get what it produces in part 2 as my bonus.'],
[3, 'I want to get the fixed payment as my bonus.']
# [1, 'The amount produced by the computer which produced ' + str(cu(payoff_part1_indiv)) + ' in part 1.'],
# [2, 'The amount produced by the computer which produced ' + str(cu(payoff_part1_indiv)) + ' in part 1.'],
# [3, 'The fixed payment, independent of how much the computers produce.']
]
else:
payoff_part1_good = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][1]
payoff_part1_bad = player.session.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][2]
choices = [
[1, 'This computer produced '+ str(cu(payoff_part1_good)) + ' in part 1. I want to get what it produces in part 2 as my bonus.'],
[2, 'This computer produced '+ str(cu(payoff_part1_bad)) + ' in part 1. I want to get what it produces in part 2 as my bonus.'],
[3, 'I want to get the fixed payment as my bonus.']
# [1, 'The amount produced by the computer which produces ' + str(cu(payoff_part1_good)) + ' in part 1.'],
# [2, 'The amount produced by the computer which produces ' + str(cu(payoff_part1_bad)) + ' in part 1.'],
# [3, 'The fixed payment, independent of how much the computers produce.']
]
else:
choices = [
[1, 'The amount the computer produces in this part.'],
[3, 'The fixed payment, independent of how much the computer produces.']
]
random.shuffle(choices)
return choices
def bonusChoice_error_message(player, value):
if not player.session.config['development'] and value is None:
return 'Please, answer the question.'
def environment_choice_error_message(player, value):
if not player.session.config['development'] and value is None:
return 'Please, answer the question.'
def vars_for_template1(player: Player):
pp = player.participant
ps = player.session
current_parameterization = pp.param_rounds[player.round_number - 1]
# chosen_decision_index = pp.chosen_decisions
# chosen_decision = chosen_decision_index if chosen_decision_index < 6 else chosen_decision_index - 5
part2_bonus = ps.parameterization[current_parameterization - 1][-2:]
part1_bonus = ps.parameterization[current_parameterization - 1][:3]
return dict(
comp_type=pp.compType[player.round_number-1],
part2_bonus_good=cu(part2_bonus[0]),
part2_bonus_bad=cu(part2_bonus[1]),
part1_bonus_pool=cu(part1_bonus[0]),
part1_bonus_good_sep=cu(part1_bonus[1]),
part1_bonus_bad_sep=cu(part1_bonus[2]),
current_parameterization=current_parameterization,
# chosen_decision=chosen_decision,
label_pool=C.LABEL_POOL[player.round_number-1],
label_sep=C.LABEL_SEP[player.round_number-1],
stage2_rounds=player.round_number - 5,
# stage_of_chosen_decision=1 if chosen_decision_index < 6 else 2,
decision_name=C.LABEL_POOL[player.round_number - 1] + '/' + C.LABEL_SEP[player.round_number - 1],
progress=int((player.round_number-1) / C.NUM_ROUNDS * 100)
)
def advice_choices(player):
if not player.participant.base:
choices = [
[1, 'Advise that the computers solve the ' + C.LABEL_POOL[-1] + ' task.'],
[2, 'Advise that the computers solve the ' + C.LABEL_SEP[-1] + ' task.']
]
else:
choices = [
[1, 'Advise that the computer solves the ' + C.LABEL_POOL[-1] + ' task.'],
[2, 'Advise that the computer solves the ' + C.LABEL_SEP[-1] + ' task.']
]
return choices
# PAGES
class Parameterization(Page):
vars_for_template = vars_for_template1
@staticmethod
def before_next_page(player: Player, timeout_happened):
print(player.participant.param_rounds[player.round_number-1])
class CQIntro(Page):
form_model = 'player'
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
@staticmethod
def get_form_fields(player):
questions = ['cq1_intro', 'cq2_intro', 'cq3_intro']
if not player.participant.base:
questions = [x + '_det' for x in questions]
return questions
@staticmethod
def error_message(player, values):
if not player.session.config['development']:
if player.participant.base:
solutions = dict(cq1_intro=2,
cq2_intro=1,
cq3_intro=3
)
else:
solutions = dict(cq1_intro_det=2,
cq2_intro_det=2,
cq3_intro_det=3
)
error_messages = dict()
for field_name in solutions:
if values[field_name] is None:
error_messages[field_name] = 'Please, answer the question.'
elif values[field_name] != solutions[field_name]:
error_messages[field_name] = 'Please, correct your answer!'
name = 'player.' + str(field_name) + '_mistakes'
exec("%s += 1" % name)
return error_messages
@staticmethod
def before_next_page(player: Player, timeout_happened):
if not player.participant.base:
player.intro_cq_mistakes = player.cq1_intro_det_mistakes + player.cq2_intro_det_mistakes + player.cq3_intro_det_mistakes
else:
player.intro_cq_mistakes = player.cq1_intro_mistakes + player.cq2_intro_mistakes + player.cq3_intro_mistakes
player.participant.pool_choice = random.choices([1, 2], k=C.NUM_ROUNDS)
# + player.cq4_mistakes + player.cq5_mistakes + player.cq1_det_mistakes + player.cq2_det_mistakes + \
# player.cq3_det_mistakes + player.cq4_det_mistakes
@staticmethod
def vars_for_template(player):
pp = player.participant
ps = player.session
# chosen_decision_index = pp.chosen_decisions
current_parameterization = pp.param_rounds[player.round_number - 1]
part2_bonus = ps.parameterization[current_parameterization - 1][-2:]
part1_bonus = ps.parameterization[current_parameterization - 1][:3]
return dict(
label_pool=C.LABEL_POOL[player.round_number - 1],
label_sep=C.LABEL_SEP[player.round_number - 1],
# stage_of_chosen_decision=1 if chosen_decision_index < 6 else 2,
current_parameterization=current_parameterization,
part2_bonus_good=cu(part2_bonus[0]),
part2_bonus_bad=cu(part2_bonus[1]),
part1_bonus_pool=cu(part1_bonus[0]),
part1_bonus_good_sep=cu(part1_bonus[1]),
part1_bonus_bad_sep=cu(part1_bonus[2])
)
class CQ(Page):
form_model = 'player'
@staticmethod
def get_form_fields(player):
form_fields = ['cq1']
if player.round_number == 1:
form_fields += ['cq2']
return form_fields
@staticmethod
def before_next_page(player: Player, timeout_happened):
player.info_cost_cq_mistakes = player.cq1_mistakes + player.cq2_mistakes
@staticmethod
def vars_for_template(player):
pp = player.participant
ps = player.session
current_parameterization = pp.param_rounds[player.round_number - 1]
# chosen_decision_index = pp.chosen_decisions
# chosen_decision = chosen_decision_index if chosen_decision_index < 6 else chosen_decision_index - 5
part2_bonus = ps.parameterization[current_parameterization - 1][-2:]
part1_bonus = ps.parameterization[current_parameterization - 1][:3]
if not player.participant.base:
cq1_label = 'In part 2 of this decision, which task do the computers solve?'
else:
cq1_label = 'In part 2 of this decision, which task does the computer solve?'
cq2_label = 'How is your bonus determined in this decision?'
return dict(
comp_type=pp.compType[player.round_number - 1],
part2_bonus_good=cu(part2_bonus[0]),
part2_bonus_bad=cu(part2_bonus[1]),
part1_bonus_pool=cu(part1_bonus[0]),
part1_bonus_good_sep=cu(part1_bonus[1]),
part1_bonus_bad_sep=cu(part1_bonus[2]),
current_parameterization=current_parameterization,
# chosen_decision=chosen_decision,
label_pool=C.LABEL_POOL[player.round_number - 1],
label_sep=C.LABEL_SEP[player.round_number - 1],
stage2_rounds=player.round_number - 5,
current_round = player.round_number,
# stage_of_chosen_decision=1 if chosen_decision_index < 6 else 2,
cq1_label=cq1_label,
cq2_label=cq2_label
)
class EnvironmentStage(Page):
form_model = 'player'
form_fields = ['environment_choice', 'timeSpent']
@staticmethod
def vars_for_template(player: Player):
pp = player.participant
ps = player.session
current_parameterization = pp.param_rounds[player.round_number - 1]
# chosen_decision_index = pp.chosen_decisions
# chosen_decision = chosen_decision_index if chosen_decision_index < 6 else chosen_decision_index - 5
part2_bonus = ps.parameterization[current_parameterization - 1][-2:]
part1_bonus = ps.parameterization[current_parameterization - 1][:3]
label = 'Which task do you want the computers to solve in part 1?' if not pp.base \
else 'Which task do you want the computer to solve in part 1?'
return dict(
comp_type=pp.compType[player.round_number - 1],
part2_bonus_good=cu(part2_bonus[0]),
part2_bonus_bad=cu(part2_bonus[1]),
part1_bonus_pool=cu(part1_bonus[0]),
part1_bonus_good_sep=cu(part1_bonus[1]),
part1_bonus_bad_sep=cu(part1_bonus[2]),
current_parameterization=current_parameterization,
# chosen_decision=chosen_decision,
label_pool=C.LABEL_POOL[player.round_number-1],
label_sep=C.LABEL_SEP[player.round_number-1],
label=label,
stage2_rounds=player.round_number - 5,
# stage_of_chosen_decision=1 if chosen_decision_index < 6 else 2,
decision_name=C.LABEL_POOL[player.round_number - 1] + '/' + C.LABEL_SEP[player.round_number - 1]
)
@staticmethod
def error_message(player, values):
if player.session.config['development']:
values['environment_choice'] = True
player.environment_choice = True
elif values['environment_choice'] is None:
return 'Please, answer the question.'
@staticmethod
def before_next_page(player, timeout_happened):
environment_choice_MaybeNone = player.field_maybe_none('environment_choice')
if player.session.config['development'] and environment_choice_MaybeNone is None:
player.environment_choice = True
# if not player.participant.base and player.round_number == 5:
# not player.participant.base = False
# player.participant.base = True
# if player.participant.salient and player.round_number == 5:
# player.participant.salient = False
# player.participant.base = True
class PostDifficultyChoice(Page):
form_model = 'player'
form_fields = ['cq_part2']
@staticmethod
def is_displayed(player: Player):
return player.participant.treatment != 'salient' and player.round_number == 1
@staticmethod
def vars_for_template(player: Player):
pp = player.participant
# chosen_decision_index = pp.chosen_decisions
# chosen_decision = chosen_decision_index if chosen_decision_index < 6 else chosen_decision_index - 5
current_parameterization = pp.param_rounds[player.round_number - 1]
if not pp.treatment == 'base':
label = 'Will you learn how much money each computer produced in part 1?'
elif pp.treatment == 'salient':
label = "Will we tell you the computer's quality?"
else:
label = 'Will you learn how much money the computer produced in part 1?'
return dict(
comp_type=player.participant.compType[player.round_number - 1],
current_parameterization=current_parameterization,
# chosen_decision=chosen_decision,
label_pool=C.LABEL_POOL[player.round_number - 1],
label_sep=C.LABEL_SEP[player.round_number - 1],
label=label,
environment_chosen_decision=player.environment_choice
)
class ObserveMistakes(Page):
@staticmethod
def vars_for_template(player: Player):
pp = player.participant
ps = player.session
# chosen_decision_index = pp.chosen_decisions
# chosen_decision = chosen_decision_index if chosen_decision_index < 6 else chosen_decision_index - 5
part1_bonus = ps.parameterization[player.participant.param_rounds[player.round_number - 1] - 1][:3]
myDict = dict(environment_chosen_decision=player.environment_choice,
label_pool=C.LABEL_POOL[player.round_number - 1],
label_sep=C.LABEL_SEP[player.round_number - 1],
# stage_of_chosen_decision=1 if chosen_decision_index < 6 else 2,
part1_bonus_pool=cu(part1_bonus[0]),
part1_bonus_good_sep=cu(part1_bonus[1]),
part1_bonus_bad_sep=cu(part1_bonus[2]),
current_parameterization=pp.param_rounds[player.round_number - 1],
comp_type=pp.compType[player.round_number - 1],
payoff_part1_indiv = cu(ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][0])
)
# Below we compute payoffs
if not pp.treatment == 'base':
if player.environment_choice: # pooling chosen
payoff_part1 = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][0] * 2
# pp.part1_payoffs.append(payoff_part1)
else: # separating chosen
payoff_part1_good = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][1]
payoff_part1_bad = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][2]
payoff_part1 = payoff_part1_good + payoff_part1_bad
# pp.part1_payoffs.append(payoff_part1)
myDict.update(payoff_part1_good=cu(payoff_part1_good),
payoff_part1_bad=cu(payoff_part1_bad))
else:
if player.environment_choice: # pooling chosen
payoff_part1 = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][0]
else: # separating chosen
if pp.compType[player.round_number - 1] == 1: # if comp is Good
payoff_part1 = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][1]
else: # if comp is Bad
payoff_part1 = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][2]
pp.part1_payoffs.append(payoff_part1)
myDict.update(payoff_part1=cu(payoff_part1))
# if not pp.treatment == 'base':
# pp.part1_payoffs.append(payoff_part1)
return myDict
class BonusChoice(Page):
form_model = 'player'
form_fields = ['bonusChoice', 'timeSpentBonus']
@staticmethod
def vars_for_template(player: Player):
pp = player.participant
ps = player.session
# chosen_decision_index = pp.chosen_decisions
# chosen_decision = chosen_decision_index if chosen_decision_index < 6 else chosen_decision_index - 5
part2_bonus = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][-2:]
part1_bonus = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][:3]
environment_chosen_decision = player.environment_choice
payoff_part1_good = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][1]
payoff_part1_bad = ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][2]
# stage_of_chosen_decision = 1 if chosen_decision_index < 6 else 2
return dict(
comp_type=pp.compType[player.round_number - 1],
part2_bonus_good=cu(part2_bonus[0]),
part2_bonus_bad=cu(part2_bonus[1]),
part1_bonus_pool=cu(part1_bonus[0]),
part1_bonus_good_sep=cu(part1_bonus[1]),
part1_bonus_bad_sep=cu(part1_bonus[2]),
current_parameterization=pp.param_rounds[player.round_number - 1],
# chosen_decision=chosen_decision,
label_pool=C.LABEL_POOL[player.round_number - 1],
label_sep=C.LABEL_SEP[player.round_number - 1],
# stage_of_chosen_decision=stage_of_chosen_decision,
environment_chosen_decision=environment_chosen_decision,
payoff_part1=cu(pp.part1_payoffs[player.round_number-1]),
payoff_part1_indiv=cu(pp.part1_payoffs[player.round_number-1]/2),
payoff_part1_good=cu(payoff_part1_good),
payoff_part1_bad=cu(payoff_part1_bad),
decision_name=C.LABEL_POOL[player.round_number - 1] + '/' + C.LABEL_SEP[player.round_number - 1]
)
@staticmethod
def before_next_page(player, timeout_happened):
bonusChoice_MaybeNone = player.field_maybe_none('bonusChoice')
if player.session.config['development'] and bonusChoice_MaybeNone is None:
player.bonusChoice = 1
@staticmethod
def error_message(player, values):
if not player.session.config['development'] and values['bonusChoice'] is None:
return 'Please, answer the question.'
class PostBonusChoice(Page):
@staticmethod
def vars_for_template(player: Player):
pp = player.participant
ps = player.session
# chosen_decision_index = pp.chosen_decisions
if not pp.treatment == 'base':
if player.bonusChoice == 1: # if variable payment is chosen and computer is good
payoff_part2 = cu(ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][3])
elif player.bonusChoice == 2: # variable payment chosen and computer is bad
payoff_part2 = cu(ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][4])
else: # if outside option is chosen
payoff_part2 = C.OUTSIDE_OPTION
else:
if player.bonusChoice == 1: # if variable payment is chosen
if pp.compType[player.round_number - 1] == 1: # variable payment chosen and computer is good
payoff_part2 = cu(ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][3])
else: # variable payment chosen and computer is bad
payoff_part2 = cu(ps.parameterization[pp.param_rounds[player.round_number - 1] - 1][4])
else: # if outside option is chosen
payoff_part2 = C.OUTSIDE_OPTION
pp.part2_payoffs.append(payoff_part2)
# if not pp.treatment == 'base':
# pp.part2_payoffs.append(payoff_part2)
return dict(
payoff_part2=payoff_part2,
decision_name=C.LABEL_POOL[player.round_number - 1] + '/' + C.LABEL_SEP[player.round_number - 1],
progress = int(player.round_number / C.NUM_ROUNDS * 100)
)
# @staticmethod
# def before_next_page(player: Player, timeout_happened):
# pp = player.participant
# all_participant_choices = []
# all_bonus_participant_choices = []
# if not pp.treatment == 'base': # in these treatments we only record the last bonusChoice since its the only one elicited
# pp.environment_choice = player.environment_choice
# pp.bonus_choices = player.bonusChoice
# else:
# if player.round_number == C.NUM_ROUNDS: # in baseline we record the last bonusChoice and the one in round 5, which are the two we elicit
# all_participant_choices.append(player.in_round(5).environment_choice)
# all_participant_choices.append(player.environment_choice)
# pp.environment_choice = all_participant_choices
# all_bonus_participant_choices.append(player.in_round(5).bonusChoice)
# all_bonus_participant_choices.append(player.bonusChoice)
# pp.bonus_choices = all_bonus_participant_choices
class Transition(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS
# class TransitionDet(Page):
# vars_for_template = vars_for_template1
#
# @staticmethod
# def is_displayed(player: Player):
# return player.round_number == 5 and player.participant.treatment == 'deterministic'
# class TransitionSalient(Page):
# vars_for_template = vars_for_template1
#
# @staticmethod
# def is_displayed(player: Player):
# return player.round_number == 5 and player.participant.treatment == 'salient'
class Message(Page):
form_model = 'player'
form_fields = ['message']
@staticmethod
def error_message(player, values):
if not player.session.config['development'] and (values['message']==''):
return 'Please, answer the questions.'
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS
class GuessBonus(Page):
form_model = 'player'
form_fields = ['bonus_guess_plan', 'bonus_guess_no_plan']
@staticmethod
def error_message(player, values):
if not player.session.config['development'] and (values['bonus_guess_plan'] is None or values['bonus_guess_no_plan'] is None):
return 'Please, answer the questions.'
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS and player.participant.treatment == 'deterministic'
class Hypothetical(Page):
form_model = 'player'
# form_fields = ['explain', 'approach', 'advice', 'change', 'sep_task']
form_fields = ['explain', 'advice', 'change', 'sep_task']
@staticmethod
def vars_for_template(player):
ps = player.session
if player.environment_choice:
label = 'In part 1 of the last decision, you chose the ' + \
C.LABEL_POOL[-1] + ' task. Why did you choose this task?'
change_label = 'In part 1 of the last decision, you chose the ' + \
C.LABEL_POOL[-1] + ' task. If you had a chance to revise your choice, would you prefer to choose the '+ C.LABEL_SEP[-1] + ' task instead?'
else:
label = 'In part 1 of the last decision, you chose the ' + \
C.LABEL_SEP[-1] + ' task. Why did you choose this task?'
change_label = 'In part 1 of the last decision, you chose the ' + \
C.LABEL_SEP[-1] + ' task. If you had a chance to revise your choice, would you prefer to choose the ' + C.LABEL_POOL[
-1] + ' task instead?'
if not player.participant.base:
adv_label = 'If you could advise another participant on the last decision of whether the computers ' \
'solve the ' + C.LABEL_POOL[-1] + ' or the ' + C.LABEL_SEP[
-1] + ' task, which would you advise ' \
'them to choose?'
sep_task_label = 'In part 1 of the last decision, which task allows you to learn the quality of the computers?'
else:
adv_label = 'If you could advise another participant on the last decision of whether the computer ' \
'solves the ' + C.LABEL_POOL[-1] + ' or the ' + C.LABEL_SEP[-1] + ' task, which would you advise ' \
'them to choose?'
sep_task_label= 'In part 1 of the last decision, which task allows you to learn the quality of the computers?'
current_parameterization = player.participant.param_rounds[- 1]
part2_bonus = ps.parameterization[current_parameterization - 1][-2:]
part1_bonus = ps.parameterization[current_parameterization - 1][:3]
return dict(
explain_label=label,
advice_label=adv_label,
change_label = change_label,
sep_task_label=sep_task_label,
label_pool=C.LABEL_POOL[- 1],
label_sep=C.LABEL_SEP[- 1],
# stage_of_chosen_decision=2,
current_parameterization=current_parameterization,
part2_bonus_good=cu(part2_bonus[0]),
part2_bonus_bad=cu(part2_bonus[1]),
part1_bonus_pool=cu(part1_bonus[0]),
part1_bonus_good_sep=cu(part1_bonus[1]),
part1_bonus_bad_sep=cu(part1_bonus[2]),
)
@staticmethod
def error_message(player, values):
# if not player.session.config['development'] and (values['advice'] is None or values['change'] is None or values['sep_task'] is None or values['explain']=='' or values['approach']==''):
if not player.session.config['development'] and (values['advice'] is None or values['change'] is None or values['sep_task'] is None or values['explain']==''):
return 'Please, answer the questions.'
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS
@staticmethod
def app_after_this_page(player, upcoming_apps):
if not player.participant.treatment == 'strategy':
return upcoming_apps[1]
page_sequence = [
Parameterization,
CQIntro,
CQ,
EnvironmentStage,
PostDifficultyChoice,
ObserveMistakes,
BonusChoice,
PostBonusChoice,
Message,
GuessBonus,
Hypothetical
# Transition
# TransitionDet,
# TransitionSalient
]