from otree.api import * doc = """ group treatment: """ class C(BaseConstants): NAME_IN_URL = 'Group_ABC' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 1 # initial amount allocated to the dictator (typeA) ENDOWMENT_A = cu(10) # initial amount allocated to the third party (typeC) ENDOWMENT_C = cu(5) PUNISHMENT_CHOICES = [ [0, 'A kişisinin kendine ayırdığı puanları düşürmek istemiyorum.'], [3, 'Kendi puanlarımdan 1 puan harcayarak A kişisinin kendine ayırdığı puanlardan 3 puan düşürmek istiyorum.'], [6, 'Kendi puanlarımdan 2 puan harcayarak A kişisinin kendine ayırdığı puanlardan 6 puan düşürmek istiyorum.'], ] BELIEF_CHOICES = [ [0, 'A kişisinin kendine ayırdığı puanları düşürmez.'], [3, 'Kendisinden 1 puan harcayarak A kişisinin 3 puanını düşürür.'], [6, 'Kendisinden 2 puan harcayarak A kişisinin 6 puanını düşürür.'], ] QUESTION_CHOICES_A = [ dict(name='multi1', label="B kişisinin benimle aynı gruptan olması"), dict(name='multi2', label="C kişisinin benimle aynı gruptan olması"), dict(name='multi3', label="B ve C kişilerinin hangi gruptan olduklarından bağımsız olarak aktarım " "kararını aldım"), ] QUESTION_CHOICES_B = [ dict(name='multi1', label="A kişisinin benimle aynı gruptan olması"), dict(name='multi2', label="C kişisinin benimle aynı gruptan olması"), dict(name='multi3', label="A kişisinin puan aktarımının ben ve C kişisinin hangi gruptan olduğundan bağımsız " "olacağını düşündüm"), ] QUESTION_CHOICES_C = [ dict(name='multi1', label="A kişisinin benimle aynı gruptan olması"), dict(name='multi2', label="B kişisinin benimle aynı gruptan olması"), dict(name='multi3', label="A ve B kişilerinin hangi gruptan olduğundan bağımsız olarak karar aldım"), ] INSTRUCTION_TEMPLATE = 'Group_ABC/instructions_abc.html' INSTRUCTION_TEMPLATE_2 = 'Group_ABC/instructions_abc_2.html' INSTRUCTION_TEMPLATE_3 = 'Group_ABC/instructions_abc_3.html' INSTRUCTION_TEMPLATE_4 = 'Group_ABC/instructions_abc_4.html' INSTRUCTION_TEMPLATE_5 = 'Group_ABC/instructions_abc_5.html' INSTRUCTION_TEMPLATE_6 = 'Group_ABC/instructions_abc_6.html' INSTRUCTION_SUMMARY_TEMPLATE = 'Group_ABC/instructions_abc_summary.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): transfer = models.CurrencyField( doc="""A tipi oyuncunun yapmak istediği transfer seviyesi""", choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], max=C.ENDOWMENT_A, label="", ) punishment_0 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_1 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_2 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_3 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_4 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_5 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_6 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_7 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_8 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_9 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment_10 = models.CurrencyField( doc="""C tipi oyuncunun ceza kararı""", widget=widgets.RadioSelect, choices=C.PUNISHMENT_CHOICES, label="", ) punishment = models.CurrencyField() punishment_cost = models.CurrencyField() belief_0A = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_5A = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_10A = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_0B = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_5B = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_10B = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_0C = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_5C = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) belief_10C = models.CurrencyField( label="", widget=widgets.RadioSelect, choices=C.BELIEF_CHOICES, ) # B için ne yazıcaz? belief_transfer_B = models.CurrencyField( choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label="", ) class Player(BasePlayer): # anlama soruları multi1 = models.BooleanField(blank=True) multi2 = models.BooleanField(blank=True) multi3 = models.BooleanField(blank=True) # multi1B = models.BooleanField(blank=True) # multi2B = models.BooleanField(blank=True) # multi3B = models.BooleanField(blank=True) payment = models.CurrencyField() with_showup = models.CurrencyField() # FUNCTIONS def punishment_decision(group: Group): if group.transfer == 0: group.punishment = group.punishment_0 elif group.transfer == 1: group.punishment = group.punishment_1 elif group.transfer == 2: group.punishment = group.punishment_2 elif group.transfer == 3: group.punishment = group.punishment_3 elif group.transfer == 4: group.punishment = group.punishment_4 elif group.transfer == 5: group.punishment = group.punishment_5 elif group.transfer == 6: group.punishment = group.punishment_6 elif group.transfer == 7: group.punishment = group.punishment_7 elif group.transfer == 8: group.punishment = group.punishment_8 elif group.transfer == 9: group.punishment = group.punishment_9 else: group.punishment = group.punishment_10 group.punishment_cost = group.punishment / 3 #def punishment_cost(group): # group.punishment_cost = group.punishment / 3 def set_payoffs(group): #group = player.group players = group.get_players() for p in players: if p.id_in_group == 1: p.payoff = C.ENDOWMENT_A - group.transfer - group.punishment elif p.id_in_group == 2: p.payoff = group.transfer else: p.payoff = C.ENDOWMENT_C - group.punishment_cost # set payoff as global variable p.participant.vars['payoff'] = p.payoff def set_with_showup(group): players = group.get_players() for p in players: with_showup = p.participant.payoff + 3 p.with_showup = float(with_showup) print("with showup", with_showup) def set_payment(group): players = group.get_players() for p in players: payment = p.participant.payoff_plus_participation_fee() p.payment = float(payment) print("payment", payment) # PAGES class Intro_abc(Page): pass class Intro_abc_2(Page): pass class Intro_abc_3(Page): pass class Intro_abc_4(Page): pass class Intro_abc_5(Page): pass class Intro_abc_6(Page): pass class Wait_for_others(WaitPage): wait_for_all_groups = True #class Group_info(Page): # pass #class Player_info(Page): # pass class Round_1(Page): form_model = 'group' form_fields = ['transfer', 'belief_transfer_B', 'punishment_0', 'punishment_1', 'punishment_2', 'punishment_3', 'punishment_4', 'punishment_5', 'punishment_6', 'punishment_7', 'punishment_8', 'punishment_9', 'punishment_10'] @staticmethod def get_form_fields(player): if player.id_in_group == 1: return ['transfer'] elif player.id_in_group == 2: return ['belief_transfer_B'] else: return ['punishment_0', 'punishment_1', 'punishment_2', 'punishment_3', 'punishment_4', 'punishment_5', 'punishment_6', 'punishment_7', 'punishment_8', 'punishment_9', 'punishment_10'] class Belief_elicit_0(Page): form_model = 'group' form_fields = ['belief_0A', 'belief_0B', 'belief_0C'] @staticmethod def get_form_fields(player): if player.id_in_group == 1: return ['belief_0A'] elif player.id_in_group == 2: return ['belief_0B'] else: return ['belief_0C'] class Belief_elicit_5(Page): form_model = 'group' form_fields = ['belief_5A', 'belief_5B', 'belief_5C'] @staticmethod def get_form_fields(player): if player.id_in_group == 1: return ['belief_5A'] elif player.id_in_group == 2: return ['belief_5B'] else: return ['belief_5C'] class Belief_elicit_10(Page): form_model = 'group' form_fields = ['belief_10A', 'belief_10B', 'belief_10C'] @staticmethod def get_form_fields(player): if player.id_in_group == 1: return ['belief_10A'] elif player.id_in_group == 2: return ['belief_10B'] else: return ['belief_10C'] class Questions_abc(Page): form_model = 'player' @staticmethod def get_form_fields(player: Player): if player.id_in_group == 1: return [multi['name'] for multi in C.QUESTION_CHOICES_A] elif player.id_in_group == 2: return [multi['name'] for multi in C.QUESTION_CHOICES_B] else: return [multi['name'] for multi in C.QUESTION_CHOICES_C] @staticmethod def error_message(player: Player, values): # print('values is', values) num_selected = 0 for multi in C.QUESTION_CHOICES_A and C.QUESTION_CHOICES_B and C.QUESTION_CHOICES_C: if values[multi['name']]: num_selected += 1 if num_selected < 1: return "Lütfen en az bir seçim yapınız." class ResultsWaitPage(WaitPage): after_all_players_arrive = 'punishment_decision' #class ResultsWaitPage2(WaitPage): # after_all_players_arrive = 'punishment_cost' class ResultsWaitPage2(WaitPage): after_all_players_arrive = 'set_payoffs' class ResultsWaitPage3(WaitPage): after_all_players_arrive = 'set_with_showup' class Results_abc(Page): @staticmethod def vars_for_template(player: Player): group = player.group amount_kept = C.ENDOWMENT_A - group.transfer punishment_cost = group.punishment / 3 return dict(amount_kept=amount_kept, punishment_cost=punishment_cost) class EarningsWaitPage(WaitPage): after_all_players_arrive = set_payment page_sequence = [Intro_abc, Intro_abc_2, Intro_abc_3, Intro_abc_4, Intro_abc_5, Intro_abc_6, Wait_for_others, Round_1, Belief_elicit_0, Belief_elicit_5, Belief_elicit_10, Questions_abc, ResultsWaitPage, ResultsWaitPage2, ResultsWaitPage3, Results_abc, EarningsWaitPage]