from otree.api import * import random import math doc = """ Part 3 Instructions """ class C(BaseConstants): NAME_IN_URL = 'Part3_Instructions' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): WTA = models.IntegerField(label='Please enter your minimum required compensation value below.', min=0, max=100) blength = models.IntegerField() noise = models.BooleanField() random_number = models.IntegerField() bid_success = models.BooleanField(initial=True) treatment1 = models.BooleanField() include_random = models.BooleanField() def range_def(player): player.blength = player.in_round(1).participant.vars.get('box_length', None) player.treatment1 = player.in_round(1).participant.vars.get('treatment1', None) player.noise = player.in_round(1).participant.vars.get('noise', None) player.random_number = round(random.expovariate(0.02)) if player.random_number > 100: player.random_number = 100 else: player.random_number = player.random_number #round(-math.log(1-(random.randint(0,10000)/10000)*(1-math.exp(-0.002*1200)))/0.002) return{ 'length': player.blength, 'ran_num': player.random_number, 'noise':player.noise,'treatment1': player.treatment1 } def price_elicitation (player): if player.WTA > player.random_number: player.bid_success = False else: player.bid_success = True return { 'bid': player.bid_success, } def include_random_number (player): if player.bid_success == 0: player.include_random = False else: player.include_random = True return { 'include_random': player.include_random, } # PAGES class Start(Page): @staticmethod def before_next_page(player,timeout_happened): player.participant.vars['blength','ran_num','noise','treatment1'] = range_def(player) player.participant.vars['ran_num'] = player.random_number class PriceElicitation(Page): form_model = 'player' form_fields = ['WTA'] @staticmethod def before_next_page(player, timeout_happened): player.participant.vars['bid'] = price_elicitation(player) class PurchaseResults(Page): pass class RulesPart3(Page): @staticmethod def vars_for_template(player): player.participant.vars['include_random']= include_random_number(player) player.participant.vars['include_random']= player.include_random @staticmethod def app_after_this_page(player, upcoming_apps): if player.bid_success == 1: return upcoming_apps[0] else: return upcoming_apps[1] page_sequence = [Start, PriceElicitation, PurchaseResults, RulesPart3]