from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class intro(Page): pass class social_pref(Page): form_model = 'player' form_fields = ['sp_1', 'sp_2', 'sp_3', 'sp_4', 'sp_5', 'sp_6', 'sp_7', 'sp_8', 'sp_9', 'sp_10'] class SpPayoffWaitpage(WaitPage): wait_for_all_groups = True def after_all_players_arrive(self): #subsession = self.subsession #players = subsession.get_players() #scores = [p.score for p in players] #subsession.sum_score = sum(scores) for p in self.subsession.get_players(): if p.id_in_group == 1: p.group.pay_sp = 0 p.group.pay_other_sp = 0 p.group.rand_sp = random.randint(1, 10) p.group.p3 = "sp_" + str(p.group.rand_sp) if getattr(p, p.group.p3) == 0: if p.group.p3 == "sp_1": p.group.pay_sp += 1.6 p.group.pay_other_sp += 2.6 if p.group.p3 == "sp_2": p.group.pay_sp += 1.8 p.group.pay_other_sp += 2.6 if p.group.p3 == "sp_3": p.group.pay_sp += 2 p.group.pay_other_sp += 2.6 if p.group.p3 == "sp_4": p.group.pay_sp += 2.2 p.group.pay_other_sp += 2.6 if p.group.p3 == "sp_5": p.group.pay_sp += 2.4 p.group.pay_other_sp += 2.6 if p.group.p3 == "sp_6": p.group.pay_sp += 1.6 p.group.pay_other_sp += 1.4 if p.group.p3 == "sp_7": p.group.pay_sp += 1.8 p.group.pay_other_sp += 1.4 if p.group.p3 == "sp_8": p.group.pay_sp += 2 p.group.pay_other_sp += 1.4 if p.group.p3 == "sp_9": p.group.pay_sp += 2.2 p.group.pay_other_sp += 1.4 if p.group.p3 == "sp_10": p.group.pay_sp += 2.4 p.group.pay_other_sp += 1.4 if getattr(p, p.group.p3) == 1: p.group.pay_other_sp += 2 p.group.pay_sp += 2 if p.id_in_group == 1: p.pay_sp = p.group.pay_sp p.participant.vars['sp_lead'] = 1 else: p.pay_sp = p.group.pay_other_sp p.participant.vars['sp_lead'] = 0 p.participant.vars['pay_sp'] = p.pay_sp page_sequence = [ intro, social_pref, SpPayoffWaitpage, ]