from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'my_trust' players_per_group = 2 num_rounds = 3 endowment = cu(10) class Subsession(BaseSubsession): pass class Group(BaseGroup): multiplication_factor = models.IntegerField() round_incentivized = models.IntegerField() sent_amount = models.CurrencyField( label="How much do you want to send to Participant B?", min=0, max=Constants.endowment ) sent_back_amount = models.CurrencyField( label="How much do you want to send back?" ) message = models.LongStringField( label="Message you want to send to other Participant", blank=True ) pass def creating_session(subsession): import random for group in subsession.get_groups(): group.multiplication_factor = random.choice([3, 6]) group.round_incentivized = random.choice([1, 2, 3]) print('set multiplication_factor to', group.multiplication_factor) print('set round_incentivized to', group.round_incentivized) def sent_back_amount_choices(group): return currency_range( 0, group.sent_amount * group.multiplication_factor, 1 ) class Player(BasePlayer): final_payoff = models.IntegerField() pass # PAGES class Send(Page): form_model = 'group' form_fields = ['sent_amount', 'message'] @staticmethod def is_displayed(player): return player.id_in_group == 1 class SendBack(Page): form_model = 'group' form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player): return player.id_in_group == 2 @staticmethod def vars_for_template(player): group = player.group return dict( tripled_amount=group.sent_amount * group.multiplication_factor ) class WaitForP1(WaitPage): pass 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 class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs def set_final_payoffs(group): for player in subsession.get_players(): prev_player = player.in_round(group.round_incentivized) player.final_payoff = prev_player.payoff class FinalResultsWaitPage(WaitPage): after_all_players_arrive = set_final_payoffs class PaymentPage(Page): pass class Results(Page): pass page_sequence = [ Send, WaitForP1, SendBack, ResultsWaitPage, Results, PaymentPage ]