from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '' class Constants(BaseConstants): name_in_url = 'NewsVendorFI' players_per_group = None num_rounds = 30 mean = 100 sd = 50 price = 12 costhigh = 9 salvage = 0 costlow = 3 truncLower = 0 truncHigher = 200 breakRound = 15 indextemplate_template = 'NewsVendorFI/indextemplate.html' class Subsession(BaseSubsession): Demand = models.IntegerField(initial=0) fractile = models.FloatField() optimalOrder = models.IntegerField(initial=0) def DemandInRound(self): pass def CalculateOptimal(self): from scipy.stats import truncnorm if self.round_number == 1: self.fractile = (Constants.price-Constants.costhigh)/(Constants.price-Constants.salvage); self.optimalOrder = int(Constants.mean + Constants.sd*truncnorm.ppf(self.fractile,(Constants.truncLower - Constants.mean) / Constants.sd, (Constants.truncHigher - Constants.mean) / Constants.sd)) else: self.fractile = self.in_round(1).fractile; self.optimalOrder = self.in_round(1).optimalOrder; class Group(BaseGroup): pass class Player(BasePlayer): name = models.StringField(label='Your name:') OrderQty = models.IntegerField(label='Your order for the round:') roundDemand = models.IntegerField(initial=0) profit = models.FloatField(initial=0) cumulativeProfit = models.FloatField(initial=0) optimalCumulativeProfitInRound = models.FloatField(initial=0) rImprove = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], initial='Yes', label='Do you think you could improve your cumulative profit if you change your strategy of ordering?', widget=widgets.RadioSelect) rStrategy = models.LongStringField(choices=[["Ordering close to the previous round's demand", "Ordering close to the previous round's demand"], ['Ordering close to the mean demand', 'Ordering close to the mean demand'], ['Ordering close to the optimal value', 'Ordering close to the optimal value'], ['Ordering between mean demand and optimal value', 'Ordering between mean demand and optimal value'], ['None of these', 'None of these']], label='In your opinion, what pattern of ordering did you follow in the last 10 rounds?', widget=widgets.RadioSelect) rForecast = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Were you trying to guess the demand while placing the order?', widget=widgets.RadioSelect) rFutureStrategy = models.StringField(choices=[['Try to guess the demand at every round', 'Try to guess the demand at every round'], ['Place the optimal order every round', 'Place the optimal order every round'], ['Place order quantity around mean demand every round', 'Place order quantity around mean demand every round'], ['Follow the last round demand', 'Follow the last round demand'], ['No strategy', 'No strategy']], label='What do you (now) think is the best strategy over the next 20 rounds?', widget=widgets.RadioSelect) treatment = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3']], initial=1, label='Group', widget=widgets.RadioSelectHorizontal) optimalProfit = models.FloatField(initial=0) optimalCumulativeProfit = models.FloatField(initial=0) rChasingMean = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label="Did you often revert to ordering close to the mean demand (100) whenever you noticed the previous round's demand exceeded 100?", widget=widgets.RadioSelect)