from otree.api import * import random doc = """ As a newsvendor, you make daily decision on the newspaper order quantity. Suppose the price is $2 per newspaper, the cost per newspaper is $1, and demand follows a # Customers have random demand, # i.e., you don't know how many newspapers they actually need. If you order less than true demand, you will # lose sales; if you order more than true demand, newspapers will be left. """ class C(BaseConstants): NAME_IN_URL = 'newsvendor' PLAYERS_PER_GROUP = None NUM_ROUNDS = 10 PRICE = 2 COST = 1 PAR1_DIS = 100 PAR2_DIS = 200 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): quantity = models.IntegerField(label='Order Quantity', min=0) # demand = random.randint(C.PAR1_DIS, C.PAR2_DIS) # payoff = C.PRICE * min(quantity, demand) - C.COST * quantity # PAGES class InputPage(Page): form_model = 'player' form_fields = ['quantity'] # # class ResultsWaitPage(WaitPage): # after_all_players_arrive = set_payoff class Results(Page): # @staticmethod def vars_for_template(player: Player): dem = random.randint(C.PAR1_DIS, C.PAR2_DIS) pro = C.PRICE * min(player.quantity, dem) - C.COST * player.quantity return dict( quantity=player.quantity, demand=dem, profit=pro, ) page_sequence = [InputPage, Results] # cd testproject # otree devserver