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
# 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(1.5)
# 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(5)]
# 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(5)]
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)
lottery1 = 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,
# str(C.LOTTERY_PAYOFFS[0][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery2 = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[1][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[1][1]) + '.'],
# [2,
# str(C.LOTTERY_PAYOFFS[1][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery3 = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[2][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[2][1]) + '.'],
# [2,
# str(C.LOTTERY_PAYOFFS[2][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery4 = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[3][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[3][1]) + '.'],
# [2,
# str(C.LOTTERY_PAYOFFS[3][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery5 = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[4][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_PAYOFFS[4][1]) + '.'],
# [2,
# str(C.LOTTERY_PAYOFFS[4][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery1_det = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[0][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[0][1]) + '.'],
# [2,
# str(C.LOTTERY_DET_PAYOFFS[0][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery2_det = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[1][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[1][1]) + '.'],
# [2,
# str(C.LOTTERY_DET_PAYOFFS[1][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery3_det = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[2][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[2][1]) + '.'],
# [2,
# str(C.LOTTERY_DET_PAYOFFS[2][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery4_det = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[3][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[3][1]) + '.'],
# [2,
# str(C.LOTTERY_DET_PAYOFFS[3][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
lottery5_det = models.IntegerField(blank=True,
# choices=[
# [1, '50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[4][0]) +
# ' and 50% chance of getting ' +
# str(C.LOTTERY_DET_PAYOFFS[4][1]) + '.'],
# [2,
# str(C.LOTTERY_DET_PAYOFFS[4][2])
# + ' for sure.']
# ],
widget=widgets.RadioSelect,
label='Which option do you prefer?')
# 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?')
# FUNCTIONS
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 = ['lottery1', 'lottery3', 'lottery2', 'lottery5']
else:
fields = ['lottery3', 'lottery1', 'lottery2', 'lottery5']
return fields
@staticmethod
def vars_for_template(player):
if player.lottery1v3 == 1:
fields = ['lottery1', 'lottery3', 'lottery2', 'lottery5']
good_payoff = [str(cu(player.session.lottery_payoffs[i][0])) for i in [0, 2, 1, 4]]
bad_payoff = [str(cu(player.session.lottery_payoffs[i][1])) for i in [0, 2, 1, 4]]
fixed_payoff = [str(cu(player.session.lottery_payoffs[i][2])) for i in [0, 2, 1, 4]]
else:
fields = ['lottery3', 'lottery1', 'lottery2', 'lottery5']
good_payoff = [str(cu(player.session.lottery_payoffs[i][0])) for i in [2, 0, 1, 4]]
bad_payoff = [str(cu(player.session.lottery_payoffs[i][1])) for i in [2, 0, 1, 4]]
fixed_payoff = [str(cu(player.session.lottery_payoffs[i][2])) for i in [2, 0, 1, 4]]
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 ['lottery1', 'lottery3', 'lottery2', 'lottery5']:
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, 6)]
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, 6)]
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 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(5))
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(5))
lottery_payoffs = [[random.choice([player.session.lottery_payoffs[i][0],player.session.lottery_payoffs[i][1]]) for i in range(5)
],
[player.session.lottery_payoffs[i][2] for i in range(5)
]]
lottery_choices = [player.lottery1, player.lottery2, player.lottery3, player.lottery4, player.lottery5]
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(5)
]
lottery_payoffs[1] += [player.session.lottery_det_payoffs[i][2] for i in range(5)
]
lottery_choices += [player.lottery1_det, player.lottery2_det, player.lottery3_det, player.lottery4_det, player.lottery5_det]
chosen_lottery = random.choice(range(10))
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):
@staticmethod
def js_vars(player):
return dict(
link=player.session.prolific_completion_url+str(player.participant.label),
)
page_sequence = [
# Lottery,
# LotteryCorrect,
# Hypothetical,
Lottery13,
LotteryList,
LotteryExtra,
# Demographics,
End,
Redirect
]