import random
from otree.api import *
doc = """
The app with the lottery elicitations and end of experiment
"""
class C(BaseConstants):
NAME_IN_URL = 'lottery'
PLAYERS_PER_GROUP = None
NUM_ROUNDS = 1
N = 6 # Number of lotteries to elicit
# BONUS_PER_CORRECT_TASK_PART1 = cu(0.15)
# BONUS_PART2_1AND2 = cu(0.25)
# BONUS_PART2_5 = cu(0.35)
# BONUS_PART2_3AND4 = cu(0.55)
# BONUS_PART2_DET = cu(0.5)
OUTSIDE_OPTION = cu(2.2)
# NUMBER_OF_TASKS_PART1 = 2
# NUMBER_OF_TASKS_PART2 = 10
# NUMBER_OF_MISTAKES = 1
# RATE_OF_MISTAKES = 2
# RATE_OF_MISTAKES2 = 1
# LOTTERY_PAYOFFS = [[BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 + BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2,
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *(1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) +
# OUTSIDE_OPTION,
# OUTSIDE_OPTION + BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1
# ],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 +
# BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2,
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2) +
# OUTSIDE_OPTION,
# OUTSIDE_OPTION + BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1
# ],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2) +
# OUTSIDE_OPTION,
# OUTSIDE_OPTION + BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1
# ],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2) +
# OUTSIDE_OPTION,
# OUTSIDE_OPTION + BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1
# * (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES)
# ],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) +
# BONUS_PART2_5 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2) +
# OUTSIDE_OPTION,
# OUTSIDE_OPTION + BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1
# ]] # For each lottery: [Pool and Good, Pool and Bad, Sep]
# LOTTERY_DET_PAYOFFS = [[BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2,
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES + 1) +
# BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2,
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2 + 1) +
# BONUS_PART2_1AND2 * NUMBER_OF_TASKS_PART2],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2 + 1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES)],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * (
# 1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) * 2 +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * (
# 1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) * 2 +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2 + 1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) +
# BONUS_PART2_3AND4 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES)],
# [BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_5 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 * 2 +
# BONUS_PART2_5 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2),
# BONUS_PER_CORRECT_TASK_PART1 * NUMBER_OF_TASKS_PART1 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES2 + 1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES) +
# BONUS_PART2_5 * NUMBER_OF_TASKS_PART2 *
# (1 - NUMBER_OF_MISTAKES / RATE_OF_MISTAKES)]] # For each lottery: [Pool and Good, Pool and Bad, Sep]
class Subsession(BaseSubsession):
pass
def creating_session(subsession: Subsession):
# each round is: [part1_pool, part1_good_sep, part1_bad_sep, part2_good, part2_bad]
# r1 = (cu(0.3), cu(0.3), cu(0.15), cu(2.5), cu(1.25))
# r2 = (cu(0.3), cu(0.3), cu(0), cu(2.5), cu(0))
# r3 = (cu(0.3), cu(0.15), cu(0), cu(2.75), cu(0))
# r4 = (cu(0.15), cu(0.15), cu(0), cu(2.75), cu(0))
# r5 = (cu(0.3), cu(0.15), cu(0), cu(1.75), cu(0))
# subsession.session.parameterization = (r1, r2, r3, r4, r5) * 2 # Delete this when running combined apps
# For each lottery: [Sep and Good, Sep and Bad, Pool and Outside]
subsession.session.lottery_payoffs = [[subsession.session.parameterization[i][1]+subsession.session.parameterization[i][3],
subsession.session.parameterization[i][2]+C.OUTSIDE_OPTION,
subsession.session.parameterization[i][0]+C.OUTSIDE_OPTION] for i in range(C.N)]
# For each lottery: [Pool and Good, Pool and Bad, Sep and Good]
subsession.session.lottery_det_payoffs = [[subsession.session.parameterization[i][0]*2+subsession.session.parameterization[i][3],
subsession.session.parameterization[i][0]*2+subsession.session.parameterization[i][4],
subsession.session.parameterization[i][1]+subsession.session.parameterization[i][2]
+subsession.session.parameterization[i][3]] for i in range(C.N)]
class Group(BaseGroup):
pass
class Player(BasePlayer):
feedback = models.LongStringField(label='Feedback:', blank=True)
feedbackDifficulty = models.IntegerField(label="How difficult were the instructions? Please answer on a scale of 1 "
"to 10 with 10 being the most difficult",
blank=True,
choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
widget=widgets.RadioSelectHorizontal)
feedbackUnderstanding = models.IntegerField(label="How well did you understand what you were asked to do?"
" Please answer on a scale of 1 to 10 with 10 being the case when"
" you understood perfectly",
blank=True,
choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
widget=widgets.RadioSelectHorizontal)
feedbackSatisfied = models.IntegerField(label="How satisfied are you with this study overall?"
" Please answer on a scale of 1 to 10 with 10 being the most "
"satisfied",
blank=True,
choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
widget=widgets.RadioSelectHorizontal)
feedbackPay = models.IntegerField(label="How appropriate do you think the payment for this study is relative to "
"other ones on Prolific? Please answer on a scale of 1 to 10 with 10 being "
"the most appropriate",
blank=True,
choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
widget=widgets.RadioSelectHorizontal)
# explain = models.LongStringField(blank=True)
for j in range(1, 11):
locals()['lottery' + str(j)] = models.IntegerField(blank=True, widget=widgets.RadioSelect,
label='Which option do you prefer?')
locals()['lottery' + str(j) + '_det'] = models.IntegerField(blank=True, widget=widgets.RadioSelect,
label='Which option do you prefer?')
del j
# for j in range(1, 6):
# locals()['lottery' + str(j) + '_initial'] = models.IntegerField(blank=True, initial=0)
# locals()['lottery' + str(j) + '_det_initial'] = models.IntegerField(blank=True, initial=0)
# del j
# lottery_inconsistency = models.BooleanField(blank=True, initial=False)
lottery1v3 = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[0][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[0][1]) + '.'],
# [2, '50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[2][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[2][1]) + '.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
# advice = models.IntegerField(blank=True,
# choices=[
# [1, 'Advise that the computer faces ' + str(C.LABEL_A) + ' tasks.'],
# [2, 'Advise that the computer faces ' + str(C.LABEL_B) + ' tasks.']
# ],
# widget=widgets.RadioSelect,
# label='If you could advise another participant on the last decision of '
# 'whether the computer faces ' + str(C.LABEL_A) + ' or ' + str(C.LABEL_B) +
# ' tasks, which would you advise them to choose?'
# )
stageCounts = models.IntegerField(blank=True)
age = models.IntegerField(blank=True,
max=100,
min=18,
label='How old are you?')
gender = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
choices=[
[1, 'Female'],
[2, 'Male'],
[3, 'Other (e.g., Non-binary, Genderqueer)']
],
label='What is your gender?')
race = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
choices=[
[1, 'Black or African American'],
[2, 'White'],
[3, 'Latinx'],
[4, 'American Indian or Alaska Native'],
[5, 'Asian'],
[6, 'Native Hawaiian or Pacific Islander'],
[7, 'Other']
],
label='What is your race?')
education = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
choices=[
[1, 'Less than high school degree'],
[2, 'High school or equivalent including GED'],
[3, 'Some college but no degree'],
[4, 'Associate or technical degree in college (2-year)'],
[5, "Bachelor's degree in college (4-year)"],
[6, "Master's degree"],
[7, 'Doctoral degree'],
[8, 'Professional degree (JD, MD)']
],
label='What is the highest degree you have received?')
sat = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
choices=[
[1, 'Strongly disagree'],
[2, 'Disagree'],
[3, 'Neither agree nor disagree'],
[4, 'Agree'],
[5, "Strongly agree"]
],
label='Recently, a number of colleges decided to stop requiring SAT and other standardized exam scores '
'as a requirement for application. How much do you agree with colleges requiring standardized '
'exam scores from applicants?')
parenting = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
choices=[
[1, 'Strongly disagree'],
[2, 'Disagree'],
[3, 'Neither agree nor disagree'],
[4, 'Agree'],
[5, "Strongly agree"]
],
label='Some parents control everything their children do, while others leave a lot of freedom to their children.'
' How much do you agree with parents controlling what their children do?')
intern = models.IntegerField(blank=True,
widget=widgets.RadioSelect,
choices=[
[1, 'Strongly disagree'],
[2, 'Disagree'],
[3, 'Neither agree nor disagree'],
[4, 'Agree'],
[5, "Strongly agree"]
],
label='Imagine that you are a team manager in a firm, and your team hired an intern. '
'How much do you agree with assigning only easy tasks to the intern?')
# FUNCTIONS
def make_lottery_choices_func(i):
def lottery_choices(player):
choices = [
[1, '50% chance of getting ' +
str(player.session.lottery_payoffs[i-1][0]) +
' and 50% chance of getting ' +
str(player.session.lottery_payoffs[i-1][1]) + '.'],
[2,
str(player.session.lottery_payoffs[i-1][2])
+ ' for sure.']
]
return choices
# Set the function name dynamically based on i
func_name = f"lottery{i}_choices"
lottery_choices.__name__ = func_name
return lottery_choices
# Define 10 functions using a loop
for i in range(1, 11):
globals()[f"lottery{i}_choices"] = make_lottery_choices_func(i)
def make_lottery_det_choices_func(i):
def lottery_det_choices(player):
choices = [
[1, '50% chance of getting ' +
str(player.session.lottery_det_payoffs[i - 1][0]) +
' and 50% chance of getting ' +
str(player.session.lottery_det_payoffs[i - 1][1]) + '.'],
[2,
str(player.session.lottery_det_payoffs[i - 1][2])
+ ' for sure.']
]
return choices
# Set the function name dynamically based on i
func_name = f"lottery{i}_det_choices"
lottery_det_choices.__name__ = func_name
return lottery_det_choices
# Define 10 functions using a loop
for i in range(1, 11):
globals()[f"lottery{i}_det_choices"] = make_lottery_choices_func(i)
#
# def lottery1_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_payoffs[0][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_payoffs[0][1]) + '.'],
# [2,
# str(player.session.lottery_payoffs[0][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery2_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_payoffs[1][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_payoffs[1][1]) + '.'],
# [2,
# str(player.session.lottery_payoffs[1][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery3_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_payoffs[2][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_payoffs[2][1]) + '.'],
# [2,
# str(player.session.lottery_payoffs[2][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery4_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_payoffs[3][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_payoffs[3][1]) + '.'],
# [2,
# str(player.session.lottery_payoffs[3][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery5_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_payoffs[4][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_payoffs[4][1]) + '.'],
# [2,
# str(player.session.lottery_payoffs[4][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery1_det_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_det_payoffs[0][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_det_payoffs[0][1]) + '.'],
# [2,
# str(player.session.lottery_det_payoffs[0][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery2_det_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_det_payoffs[1][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_det_payoffs[1][1]) + '.'],
# [2,
# str(player.session.lottery_det_payoffs[1][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery3_det_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_det_payoffs[2][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_det_payoffs[2][1]) + '.'],
# [2,
# str(player.session.lottery_det_payoffs[2][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery4_det_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_det_payoffs[3][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_det_payoffs[3][1]) + '.'],
# [2,
# str(player.session.lottery_det_payoffs[3][2])
# + ' for sure.']
# ]
# return choices
#
# def lottery5_det_choices(player):
# choices = [
# [1, '50% chance of getting ' +
# str(player.session.lottery_det_payoffs[4][0]) +
# ' and 50% chance of getting ' +
# str(player.session.lottery_det_payoffs[4][1]) + '.'],
# [2,
# str(player.session.lottery_det_payoffs[4][2])
# + ' for sure.']
# ]
# return choices
def lottery1v3_choices(player):
choices = [
[1, '50% chance of getting ' +
str(cu(player.session.lottery_payoffs[0][0])) +
' and 50% chance of getting ' +
str(cu(player.session.lottery_payoffs[0][1])) + '.'],
[2, '50% chance of getting ' +
str(cu(player.session.lottery_payoffs[2][0])) +
' and 50% chance of getting ' +
str(cu(player.session.lottery_payoffs[2][1])) + '.']
]
return choices
def custom_export(players):
# header row
participant_var_names = ['det', 'base', 'finished', 'label1', 'label2', 'param_rounds', 'environment_choice',
'compType', 'chosen_decisions', 'part1_payoffs', 'part2_payoffs']
yield participant_var_names
for p in players:
yield [p.participant.vars.get(name, None) for name in participant_var_names]
# PAGES
# class Lottery(Page):
# form_model = 'player'
#
# @staticmethod
# def get_form_fields(player):
# # player.participant.param_rounds = [1, 2, 3, 4, 5]
# # player.participant.environment_choice = [True]
# lotteries = ['lottery' + str(x) for x in random.sample([1,2,3,4,5], 5)]
# # if player.participant.treatment == 'deterministic':
# # lotteries += ['lottery' + str(x) + '_det' for x in random.sample([1,2,3,4,5], 5)]
# # random.shuffle(lotteries)
# player.participant.lottery_order = lotteries
# return lotteries
#
# @staticmethod
# def before_next_page(player, timeout_happened):
# lotteriesMaybeNone = [player.field_maybe_none('lottery' + str(x) for x in range(1, 6))]
# # [player.field_maybe_none('lottery1'), player.field_maybe_none('lottery2'), player.field_maybe_none('lottery3'),
# # player.field_maybe_none('lottery4'), player.field_maybe_none('lottery5')]
# if player.participant.treatment == 'deterministic':
# lotteriesMaybeNone += [player.field_maybe_none('lottery' + str(x) + '_det' for x in range(1, 6))]
# if player.session.config['development'] and None in lotteriesMaybeNone:
# player.lottery1, player.lottery2, player.lottery3, player.lottery4, player.lottery5 = [1] * 5
# if player.participant.treatment == 'deterministic':
# player.lottery1_det, player.lottery2_det, player.lottery3_det, player.lottery4_det, player.lottery5_det = [1] * 5
# player.lottery1_initial, player.lottery2_initial, player.lottery3_initial, player.lottery4_initial, player.lottery5_initial = \
# player.lottery1, player.lottery2, player.lottery3, player.lottery4, player.lottery5
# if player.participant.treatment == 'deterministic':
# player.lottery1_det_initial, player.lottery2_det_initial, player.lottery3_det_initial, player.lottery4_det_initial, player.lottery5_det_initial = \
# player.lottery1_det, player.lottery2_det, player.lottery3_det, player.lottery4_det, player.lottery5_det
#
# @staticmethod
# def error_message(player, values):
# if not player.session.config['development']:
# error_messages = dict()
# for field_name in ['lottery' + str(x) for x in range(1,6)]:
# if values[field_name] is None:
# error_messages[field_name] = 'Please, answer the question.'
# if player.participant.treatment == 'deterministic':
# for field_name in ['lottery' + str(x) + '_det' for x in range(1,6)]:
# if values[field_name] is None:
# error_messages[field_name] = 'Please, answer the question.'
# if (values['lottery2'] == 1 and (values['lottery1'] == 2 or values['lottery3'] == 2 or values['lottery4'] == 2))\
# or (values['lottery3'] == 1 and values['lottery4'] == 2) \
# or (values['lottery5'] == 1 and (values['lottery1'] == 2 or values['lottery2'] == 2 or values['lottery3'] == 2 or values['lottery4'] == 2)):
# player.lottery_inconsistency = True
# return error_messages
# class LotteryCorrect(Page):
# @staticmethod
# def is_displayed(player):
# return player.lottery_inconsistency
#
# form_model = 'player'
#
# @staticmethod
# def get_form_fields(player):
# return player.participant.lottery_order
#
# @staticmethod
# def error_message(player, values):
# if not player.session.config['development']:
# error_messages = dict()
# for field_name in ['lottery' + str(x) for x in range(1, 6)]:
# if values[field_name] is None:
# error_messages[field_name] = 'Please, answer the question.'
# if player.participant.treatment == 'deterministic':
# for field_name in ['lottery' + str(x) + '_det' for x in range(1, 6)]:
# if values[field_name] is None:
# error_messages[field_name] = 'Please, answer the question.'
# for x in ['lottery1', 'lottery3', 'lottery4']:
# if values['lottery2'] == 1 and values[x] == 2:
# error_messages['lottery2'], error_messages[x] = \
# ['Your choice in this question contradicts your choice in another question. '
# 'Please update your choices to make them consistent.']*2
# # if values['lottery2'] == 1 and values['lottery3'] == 2:
# # error_messages['lottery2'], error_messages['lottery3'] = \
# # ['Your choice in this question contradicts your choice in another question. '
# # 'Please update your choices to make them consistent.']*2
# # if values['lottery2'] == 1 and values['lottery4'] == 2:
# # error_messages['lottery2'], error_messages['lottery4'] = \
# # ['Your choice in this question contradicts your choice in another question. '
# # 'Please update your choices to make them consistent.']*2
# if values['lottery3'] == 1 and values['lottery4'] == 2:
# error_messages['lottery3'], error_messages['lottery4'] = \
# ['Your choice in this question contradicts your choice in another question. '
# 'Please update your choices to make them consistent.'] * 2
# for x in ['lottery1', 'lottery2', 'lottery3', 'lottery4']:
# if values['lottery5'] == 1 and values[x] == 2:
# error_messages['lottery5'], error_messages[x] = \
# ['Your choice in this question contradicts your choice in another question. '
# 'Please update your choices to make them consistent.'] * 2
# # if values['lottery5'] == 1 and (values['lottery1'] == 2 or values['lottery2'] == 2 or values['lottery3'] == 2 or values['lottery4'] == 2):
# # error_messages['lottery2'], error_messages[list(values.keys())[list(values.values()).index(2)]] = \
# # ['Your choice in this question contradicts your choice in another question. '
# # 'Please update your choices to make them consistent.']*(len([list(values.values()).index(2)])+1)
# return error_messages
# class Lottery13(Page):
# form_model = 'player'
# form_fields = ['lottery1v3']
#
# @staticmethod
# def error_message(player, values):
# if not player.session.config['development']:
# error_messages = dict()
# if values['lottery1v3'] is None:
# error_messages['lottery1v3'] = 'Please, answer the question.'
# return error_messages
#
# @staticmethod
# def before_next_page(player, timeout_happened):
# # player.participant.treatment = 'deterministic' # Delete this when running Combined
# lottery1v3_MaybeNone = player.field_maybe_none('lottery1v3')
# if player.session.config['development'] and lottery1v3_MaybeNone is None:
# player.lottery1v3 = 1
class LotteryList(Page):
form_model = 'player'
# @staticmethod
# def get_form_fields(player):
# if player.lottery1v3 == 1:
# fields = ['lottery'+str(x) for x in [1,3,2,5,6,7,8,9,10]]
# else:
# fields = ['lottery'+str(x) for x in [3,1,2,5,6,7,8,9,10]]
# return fields
@staticmethod
def get_form_fields(player):
if not player.participant.treatment == 'base':
fields = ['lottery' + str(x) + '_det' for x in range(1, C.N+1)]
else:
fields = ['lottery' + str(x) for x in range(1, C.N+1)]
return fields
# @staticmethod
# def vars_for_template(player):
# if player.lottery1v3 == 1:
# fields = ['lottery'+str(x) for x in [1,3,2,5,6,7,8,9,10]]
# good_payoff = [str(cu(player.session.lottery_payoffs[i][0])) for i in [0, 2, 1, 4,5,6,7,8,9]]
# bad_payoff = [str(cu(player.session.lottery_payoffs[i][1])) for i in [0, 2, 1, 4,5,6,7,8,9]]
# fixed_payoff = [str(cu(player.session.lottery_payoffs[i][2])) for i in [0, 2, 1, 4,5,6,7,8,9]]
# else:
# fields = ['lottery'+str(x) for x in [3,1,2,5,6,7,8,9,10]]
# good_payoff = [str(cu(player.session.lottery_payoffs[i][0])) for i in [2, 0, 1, 4,5,6,7,8,9]]
# bad_payoff = [str(cu(player.session.lottery_payoffs[i][1])) for i in [2, 0, 1, 4,5,6,7,8,9]]
# fixed_payoff = [str(cu(player.session.lottery_payoffs[i][2])) for i in [2, 0, 1, 4,5,6,7,8,9]]
# return {
# 'lotteries': zip(fields, good_payoff, bad_payoff, fixed_payoff)
# }
@staticmethod
def vars_for_template(player):
if not player.participant.treatment == 'base':
fields = ['lottery' + str(x) + '_det' for x in range(1, C.N+1)]
good_payoff = [str(cu(player.session.lottery_det_payoffs[i][0])) for i in range(C.N)]
bad_payoff = [str(cu(player.session.lottery_det_payoffs[i][1])) for i in range(C.N)]
fixed_payoff = [str(cu(player.session.lottery_det_payoffs[i][2])) for i in range(C.N)]
else:
fields = ['lottery' + str(x) for x in range(1, C.N+1)]
good_payoff = [str(cu(player.session.lottery_payoffs[i][0])) for i in range(C.N)]
bad_payoff = [str(cu(player.session.lottery_payoffs[i][1])) for i in range(C.N)]
fixed_payoff = [str(cu(player.session.lottery_payoffs[i][2])) for i in range(C.N)]
return {
'lotteries': zip(fields, good_payoff, bad_payoff, fixed_payoff)
}
# @staticmethod
# def error_message(player, values):
# if not player.session.config['development']:
# error_messages = dict()
# for field_name in ['lottery'+str(x) for x in [1,3,2,5,6,7,8,9,10]]:
# if values[field_name] is None:
# error_messages[field_name] = 'Please, answer the question.'
# return error_messages
@staticmethod
def error_message(player, values):
if not player.session.config['development']:
error_messages = dict()
if not player.participant.treatment == 'base':
fields = ['lottery' + str(x) + '_det' for x in range(1, C.N+1)]
else:
fields = ['lottery' + str(x) for x in range(1, C.N+1)]
for field_name in fields:
if values[field_name] is None:
error_messages[field_name] = 'Please, answer the question.'
return error_messages
# @staticmethod
# def before_next_page(player, timeout_happened):
# if player.lottery3 == 1:
# player.lottery4 = 1
# class LotteryExtra(Page):
# form_model = 'player'
#
# @staticmethod
# def is_displayed(player: Player):
# return player.lottery3 == 2 or player.participant.treatment == 'deterministic'
#
# @staticmethod
# def get_form_fields(player):
# fields = []
# if player.lottery3 == 2:
# fields = ['lottery4']
# if player.participant.treatment == 'deterministic':
# fields += ['lottery' + str(x) + '_det' for x in range(1, 11)]
# return fields
#
# @staticmethod
# def vars_for_template(player):
# fields, good_payoff, bad_payoff, fixed_payoff = [[],[],[],[]]
# if player.lottery3 == 2:
# fields += ['lottery4']
# good_payoff += [str(cu(player.session.lottery_payoffs[3][0]))]
# bad_payoff += [str(cu(player.session.lottery_payoffs[3][1]))]
# fixed_payoff += [str(cu(player.session.lottery_payoffs[3][2]))]
# if player.participant.treatment == 'deterministic':
# for x in range(5):
# fields += ['lottery' + str(x+1) + '_det']
# good_payoff += [str(cu(player.session.lottery_det_payoffs[x][0]))]
# bad_payoff += [str(cu(player.session.lottery_det_payoffs[x][1]))]
# fixed_payoff += [str(cu(player.session.lottery_det_payoffs[x][2]))]
# return {
# 'lotteries': zip(fields, good_payoff, bad_payoff, fixed_payoff)
# }
#
# @staticmethod
# def error_message(player, values):
# if not player.session.config['development']:
# error_messages = dict()
# field_names = []
# if player.participant.treatment == 'deterministic':
# field_names += ['lottery' + str(x) + '_det' for x in range(1, 11)]
# if player.lottery3 == 2:
# field_names += ['lottery4']
# for field_name in field_names:
# if values[field_name] is None:
# error_messages[field_name] = 'Please, answer the question.'
# return error_messages
class Attitudes(Page):
form_model = 'player'
form_fields = ['sat','parenting','intern']
@staticmethod
def error_message(player, values):
if not player.session.config['development']:
error_messages = dict()
field_names = ['sat','parenting','intern']
for field_name in field_names:
if values[field_name] is None:
error_messages[field_name] = 'Please, answer the question.'
return error_messages
class Demographics(Page):
form_model = 'player'
form_fields = ['age', 'gender', 'race', 'education']
@staticmethod
def error_message(player, values):
if not player.session.config['development']:
error_messages = dict()
field_names = ['age', 'gender', 'race', 'education']
for field_name in field_names:
if values[field_name] is None:
error_messages[field_name] = 'Please, answer the question.'
return error_messages
class End(Page):
form_model = 'player'
form_fields = ['feedback', 'feedbackDifficulty', 'feedbackUnderstanding',
'feedbackSatisfied', 'feedbackPay']
@staticmethod
def vars_for_template(player):
# if player.participant.treatment == 'deterministic' or player.participant.treatment == 'salient':
# player.stageCounts = random.choice([1, 3]) if player.participant.chosen_decisions < 6 else random.choice([2, 3])
# else:
player.stageCounts = random.choice([1, 2])
# player.stageCounts = 3 # Delete this when running Combined
if player.stageCounts == 1:
decision_to_count = random.choice(range(10))
player.payoff = player.participant.part1_payoffs[decision_to_count] + player.participant.part2_payoffs[decision_to_count]
# elif player.stageCounts == 2:
# player.payoff = player.participant.part1_payoffs[1] + player.participant.part2_payoffs[1]
else:
# chosen_lottery = random.choice(range(10))
# lottery_payoffs = [[random.choice([player.session.lottery_payoffs[i][0],player.session.lottery_payoffs[i][1]]) for i in range(10)
# ],
# [player.session.lottery_payoffs[i][2] for i in range(10)
# ]]
# lottery_choices = [player.lottery1, player.lottery2, player.lottery3, player.lottery4, player.lottery5,
# player.lottery6, player.lottery7, player.lottery8, player.lottery9, player.lottery10]
# if player.participant.treatment == 'deterministic':
# lottery_payoffs[0] += [random.choice([player.session.lottery_det_payoffs[i][0],
# player.session.lottery_det_payoffs[i][1]]) for i in range(10)
# ]
# lottery_payoffs[1] += [player.session.lottery_det_payoffs[i][2] for i in range(10)
# ]
# lottery_choices += [player.lottery1_det, player.lottery2_det, player.lottery3_det, player.lottery4_det, player.lottery5_det,
# player.lottery6_det, player.lottery7_det, player.lottery8_det, player.lottery9_det, player.lottery10_det]
# chosen_lottery = random.choice(range(20))
chosen_lottery = random.choice(range(C.N))
if not player.participant.treatment == 'base':
lottery_payoffs = [[random.choice([player.session.lottery_det_payoffs[i][0],
player.session.lottery_det_payoffs[i][1]]) for i in range(C.N)
],
[player.session.lottery_det_payoffs[i][2] for i in range(C.N)
]]
lottery_choices = [player.lottery1_det, player.lottery2_det, player.lottery3_det, player.lottery4_det,
player.lottery5_det, player.lottery6_det]
else:
lottery_payoffs = [
[random.choice([player.session.lottery_payoffs[i][0], player.session.lottery_payoffs[i][1]]) for i
in
range(C.N)
],
[player.session.lottery_payoffs[i][2] for i in range(C.N)
]]
lottery_choices = [player.lottery1, player.lottery2, player.lottery3, player.lottery4, player.lottery5, player.lottery6]
choice_counts = lottery_choices[chosen_lottery]
player.payoff = lottery_payoffs[choice_counts-1][chosen_lottery]
return dict(stageCounts=player.stageCounts,
payoff=player.payoff
)
@staticmethod
def before_next_page(player, timeout_happened):
player.participant.finished = True
class Redirect(Page):
pass
page_sequence = [
# Lottery,
# LotteryCorrect,
# Hypothetical,
# Lottery13,
LotteryList,
Attitudes,
# LotteryExtra,
Demographics,
End,
Redirect
]