from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from public_goods.Src.Customer import Customer from public_goods.Src.Distributor import Distributor from public_goods.Src.Factory import Factory from public_goods.Src.Retailer import Retailer from public_goods.Src.SupplyChainActor import SupplyChainActor from public_goods.Src.SupplyChainQueue import SupplyChainQueue from public_goods.Src.Wholesaler import Wholesaler from public_goods.Src.Main import * import random doc = """ This is a one-period public goods game with 3 players. """ class Constants(BaseConstants): name_in_url = 'public_goods' players_per_group = 4 num_rounds = 25 instructions_template = 'public_goods/Instructions.html' # """Amount allocated to each player""" STORAGE_COST_PER_UNIT = 0.5 BACKORDER_PENALTY_COST_PER_UNIT = 1 # We can play the full game since no actor is programmed to dump stock near end of game ##WEEKS_TO_PLAY = 36 QUEUE_DELAY_WEEKS = 2 INITIAL_STOCK = 12 INITIAL_COST = 0 INITIAL_CURRENT_ORDERS = 0 CUSTOMER_INITIAL_ORDERS = 4 CUSTOMER_SUBSEQUENT_ORDERS = 8 TARGET_STOCK = 12 MAX_PLACED_ORDER=1000 class Subsession(BaseSubsession): def vars_for_admin_report(self): contributions = [p.contribution for p in self.get_players() if p.contribution != None] if contributions: return { 'avg_contribution': sum(contributions)/len(contributions), 'min_contribution': min(contributions), 'max_contribution': max(contributions), } else: return { 'avg_contribution': '(no data)', 'min_contribution': '(no data)', 'max_contribution': '(no data)', } class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) self.individual_share = self.total_contribution * Constants.multiplier / Constants.players_per_group for p in self.get_players(): p.payoff = (Constants.endowment - p.contribution) + self.individual_share class Player(BasePlayer): placed_order = models.int(min=0, max = Constants.MAX_PLACED_ORDER, label ="How much will you order?") incoming_order = models.IntegerField() received_shipment = models.IntegerField() inventory_level = models.IntegerField() order_on_hand = models.IntegerField() currentCost = models.IntegerField() def calcStateVariables(self): self.incoming_order=5 self.received_shipment=5 self.inventory_level=12 self.currentCost=0 self.order_on_hand=5 def role(self): if self.id_in_group == 1: return 'Retailer' if self.id_in_group == 2: return 'Wholesaler' if self.id_in_group == 3: return 'Distributor' if self.id_in_group == 4: return 'Factory'