from otree.api import * import itertools import random #Cuando no estan balanceados los grupos... doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'trust_tutorial' players_per_group = 2 num_rounds = 1 endowment = cu(10) multiplication_factor = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): #Treatments! (en este caso, para que tengan diferentes multiplication factors) ADD: El value se lo damos en las functions multiplication_factor = models.IntegerField() sent_amount = models.CurrencyField( label="How much do you want to send to participant B?", min=cu(0), max=Constants.endowment ) sent_back_amount = models.CurrencyField( label="How much do you want to send back?" ) #its more easy to send infrmation betw when is in the roup level rather than in the player level." \ #Apropiate when just 1 player needs to do something and the other nothing" class Player(BasePlayer): pass ##################### ##### Functions ##### ##################### #Functions se definen entre la player y pages class. " #Function: Dynamic func foundation" #Treatment: # balance treatments: primer grupo toma valor 3. Segundo valor 4. cuarto valor 3.... def creating_session(subsession): treatment = itertools.cycle([3, 4]) for group in subsession.get_groups(): group.multiplication_factor = next(treatment) def sent_back_amount_choices(group): return currency_range( cu(0.5), group.sent_amount * Constants.multiplication_factor, cu(1) ) def set_payoffs(group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff = Constants.endowment - group.sent_amount + group.sent_back_amount p2.payoff = group.sent_amount * group.multiplication_factor - group.sent_back_amount #################### ###### PAGES ###### #################### #Defino lo que se le va a presentar al player 1" class Send(Page): form_model = 'group' form_fields = ['sent_amount'] #Esta funcion solo se hace EN LA CLASE, en este caso, para player 1" @staticmethod def is_displayed(player): return player.id_in_group == 1 #HAce que todos esperen" class WaitForP1(WaitPage): pass #"Form model:here i specify the variables that are elicity here" class SendBack(Page): form_model = 'group' form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player): return player.id_in_group == 2 #To define some temporary variables:" @staticmethod def vars_for_template(player): group = player.group return dict( tripled_amount=group.sent_amount * Constants.multiplication_factor ) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): pass page_sequence = [Send, WaitForP1, SendBack, ResultsWaitPage, Results]