from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import itertools doc = """ This is a game that demonstrates the anchoring effect. """ class Constants(BaseConstants): name_in_url = 'anchoring' players_per_group = None num_rounds = 1 instructions_template = 'anchoring/Instructions.html' class Subsession(BaseSubsession): def creating_session(self): # randomize to treatments colors = itertools.cycle(['blue','red']) for player in self.get_players(): player.color = next(colors) class Group(BaseGroup): #low_player = () #high_player = () average_guess_low = models.FloatField() average_guess_high = models.FloatField() #def set_groups(self): def average_guess(self): high_contributions = 0 num_high_players = 0 low_contributions = 0 num_low_players = 0 for player in self.get_players(): if player.role() == 'High Player': high_contributions += player.guess num_high_players += 1 if player.role() == 'Low Player': low_contributions += player.guess num_low_players += 1 self.average_guess_high = high_contributions / num_high_players self.average_guess_low = low_contributions / num_low_players class Player(BasePlayer): color = models.CharField() guess = models.FloatField( doc=""" Guess by this player. """, min=0, max=1000000 ) average_price = models.BooleanField( doc="Average price of a German car is higher or lower than this value" ) def role(self): if self.color == 'red': return 'High Player' if self.color == 'blue': return 'Low Player'