from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Max Reuning & Stefano Pomponio' doc = """ In this Treatmentgroup the vintner and the supermarket will negotiate about the wholesale price to which the supermarket can buy the wine at. """ class Constants(BaseConstants): name_in_url = 'my_negotiation' players_per_group = 2 num_rounds = 1 # These variables do not store any value. The templates refer to them. # In case that the roles or the name of the product have to be changed, they do not have to be changed one by one in the templates. good = 'bottles of wine' p1 = 'vintner' p2 = 'supermarket' p3 = 'supermarket 2' ps = 'supermarkets' p = 'supermarket' units = 100 production_cost = c(5) market_price = c(21) payoff_if_rejected = c(10) offer_increment = c(1) instructions_template = 'my_negotiation/Instructions.html' class Subsession(BaseSubsession): # participants keep their role while groups are reshuffled def before_session_starts(self): self.group_randomly(fixed_id_in_group=True) # selecting one round randomly to calculate payoff def creating_session(self): if self.round_number == 1: paying_round = random.randint(1, Constants.num_rounds) #hier gibt einen Unterschied! self.session.vars['paying_round'] = paying_round class Group(BaseGroup): # the offer made by p1 to p2 offer = models.CurrencyField( choices=currency_range(Constants.production_cost, Constants.market_price, Constants.offer_increment), ) # checks if p2 accepted the offer actual_accept = models.BooleanField() def set_payoffs(self): # The player variable "points" is referred to as "revenue" in the experiment. "payoff" sets the real, monetary payoff. p1, p2 = self.get_players() if self.actual_accept: p1.points = (Constants.units * self.offer) - (Constants.units * Constants.production_cost) p2.points = (Constants.market_price * Constants.units) - (Constants.units * self.offer) else: p1.points = Constants.payoff_if_rejected p2.points = Constants.payoff_if_rejected # The monetary payoff is calculated in the randomly selected round. if (self.round_number == 1): p1.payoff = p1.points * 0.02 p2.payoff = p2.points * 0.02 class Player(BasePlayer): points = models.CurrencyField() strategy_accept = models.CurrencyField( choices=currency_range(Constants.production_cost, Constants.market_price, Constants.offer_increment), )