from otree.api import * import random import json doc = """ Simple trust game """ class Constants(BaseConstants): name_in_url = 'exp' players_per_group = 12 num_rounds = 30 A = 10 # marginal benefit of effort B = 4 # marginal cost of effort: B/2 LA = 0.4 # spillover multiplier K = 3.9 # cost of linking MUTUAL = False NAMES = [] for i in range(players_per_group): NAMES.append('ID'+str(i+1)) CRPAYOFF = 10 EXCHANGE = 150 SHOWUP = 3.5 MAXEFFORT = 20.0 DICTATORBUDGET = 1 * EXCHANGE WAITPAGE_TIMEOUT = 900 FORMATION_TIMEOUT = 60 FEEDBACK_TIMEOUT = 60 class Subsession(BaseSubsession): pass def add_id(src, text, name): if text not in src and text not in name: src += text + ',' return src class Group(BaseGroup): n_round = models.IntegerField(initial=1) def get_res(self): players = self.get_players() for p in players: p.neighbors_temp = p.neighbors for i in range(1, len(players)+1): if getattr(p, 'ID'+str(i)): p.neighbors = add_id(p.neighbors, 'ID'+str(i), p.name) for q in players: if q.name == 'ID'+str(i): q.neighbors = add_id(q.neighbors, p.name, q.name) self.n_round += 1 class Player(BasePlayer): name = models.StringField() friends = models.LongStringField() effort = models.FloatField( label="Please, choose an activity level:", min=0.0, max=Constants.MAXEFFORT, ) neighbors = models.StringField(initial='') neighbors_temp = models.StringField(initial='') neighbors_history = models.StringField(initial='') numneis = models.IntegerField() numneis_cost = models.IntegerField() totalpayoffP1 = models.FloatField() mypayoff = models.FloatField() totalCRpayoff = models.FloatField() payoffCR1 = models.FloatField() payoffCR2 = models.FloatField() payoffCR3 = models.FloatField() CRcorrect = models.IntegerField() finalpayoff = models.FloatField() money1 = models.FloatField() money2 = models.FloatField() dropout = models.BooleanField() socpref = models.IntegerField() nogroup = models.BooleanField() choice = models.StringField() # these field names should be the same as the list of names in the Constants ID1 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID2 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID3 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID4 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID5 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID6 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID7 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID8 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID9 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID10 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID11 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) ID12 = models.BooleanField(widget=widgets.CheckboxInput, blank=True, initial=False) # survey fields keep = models.IntegerField(label='Tick this box if you want to keep link.') gender = models.IntegerField( choices=[ [0, 'Male'], [1, 'Female'], [2, 'Prefer not to say'], ], widget=widgets.RadioSelect ) age = models.IntegerField( min=0, max=100 ) prolific = models.StringField() nationality = models.StringField() highesteduc = models.IntegerField( choices=[ [0, 'Primary school'], [1, 'Middle school'], [2, 'High school'], [3, 'Vocational school'], [4, 'Bachelor degree'], [5, 'Master degree'], [6, 'PhD degree'], ], widget=widgets.RadioSelect ) student = models.IntegerField( choices=[ [0, 'No'], [1, 'Yes'], ], widget=widgets.RadioSelect ) work = models.IntegerField( choices=[ [0, 'No'], [1, 'Yes, part time'], [2, 'Yes, full time'], ], widget=widgets.RadioSelect ) feedback = models.LongStringField() cogreflection1 = models.FloatField( min=0 ) cogreflection2 = models.IntegerField( min=0 ) cogreflection3 = models.IntegerField( min=0 ) riskaversion1 = models.IntegerField( min=0, max=100, ) invest = models.IntegerField() payoff3 = models.FloatField() def drop(self): # if not self.keep: # self.neighbors = self.neighbors_temp self.neighbors = '' # self.ID1 = None # self.ID2 = None # self.ID3 = None # self.ID4 = None # self.ID5 = None