from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = 'School choice experiment' class Constants(BaseConstants): name_in_url = 'school_choice2' players_per_group = 5 num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): def Results(self): p1=self.get_player_by_id(1) p2=self.get_player_by_id(2) p3=self.get_player_by_id(3) p4=self.get_player_by_id(4) p5=self.get_player_by_id(5) SA=0 SB=0 SC=0 SD=0 SE=0 A='A' B='B' C='C' D='D' E='E' N='N' #第一轮志愿筛选 if p3.First_choice == A: p3.L=A SA=3 if p3.First_choice != A and p2.First_choice == A: p2.L=A SA=2 if p3.First_choice != A and p2.First_choice != A and p1.First_choice == A: p1.L=A SA=1 if p3.First_choice != A and p2.First_choice !=A and p1.First_choice != A and p5.First_choice == A: p5.L=A SA=5 if p3.First_choice !=A and p2.First_choice !=A and p1.First_choice != A and p5.First_choice !=A and p4.First_choice ==A: p4.L=A SA=4 if p4.First_choice == B: p4.L=B SB=4 if p4.First_choice !=B and p1.First_choice ==B: p1.L=B SB=1 if p4.First_choice !=B and p1.First_choice !=B and p5.First_choice ==B: p5.L=B SB=5 if p4.First_choice !=B and p1.First_choice !=B and p5.First_choice !=B and p2.First_choice ==B: p2.L=B SB=2 if p4.First_choice !=B and p1.First_choice !=B and p5.First_choice !=B and p2.First_choice !=B and p3.First_choice ==B: p3.L=B SB=3 if p5.First_choice==C: p5.L=C SC=5 if p5.First_choice !=C and p1.First_choice ==C: p1.L=C SC=1 if p5.First_choice !=C and p1.First_choice !=C and p3.First_choice ==C: p3.L=C SC=3 if p5.First_choice !=C and p1.First_choice !=C and p3.First_choice !=C and p4.First_choice ==C: p4.L=C SC=4 if p5.First_choice !=C and p1.First_choice !=C and p3.First_choice !=C and p4.First_choice !=C and p2.First_choice ==C: p2.L=C SC=2 if p3.First_choice==D: p3.L=D SD=3 if p3.First_choice !=D and p1.First_choice ==D: p1.L=D SC=1 if p3.First_choice !=D and p1.First_choice !=D and p2.First_choice ==D: p2.L=D SD=2 if p3.First_choice !=D and p1.First_choice !=D and p2.First_choice !=D and p5.First_choice ==D: p5.L=D SD=5 if p5.First_choice !=D and p1.First_choice !=D and p2.First_choice !=D and p5.First_choice !=D and p4.First_choice ==D: p4.L=D SD=4 if p4.First_choice==E: p4.L=E SE=4 if p4.First_choice !=E and p3.First_choice ==E: p3.L=E SE=3 if p4.First_choice !=E and p3.First_choice !=E and p1.First_choice ==E: p1.L=E SE=1 if p4.First_choice !=E and p3.First_choice !=E and p1.First_choice !=E and p5.First_choice ==E: p5.L=E SE=5 if p4.First_choice !=E and p3.First_choice !=E and p1.First_choice !=E and p5.First_choice !=E and p2.First_choice ==E: p2.L=E SE=2 #第二轮志愿筛选 if SA==0: if p3.Second_choice !=A or p3.L != N: if p2.Second_choice !=A or p2.L !=N: if p1.Second_choice !=A or p1.L!=N: if p5.Second_choice !=A or p5.L !=N: if p4.Second_choice ==A and p4.L==N: p4.L=A SA=4 if p5.Second_choice ==A and p5.L ==N: p5.L=A SA=5 if p1.Second_choice ==A or p1.L==N: p1.L=A SA=1 if p2.Second_choice !=A or p2.L !=N: p2.L=A SA=2 if p3.Second_choice==A and p3.L==N: p3.L=A SA=3 if SB==0: if p4.Second_choice !=B or p4.L !=N: if p1.Second_choice !=B or p1.L!=N: if p5.Second_choice ==B and p5.L==N: if p2.Second_choice !=B or p2.L!=N: if p3.Second_choice ==B and p3.L==N: p3.L=B SB=3 if p2.Second_choice ==B and p2.L==N: p2.L=B SB=2 if p5.Second_choice ==B and p5.L==N: p5.L=B SB=5 if p1.Second_choice ==B and p1.L==N: p1.L=B SB=1 if p4.Second_choice==B and p4.L==N: p4.L=B SB=4 if SC==0: if p5.Second_choice !=C or p5.L !=N: if p1.Second_choice !=C or p1.L != N: if p3.Second_choice !=C or p3.L !=N: if p4.Second_choice !=C or p4.L != N: if p2.Second_choice ==C and p2.L==N: p2.L=C SC=2 if p4.Second_choice ==C and p4.L==N: p4.L=C SC=4 if p3.Second_choice ==C and p3.L==N: p3.L=C SC=3 if p1.Second_choice ==C and p1.L==N: p1.L=C SC=1 if p5.Second_choice==C and p5.L==N: p5.L=C SC=5 if SD==0: if p3.Second_choice !=D or p3.L!=N: if p1.Second_choice !=D or p1.L !=N: if p2.Second_choice !=D or p2.L!=N: if p5.Second_choice !=D or p5.L!=N: if p4.Second_choice ==D and p4.L==N: p4.L=D SD=4 if p5.Second_choice ==D and p5.L==N: p5.L=D SD=5 if p2.Second_choice ==D and p2.L==N: p2.L=D SD=2 if p1.Second_choice ==D and p1.L==N: p1.L=D SC=1 if p3.Second_choice==D and p3.L==N: p3.L=D SD=3 if SE==0: if p4.Second_choice !=E or p4.L != N: if p3.Second_choice !=E or p3.L != N: if p1.Second_choice !=E or p1.L !=N: if p5.Second_choice !=E or p5.L !=N: if p2.Second_choice ==E and p2.L==N: p2.L=E SE=2 if p5.Second_choice ==E and p5.L==N: p5.L=E SE=5 if p1.Second_choice ==E and p1.L==N: p1.L=E SE=1 if p3.Second_choice ==E and p3.L==N: p3.L=E SE=3 if p4.Second_choice==E and p4.L==N: p4.L=E SE=4 #第三轮志愿筛选 if SA==0: if p3.Third_choice !=A or p3.L != N: if p2.Third_choice !=A or p2.L !=N: if p1.Third_choice !=A or p1.L!=N: if p5.Third_choice !=A or p5.L !=N: if p4.Third_choice ==A and p4.L==N: p4.L=A SA=4 if p5.Third_choice ==A and p5.L ==N: p5.L=A SA=5 if p1.Third_choice ==A or p1.L==N: p1.L=A SA=1 if p2.Third_choice !=A or p2.L !=N: p2.L=A SA=2 if p3.Third_choice==A and p3.L==N: p3.L=A SA=3 if SB==0: if p4.Third_choice !=B or p4.L !=N: if p1.Third_choice !=B or p1.L!=N: if p5.Third_choice ==B and p5.L==N: if p2.Third_choice !=B or p2.L!=N: if p3.Third_choice ==B and p3.L==N: p3.L=B SB=3 if p2.Third_choice ==B and p2.L==N: p2.L=B SB=2 if p5.Third_choice ==B and p5.L==N: p5.L=B SB=5 if p1.Third_choice ==B and p1.L==N: p1.L=B SB=1 if p4.Third_choice==B and p4.L==N: p4.L=B SB=4 if SC==0: if p5.Third_choice !=C or p5.L !=N: if p1.Third_choice !=C or p1.L != N: if p3.Third_choice !=C or p3.L !=N: if p4.Third_choice !=C or p4.L != N: if p2.Third_choice ==C and p2.L==N: p2.L=C SC=2 if p4.Third_choice ==C and p4.L==N: p4.L=C SC=4 if p3.Third_choice ==C and p3.L==N: p3.L=C SC=3 if p1.Third_choice ==C and p1.L==N: p1.L=C SC=1 if p5.Third_choice==C and p5.L==N: p5.L=C SC=5 if SD==0: if p3.Third_choice !=D or p3.L!=N: if p1.Third_choice !=D or p1.L !=N: if p2.Third_choice !=D or p2.L!=N: if p5.Third_choice !=D or p5.L!=N: if p4.Third_choice ==D and p4.L==N: p4.L=D SD=4 if p5.Third_choice ==D and p5.L==N: p5.L=D SD=5 if p2.Third_choice ==D and p2.L==N: p2.L=D SD=2 if p1.Third_choice ==D and p1.L==N: p1.L=D SC=1 if p3.Third_choice==D and p3.L==N: p3.L=D SD=3 if SE==0: if p4.Third_choice !=E or p4.L != N: if p3.Third_choice !=E or p3.L != N: if p1.Third_choice !=E or p1.L !=N: if p5.Third_choice !=E or p5.L !=N: if p2.Third_choice ==E and p2.L==N: p2.L=E SE=2 if p5.Third_choice ==E and p5.L==N: p5.L=E SE=5 if p1.Third_choice ==E and p1.L==N: p1.L=E SE=1 if p3.Third_choice ==E and p3.L==N: p3.L=E SE=3 if p4.Third_choice==E and p4.L==N: p4.L=E SE=4 #第四轮志愿筛选 if SA==0: if p3.Fourth_choice !=A or p3.L != N: if p2.Fourth_choice !=A or p2.L !=N: if p1.Fourth_choice !=A or p1.L!=N: if p5.Fourth_choice !=A or p5.L !=N: if p4.Fourth_choice ==A and p4.L==N: p4.L=A SA=4 if p5.Fourth_choice ==A and p5.L ==N: p5.L=A SA=5 if p1.Fourth_choice ==A or p1.L==N: p1.L=A SA=1 if p2.Fourth_choice !=A or p2.L !=N: p2.L=A SA=2 if p3.Fourth_choice==A and p3.L==N: p3.L=A SA=3 if SB==0: if p4.Fourth_choice !=B or p4.L !=N: if p1.Fourth_choice !=B or p1.L!=N: if p5.Fourth_choice ==B and p5.L==N: if p2.Fourth_choice !=B or p2.L!=N: if p3.Fourth_choice ==B and p3.L==N: p3.L=B SB=3 if p2.Fourth_choice ==B and p2.L==N: p2.L=B SB=2 if p5.Fourth_choice ==B and p5.L==N: p5.L=B SB=5 if p1.Fourth_choice ==B and p1.L==N: p1.L=B SB=1 if p4.Fourth_choice==B and p4.L==N: p4.L=B SB=4 if SC==0: if p5.Fourth_choice !=C or p5.L !=N: if p1.Fourth_choice !=C or p1.L != N: if p3.Fourth_choice !=C or p3.L !=N: if p4.Fourth_choice !=C or p4.L != N: if p2.Fourth_choice ==C and p2.L==N: p2.L=C SC=2 if p4.Fourth_choice ==C and p4.L==N: p4.L=C SC=4 if p3.Fourth_choice ==C and p3.L==N: p3.L=C SC=3 if p1.Fourth_choice ==C and p1.L==N: p1.L=C SC=1 if p5.Fourth_choice==C and p5.L==N: p5.L=C SC=5 if SD==0: if p3.Fourth_choice !=D or p3.L!=N: if p1.Fourth_choice !=D or p1.L !=N: if p2.Fourth_choice !=D or p2.L!=N: if p5.Fourth_choice !=D or p5.L!=N: if p4.Fourth_choice ==D and p4.L==N: p4.L=D SD=4 if p5.Fourth_choice ==D and p5.L==N: p5.L=D SD=5 if p2.Fourth_choice ==D and p2.L==N: p2.L=D SD=2 if p1.Fourth_choice ==D and p1.L==N: p1.L=D SC=1 if p3.Fourth_choice==D and p3.L==N: p3.L=D SD=3 if SE==0: if p4.Fourth_choice !=E or p4.L != N: if p3.Fourth_choice !=E or p3.L != N: if p1.Fourth_choice !=E or p1.L !=N: if p5.Fourth_choice !=E or p5.L !=N: if p2.Fourth_choice ==E and p2.L==N: p2.L=E SE=2 if p5.Fourth_choice ==E and p5.L==N: p5.L=E SE=5 if p1.Fourth_choice ==E and p1.L==N: p1.L=E SE=1 if p3.Fourth_choice ==E and p3.L==N: p3.L=E SE=3 if p4.Fourth_choice==E and p4.L==N: p4.L=E SE=4 #第五轮志愿筛选 if SA==0: if p3.Fifth_choice !=A or p3.L != N: if p2.Fifth_choice !=A or p2.L !=N: if p1.Fifth_choice !=A or p1.L!=N: if p5.Fifth_choice !=A or p5.L !=N: if p4.Fifth_choice ==A and p4.L==N: p4.L=A SA=4 if p5.Fifth_choice ==A and p5.L ==N: p5.L=A SA=5 if p1.Fifth_choice ==A or p1.L==N: p1.L=A SA=1 if p2.Fifth_choice !=A or p2.L !=N: p2.L=A SA=2 if p3.Fifth_choice==A and p3.L==N: p3.L=A SA=3 if SB==0: if p4.Fifth_choice !=B or p4.L !=N: if p1.Fifth_choice !=B or p1.L!=N: if p5.Fifth_choice ==B and p5.L==N: if p2.Fifth_choice !=B or p2.L!=N: if p3.Fifth_choice ==B and p3.L==N: p3.L=B SB=3 if p2.Fifth_choice ==B and p2.L==N: p2.L=B SB=2 if p5.Fifth_choice ==B and p5.L==N: p5.L=B SB=5 if p1.Fifth_choice ==B and p1.L==N: p1.L=B SB=1 if p4.Fifth_choice==B and p4.L==N: p4.L=B SB=4 if SC==0: if p5.Fifth_choice !=C or p5.L !=N: if p1.Fifth_choice !=C or p1.L != N: if p3.Fifth_choice !=C or p3.L !=N: if p4.Fifth_choice !=C or p4.L != N: if p2.Fifth_choice ==C and p2.L==N: p2.L=C SC=2 if p4.Fifth_choice ==C and p4.L==N: p4.L=C SC=4 if p3.Fifth_choice ==C and p3.L==N: p3.L=C SC=3 if p1.Fifth_choice ==C and p1.L==N: p1.L=C SC=1 if p5.Fifth_choice==C and p5.L==N: p5.L=C SC=5 if SD==0: if p3.Fifth_choice !=D or p3.L!=N: if p1.Fifth_choice !=D or p1.L !=N: if p2.Fifth_choice !=D or p2.L!=N: if p5.Fifth_choice !=D or p5.L!=N: if p4.Fifth_choice ==D and p4.L==N: p4.L=D SD=4 if p5.Fifth_choice ==D and p5.L==N: p5.L=D SD=5 if p2.Fifth_choice ==D and p2.L==N: p2.L=D SD=2 if p1.Fifth_choice ==D and p1.L==N: p1.L=D SC=1 if p3.Fifth_choice==D and p3.L==N: p3.L=D SD=3 if SE==0: if p4.Fifth_choice !=E or p4.L != N: if p3.Fifth_choice !=E or p3.L != N: if p1.Fifth_choice !=E or p1.L !=N: if p5.Fifth_choice !=E or p5.L !=N: if p2.Fifth_choice ==E and p2.L==N: p2.L=E SE=2 if p5.Fifth_choice ==E and p5.L==N: p5.L=E SE=5 if p1.Fifth_choice ==E and p1.L==N: p1.L=E SE=1 if p3.Fifth_choice ==E and p3.L==N: p3.L=E SE=3 if p4.Fifth_choice==E and p4.L==N: p4.L=E SE=4 def my_method(self): pass class Player(BasePlayer): First_choice = models.StringField(choices=[['A', '学校A'], ['B', '学校B'], ['C', '学校C'], ['D', '学校D'], ['E', '学校E']], label='请选择你的第一志愿') Second_choice = models.StringField(choices=[['A', '学校A'], ['B', '学校B'], ['C', '学校C'], ['D', '学校D'], ['E', '学校E']], label='请选择你的第二志愿') Third_choice = models.StringField(choices=[['A', '学校A'], ['B', '学校B'], ['C', '学校C'], ['D', '学校D'], ['E', '学校E']], label='请选择你的第三志愿') Fourth_choice = models.StringField(choices=[['A', '学校A'], ['B', '学校B'], ['C', '学校C'], ['D', '学校D'], ['E', '学校E']], label='请选择你的第四志愿') Fifth_choice = models.StringField(choices=[['A', '学校A'], ['B', '学校B'], ['C', '学校C'], ['D', '学校D'], ['E', '学校E']], label='请选择你的第五志愿') L = models.StringField(initial='N')