from otree.api import (
models,
widgets,
BaseConstants,
BaseSubsession,
BaseGroup,
BasePlayer,
Currency as c,
currency_range,
Page,
WaitPage,
)
import random
import json
import itertools
doc = """
Your app description
"""
class Constants(BaseConstants):
name_in_url = 'job_search_student'
players_per_group = 25
num_rounds = 200
search_cost_1 = 2
search_cost_2 = 3
search_cost_3 = 5
search_cost_4 = 8
search_cost_5 = 12
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
reservation_wage = models.IntegerField(min=1, max=10, label='Enter integer between 1 and 10 inclusive')
sample_size = models.IntegerField(min=0, max=5, label='Enter integer between 0 and 5 inclusive')
show = models.IntegerField(Initial=0)
draw = models.StringField()
drawrandom = models.IntegerField()
searchcost = models.FloatField()
subsidy = models.IntegerField()
largest_number = models.IntegerField()
endowments = models.IntegerField()
jobpayoff = models.IntegerField()
searchinter = models.IntegerField()
currentearning = models.CurrencyField()
currency = models.CurrencyField()
currency2 = models.CurrencyField()
currency3 = models.CurrencyField()
currency4 = models.CurrencyField()
currency5 = models.CurrencyField()
currency6 = models.CurrencyField()
currency7 = models.CurrencyField()
currency8 = models.CurrencyField()
currency9 = models.CurrencyField()
currency10 = models.CurrencyField()
# payoff_1 = models.IntegerField()
# payoff_2 = models.IntegerField()
# payoff_3 = models.IntegerField()
# payoff_4 = models.IntegerField()
# FUNCTION
def creating_session(subsession):
print('in creating session')
for p in subsession.get_players():
if p.round_number<41:
p.subsidy = subsession.session.config['phase1_subsidy']
else:
if 40
195:
p.subsidy = 0
if subsession.round_number == 1:
p.endowments = 200
p.participant.vars['totalEarnings'] = p.endowments
p.participant.vars['found_job'] = False
if subsession.round_number == 21:
p.endowments = 200
p.participant.vars['totalEarnings_2'] = p.endowments
p.participant.vars['found_job_2'] = False
if subsession.round_number == 41:
p.endowments = 200
p.participant.vars['totalEarnings_3'] = p.endowments
p.participant.vars['found_job_3'] = False
if subsession.round_number == 61:
p.endowments = 200
p.participant.vars['totalEarnings_4'] = p.endowments
p.participant.vars['found_job_4'] = False
if subsession.round_number == 81:
p.endowments = 200
p.participant.vars['totalEarnings_5'] = p.endowments
p.participant.vars['found_job_5'] = False
if subsession.round_number == 101:
p.endowments = 200
p.participant.vars['totalEarnings_6'] = p.endowments
p.participant.vars['found_job_6'] = False
if subsession.round_number == 121:
p.endowments = 200
p.participant.vars['totalEarnings_7'] = p.endowments
p.participant.vars['found_job_7'] = False
if subsession.round_number == 141:
p.endowments = 200
p.participant.vars['totalEarnings_8'] = p.endowments
p.participant.vars['found_job_8'] = False
if subsession.round_number == 161:
p.endowments = 200
p.participant.vars['totalEarnings_9'] = p.endowments
p.participant.vars['found_job_9'] = False
if subsession.round_number == 181:
p.endowments = 200
p.participant.vars['totalEarnings_10'] = p.endowments
p.participant.vars['found_job_10'] = False
p.show = 0
def custom_export(players):
# header row
yield ['session', 'participant_code', 'round_number', 'id_in_group', 'totalEarnings','totalEarnings_2', 'totalEarnings_3', 'totalEarnings_4', 'totalEarnings_5', 'totalEarnings_6','totalEarnings_7', 'totalEarnings_8', 'totalEarnings_9', 'totalEarnings_10']
for p in players:
yield [p.session.code, p.participant.code, p.round_number, p.id_in_group, p.participant.vars.get('totalEarnings', None), p.participant.vars.get('totalEarnings_2', None), p.participant.vars.get('totalEarnings_3', None), p.participant.vars.get('totalEarnings_4', None), p.participant.vars.get('totalEarnings_5', None), p.participant.vars.get('totalEarnings_6', None), p.participant.vars.get('totalEarnings_7', None), p.participant.vars.get('totalEarnings_8', None), p.participant.vars.get('totalEarnings_9', None), p.participant.vars.get('totalEarnings_10', None)]
def job_seeking(p):
print('player',p)
mydraw = [0,1,2,3,4,5,6,7,8,9,10]
if p.sample_size >0:
p.draw = json.dumps(random.choices(mydraw, weights=(40,1,1,1,1,1,1,1,1,1,1), k=p.sample_size))
print(p.draw)
p.largest_number = max(json.loads(p.draw))
print("The largest number is:", p.largest_number)
if p.round_number<61:
p.show = p.round_number
if 0 < p.round_number < 41:
if 0 < p.round_number < 21:
if p.largest_number >= p.reservation_wage:
p.payoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number -180) + p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number -180)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job'] = True
else:
p.payoff = p.subsidy - ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['totalEarnings'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings'])
else:
if p.largest_number >= p.reservation_wage:
p.payoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number - 160) + p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number - 160)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_2'] = True
p.participant.vars['found_job'] = False
else:
p.payoff = p.subsidy - ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job'] = False
p.participant.vars['totalEarnings_2'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_2'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_2'])
else:
if p.largest_number >= p.reservation_wage:
p.payoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number - 140) + p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number - 140)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_3'] = True
p.participant.vars['found_job_2'] = False
else:
p.payoff = p.subsidy - ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_2'] = False
p.participant.vars['totalEarnings_3'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_3'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_3'])
else:
if 60< p.round_number <81:
p.show = p.round_number
if p.largest_number >= p.reservation_wage:
p.payoff = p.largest_number * ( Constants.num_rounds + 1 - p.round_number-120) + p.subsidy - ((p.sample_size)*((p.sample_size)*(p.sample_size)+11)/6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number - 120)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_4'] = True
p.participant.vars['found_job_3'] = False
else:
p.payoff = p.subsidy - ((p.sample_size)*((p.sample_size)*(p.sample_size)+11)/6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_3'] = False
p.participant.vars['totalEarnings_4'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_4'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_4'])
else:
if 80= p.reservation_wage:
p.payoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number-100) + p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number - 100)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_5'] = True
p.participant.vars['found_job_4'] = False
else:
p.payoff = p.subsidy - ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_4'] = False
p.participant.vars['totalEarnings_5'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_5'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_5'])
else:
if 100= p.reservation_wage:
p.payoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number-80) + p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number-80)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_6'] = True
p.participant.vars['found_job_5'] = False
else:
p.payoff = p.subsidy - ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_5'] = False
p.participant.vars['totalEarnings_6'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_6'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_6'])
else:
if 120= p.reservation_wage:
p.payoff = p.largest_number * (
Constants.num_rounds + 1 - p.round_number-60) + p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number-60)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_7'] = True
p.participant.vars['found_job_6'] = False
else:
p.payoff = p.subsidy - ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_6'] = False
p.participant.vars['totalEarnings_7'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_7'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_7'])
else:
if 140= p.reservation_wage:
p.payoff = p.largest_number * (
Constants.num_rounds + 1 - p.round_number-40) + p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number-40)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_8'] = True
p.participant.vars['found_job_7'] = False
else:
p.payoff = p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_7'] = False
p.participant.vars['totalEarnings_8'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_8'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_8'])
else:
if 160= p.reservation_wage:
p.payoff = p.largest_number * (
Constants.num_rounds + 1 - p.round_number-20) + p.subsidy - (
(p.sample_size) * (
(p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number-20)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_9'] = True
p.participant.vars['found_job_8'] = False
else:
p.payoff = p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_8'] = False
p.participant.vars['totalEarnings_9'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_9'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_9'])
else:
p.show = p.round_number
if p.largest_number >= p.reservation_wage:
p.payoff = p.largest_number * (
Constants.num_rounds + 1 - p.round_number) + p.subsidy - (
(p.sample_size) * (
(p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = p.largest_number * (Constants.num_rounds + 1 - p.round_number)
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_10'] = True
p.participant.vars['found_job_9'] = False
else:
p.payoff = p.subsidy - (
(p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.jobpayoff = 0
p.searchcost = ((p.sample_size) * ((p.sample_size) * (p.sample_size) + 11) / 6)
p.participant.vars['found_job_9'] = False
p.participant.vars['totalEarnings_10'] += p.payoff
p.currentearning = p.participant.vars['totalEarnings_10'] - p.payoff
print("Your total earning is:", p.participant.vars['totalEarnings_10'])
else:
p.draw = str(0)
p.largest_number = 0
p.payoff = p.subsidy
p.jobpayoff = 0
p.searchcost = 0
p.show = p.round_number
if 0 1:
return False
else:
return True
class instruction(Page):
def is_displayed(self):
if self.subsession.round_number > 1:
return False
else:
return True
class Draw(Page):
def is_displayed(self):
if self.subsession.round_number > 1:
return False
else:
return True
class Draw_graph(Page):
def is_displayed(self):
if self.subsession.round_number > 1:
return False
else:
return True
class example(Page):
def is_displayed(self):
if self.subsession.round_number > 1:
return False
else:
return True
class Baseline(Page):
def is_displayed(self):
if self.subsession.round_number == 1:
return True
else:
return False
class page_a(Page):
form_model = 'player'
form_fields = ['reservation_wage']
def is_displayed(player):
if (player.round_number<21 and player.participant.vars['found_job'] == True) or (2020:
# a = player.round_number - 20
# else:
# a = player.round_number
# return dict(a=a)
class page_b(Page):
form_model = 'player'
form_fields = ['sample_size']
def is_displayed(player):
if (player.round_number<21 and player.participant.vars['found_job'] == True) or (20 180:
return True
else:
return False
class Final(Page):
def is_displayed(player):
if (player.participant.vars['found_job'] == True and player.show == player.round_number) or (player.subsession.round_number == 20 and player.participant.vars['found_job'] == False) or (player.participant.vars['found_job_2'] == True and player.show == player.round_number) or (player.subsession.round_number == 40 and player.participant.vars['found_job_2'] == False) or (player.participant.vars['found_job_3'] == True and player.show == player.round_number) or (player.subsession.round_number == 60 and player.participant.vars['found_job_3'] == False) or (player.participant.vars['found_job_4'] == True and player.show == player.round_number) or (player.subsession.round_number == 80 and player.participant.vars['found_job_4'] == False) or (player.participant.vars['found_job_5'] == True and player.show == player.round_number) or (player.subsession.round_number == 100 and player.participant.vars['found_job_5'] == False) or (player.participant.vars['found_job_6'] == True and player.show == player.round_number) or (player.subsession.round_number == 120 and player.participant.vars['found_job_6'] == False) or (player.participant.vars['found_job_7'] == True and player.show == player.round_number) or (player.subsession.round_number == 140 and player.participant.vars['found_job_7'] == False) or (player.participant.vars['found_job_8'] == True and player.show == player.round_number) or (player.subsession.round_number == 160 and player.participant.vars['found_job_8'] == False) or (player.participant.vars['found_job_9'] == True and player.show == player.round_number) or (player.subsession.round_number == 180 and player.participant.vars['found_job_9'] == False) or (player.participant.vars['found_job_10'] == True and player.show == player.round_number) or (player.subsession.round_number == 200 and player.participant.vars['found_job_10'] == False):
# if player.participant.vars['found_job'] == True and player.show == player.round_number or player.subsession.round_number == 20:
return True
else:
return False
# class Treatment(Page):
# def is_displayed(player):
# if player.round_number <41:
# if (player.participant.vars['found_job_2'] == True and player.show == player.round_number) or (player.subsession.round_number == 40 and player.participant.vars['found_job_2'] == False):
# return True
# else:
# return False
# class Final2(Page):
# def is_displayed(player):
# if player.round_number>40:
# if (player.participant.vars['found_job_3'] == True and player.show == player.round_number) or (player.subsession.round_number == 60 and player.participant.vars['found_job_3'] == False) or (player.participant.vars['found_job_4'] == True and player.show == player.round_number) or (player.subsession.round_number == 80 and player.participant.vars['found_job_4'] == False) or (player.participant.vars['found_job_5'] == True and player.show == player.round_number) or (player.subsession.round_number == 100 and player.participant.vars['found_job_5'] == False) or (player.participant.vars['found_job_6'] == True and player.show == player.round_number) or (player.subsession.round_number == 120 and player.participant.vars['found_job_6'] == False):
# return True
# else:
# return False
class Finalfinal(Page):
def is_displayed(player):
if player.round_number>180:
if player.participant.vars['found_job_10'] == True or player.subsession.round_number == 200:
return True
else:
return False
def before_next_page(player, timeout_happened):
print('player', player)
payoff_seeking(player)
print("Your payoff draw is", player.drawrandom)
class payoff(Page):
def is_displayed(player):
if player.participant.vars['found_job_10'] == True or player.round_number == 200:
return True
else:
return False
class thanks(Page):
def is_displayed(player):
if player.participant.vars['found_job_10'] == True or player.round_number == 200:
return True
else:
return False
page_sequence = [introduction, instruction, Draw, Draw_graph, example, Baseline, page_a, page_b, page_c, Results, Final, Finalfinal, payoff, thanks]