from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, Page, WaitPage, ) import random import json doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'job_search' players_per_group = 25 num_rounds = 120 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() # 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 400: 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 -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'] = 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 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 - 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_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 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 - 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_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 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-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_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 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-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_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 print("Your total earning is:", p.participant.vars['totalEarnings_5']) 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_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 print("Your total earning is:", p.participant.vars['totalEarnings_6']) 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 100: return True else: return False class Final(Page): def is_displayed(player): if player.round_number <41: 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): # if player.participant.vars['found_job'] == True and player.show == player.round_number or player.subsession.round_number == 20: return True else: return False 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>100: if player.participant.vars['found_job_6'] == True or player.subsession.round_number == 120: 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_6'] == True or player.round_number == 120: return True else: return False class thanks(Page): def is_displayed(player): if player.participant.vars['found_job_6'] == True or player.round_number == 120: return True else: return False page_sequence = [introduction, instruction, Draw, Draw_graph, example, Baseline, page_a, page_b, page_c, Results, Final, Treatment, Final2, Finalfinal, payoff, thanks]