from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from random import choice import random from random import randint doc = """ 2 firms complete in a market by setting prices for homogenous goods. See "Kruse, J. B., Rassenti, S., Reynolds, S. S., & Smith, V. L. (1994). Bertrand-Edgeworth competition in experimental markets. Econometrica: Journal of the Econometric Society, 343-371." """ class Constants(BaseConstants): players_per_group = 6 name_in_url = 'school_choice' num_rounds = 2 instructions_template = 'school_choice/instructions.html' chosen_round = 2 StudentA = ['student_1', 'student_3', 'student_4'] StudentB = ['student_2', 'student_5', 'student_6'] StudentC = ['student1', 'student3', 'student4'] StudentD = ['student2', 'student5', 'student6'] class Subsession(BaseSubsession): def after_all_players_arrive(self, players): if self.round_number == 1: random.shuffle(players) return players pass class Group(BaseGroup): pass class Player(BasePlayer): major = models.StringField( label='what is your major?' ) age = models.IntegerField(label='What is your age?', min=13, max=125) gender = models.StringField( choices=[['Male', 'Male'], ['Female', 'Female'], ['other', 'other'], ['prefer not to say', 'prefer not to say']], label='What is your gender?', widget=widgets.RadioSelect, ) random_number = models.IntegerField() slider_value = models.IntegerField(min=0, max=100) number = models.IntegerField() chosen_bet = models.CharField( choices=[['A', 'Bet A'], ['B', 'Bet B']], widget=widgets.RadioSelect ) guess_aa = models.IntegerField(min=0, max=100) guess_ab = models.IntegerField(min=0, max=100) guess_am = models.IntegerField(min=0, max=100) guess_ba = models.IntegerField(min=0, max=100) guess_bb = models.IntegerField(min=0, max=100) guess_bm = models.IntegerField(min=0, max=100) belief_a = models.IntegerField() belief_n = models.IntegerField() belief_a1 = models.IntegerField() belief_n1 = models.IntegerField() practice = models.IntegerField(min=0, max=100) none1 = models.BooleanField(blank=True) none2 = models.BooleanField(blank=True) student_1 = models.BooleanField(blank=True) student_2 = models.BooleanField(blank=True) student_3 = models.BooleanField(blank=True) student_4 = models.BooleanField(blank=True) student_5 = models.BooleanField(blank=True) student_6 = models.BooleanField(blank=True) student1 = models.BooleanField(blank=True) student2 = models.BooleanField(blank=True) student3 = models.BooleanField(blank=True) student4 = models.BooleanField(blank=True) student5 = models.BooleanField(blank=True) student6 = models.BooleanField(blank=True) student_1A = models.BooleanField(blank=True) student_4A = models.BooleanField(blank=True) student_5A = models.BooleanField(blank=True) student_6A = models.BooleanField(blank=True) student_4B = models.BooleanField(blank=True) student_5B = models.BooleanField(blank=True) student_6B = models.BooleanField(blank=True) PercentageA = models.IntegerField(label='What is the likelihood of winning E$110 in the lottery?', min=0, max=100) PercentageB = models.IntegerField(label='What is the likelihood of winning E$110 in the lottery?', min=0, max=100) Percentage2 = models.IntegerField(min=0, max=100) belief_a = models.IntegerField() winA = models.IntegerField() belief_b = models.IntegerField() winB = models.IntegerField() # FUNCTIONS def creating_session(subsession: Subsession): subsession.group_randomly(fixed_id_in_group=True) def set_winner(group: Group): all_players = group.get_players() for player in all_players: if player.id_in_group in [1, 2]: player.number_JP = choice([100, 90, 75]) elif player.id_in_group in [3, 4]: player.number_JP = choice([95, 80, 65]) else: player.number_JP = choice([85, 70, 60]) chosen_a = [p for p in all_players if p.chosen_betJP == 'A'] chosen_b = [p for p in all_players if p.chosen_betJP == 'B'] top_a = sorted(chosen_a, key=lambda x: x.number_JP, reverse=True)[:1] top_b = sorted(chosen_b, key=lambda x: x.number_JP, reverse=True)[:1] secondchosen_a = [p for p in all_players if p not in top_a and p not in top_b] top_secondchosen_a = sorted(secondchosen_a, key=lambda x: x.number_JP, reverse=True)[:1] secondchosen_b = [p for p in all_players if p not in top_a and p not in top_b and p not in top_secondchosen_a] top_secondchosen_b = sorted(secondchosen_b, key=lambda x: x.number_JP, reverse=True)[:1] top_guessa1 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab1 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb1 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba1 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa1 = sorted( [p for p in all_players if p not in top_guessa1 and p not in top_guessab1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab1 = sorted( [p for p in all_players if p not in top_guessa1 and p not in top_guessab1 and p not in top_secondguessa1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb1 = sorted( [p for p in all_players if p not in top_guessb1 and p not in top_guessba1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba1 = sorted( [p for p in all_players if p not in top_guessb1 and p not in top_guessba1 and p not in top_secondguessb1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa2 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab2 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb2 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba2 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa2 = sorted( [p for p in all_players if p not in top_guessa2 and p not in top_guessab2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab2 = sorted( [p for p in all_players if p not in top_guessa2 and p not in top_guessab2 and p not in top_secondguessa2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb2 = sorted( [p for p in all_players if p not in top_guessb2 and p not in top_guessba2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba2 = sorted( [p for p in all_players if p not in top_guessb2 and p not in top_guessba2 and p not in top_secondguessb2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa3 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab3 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb3 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba3 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa3 = sorted( [p for p in all_players if p not in top_guessa3 and p not in top_guessab3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab3 = sorted( [p for p in all_players if p not in top_guessa3 and p not in top_guessab3 and p not in top_secondguessa3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb3 = sorted( [p for p in all_players if p not in top_guessb3 and p not in top_guessba3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba3 = sorted( [p for p in all_players if p not in top_guessb3 and p not in top_guessba3 and p not in top_secondguessb3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa4 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab4 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb4 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba4 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa4 = sorted( [p for p in all_players if p not in top_guessa4 and p not in top_guessab4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab4 = sorted( [p for p in all_players if p not in top_guessa4 and p not in top_guessab4 and p not in top_secondguessa4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb4 = sorted( [p for p in all_players if p not in top_guessb4 and p not in top_guessba4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba4 = sorted( [p for p in all_players if p not in top_guessb4 and p not in top_guessba4 and p not in top_secondguessb4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa5 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab5 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb5 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba5 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa5 = sorted( [p for p in all_players if p not in top_guessa5 and p not in top_guessab5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab5 = sorted( [p for p in all_players if p not in top_guessa5 and p not in top_guessab5 and p not in top_secondguessa5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb5 = sorted( [p for p in all_players if p not in top_guessb5 and p not in top_guessba5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba5 = sorted( [p for p in all_players if p not in top_guessb5 and p not in top_guessba5 and p not in top_secondguessb5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa6 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab6 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb6 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba6 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa6 = sorted( [p for p in all_players if p not in top_guessa6 and p not in top_guessab6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab6 = sorted( [p for p in all_players if p not in top_guessa6 and p not in top_guessab6 and p not in top_secondguessa6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb6 = sorted( [p for p in all_players if p not in top_guessb6 and p not in top_guessba6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba6 = sorted( [p for p in all_players if p not in top_guessb6 and p not in top_guessba6 and p not in top_secondguessb6], key=lambda x: x.number_JP, reverse=True)[:1] for player in top_a: player.winA_JP = 10 for player in top_secondchosen_a: player.winA_JP = 10 for player in top_b: player.winB_JP = 7 for player in top_secondchosen_b: player.winB_JP = 7 for player in all_players: if player.id_in_group == 1 and player in top_guessa1: player.belief_a_JP = player.guess_aa elif player.id_in_group == 1 and player in top_secondguessa1: player.belief_a_JP = player.guess_aa elif player.id_in_group == 1 and player in top_secondguessab1: player.belief_a_JP = player.guess_ab elif player.id_in_group == 2 and player in top_guessa2: player.belief_a_JP = player.guess_aa elif player.id_in_group == 2 and player in top_secondguessa2: player.belief_a_JP = player.guess_aa elif player.id_in_group == 2 and player in top_secondguessab2: player.belief_a_JP = player.guess_ab elif player.id_in_group == 3 and player in top_guessa3: player.belief_a_JP = player.guess_aa elif player.id_in_group == 3 and player in top_secondguessa3: player.belief_a_JP = player.guess_aa elif player.id_in_group == 3 and player in top_secondguessab3: player.belief_a_JP = player.guess_ab elif player.id_in_group == 4 and player in top_guessa4: player.belief_a_JP = player.guess_aa elif player.id_in_group == 4 and player in top_secondguessa4: player.belief_a_JP = player.guess_aa elif player.id_in_group == 4 and player in top_secondguessab4: player.belief_a_JP = player.guess_ab elif player.id_in_group == 5 and player in top_guessa5: player.belief_a_JP = player.guess_aa elif player.id_in_group == 5 and player in top_secondguessa5: player.belief_a_JP = player.guess_aa elif player.id_in_group == 5 and player in top_secondguessab5: player.belief_a_JP = player.guess_ab elif player.id_in_group == 6 and player in top_guessa6: player.belief_a_JP = player.guess_aa elif player.id_in_group == 6 and player in top_secondguessa6: player.belief_a_JP = player.guess_aa elif player.id_in_group == 6 and player in top_secondguessab6: player.belief_a_JP = player.guess_ab else: player.belief_a_JP = player.guess_am_JP for player in all_players: if player.id_in_group == 1 and player in top_guessb1: player.belief_b = player.guess_bb elif player.id_in_group == 1 and player in top_secondguessba1: player.belief_b = player.guess_ba elif player.id_in_group == 1 and player in top_secondguessb1: player.belief_b = player.guess_bb elif player.id_in_group == 2 and player in top_guessb2: player.belief_b = player.guess_bb elif player.id_in_group == 2 and player in top_secondguessba2: player.belief_b = player.guess_ba elif player.id_in_group == 2 and player in top_secondguessb2: player.belief_b = player.guess_bb elif player.id_in_group == 3 and player in top_guessb3: player.belief_b = player.guess_bb elif player.id_in_group == 3 and player in top_secondguessba3: player.belief_b = player.guess_ba elif player.id_in_group == 3 and player in top_secondguessb3: player.belief_b = player.guess_bb elif player.id_in_group == 4 and player in top_guessb4: player.belief_b = player.guess_bb elif player.id_in_group == 4 and player in top_secondguessba4: player.belief_b = player.guess_ba elif player.id_in_group == 4 and player in top_secondguessb4: player.belief_b = player.guess_bb elif player.id_in_group == 5 and player in top_guessb5: player.belief_b = player.guess_bb elif player.id_in_group == 5 and player in top_secondguessba5: player.belief_b = player.guess_ba elif player.id_in_group == 5 and player in top_secondguessb5: player.belief_b = player.guess_bb elif player.id_in_group == 6 and player in top_guessb6: player.belief_b = player.guess_bb elif player.id_in_group == 6 and player in top_secondguessba6: player.belief_b = player.guess_ba elif player.id_in_group == 6 and player in top_secondguessb6: player.belief_b = player.guess_bb else: player.belief_b = player.guess_bm_JP def set_payoffs(group: Group): for player in group.get_players(): if player.random_number_JP ==1: player.payoff = player.in_round(1).winA_JP + player.in_round(1).winB_JP elif player.random_number_JP == 2: player.payoff = player.in_round(2).winA_JP + player.in_round(2).winB_JP elif player.random_number_JP == 3: if player.in_round(2).belief_a_JP ==1: player.payoff = player.in_round(2).guess_a_JP else: player.payoff = 100-player.in_round(2).guess_a_JP else: if player.in_round(2).belief_a_JP ==1: player.payoff = player.in_round(2).guess_b_JP else: player.payoff = 100-player.in_round(2).guess_b_JP # PAGES class Introduction(Page): pass class Introduction2(Page): pass class Intro1(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Intro2(Page): form_model = 'player' form_fields = ['student_1', 'student_2', 'student_3','student_4', 'student_5', 'student_6', 'none1', 'none2' ,'student_1A','student_4A','student_5A','student_6A','student_4B','student_5B','student_6B'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 class ChoosingBet(Page): form_model = 'player' form_fields = ['chosen_bet'] class GuessingA(Page): form_model = 'player' form_fields = ['guess_aa','guess_ab','guess_am'] @staticmethod def error_message(player, values): print('values is', values) if values['guess_aa'] + values['guess_ab'] + values['guess_am'] != 100: return 'The numbers must add up to 100' class GuessingB(Page): form_model = 'player' form_fields = ['guess_bb', 'guess_ba', 'guess_bm'] @staticmethod def error_message(player, values): print('values is', values) if values['guess_bb'] + values['guess_ba'] + values['guess_bm'] != 100: return 'The numbers must add up to 100' class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_winner' class Results(Page): @staticmethod def vars_for_template(player: Player): group = player.group all_players = group.get_players() top_a = sorted( [p for p in all_players if p.chosen_betJP == 'A'], key=lambda x: x.number_JP, reverse=True)[:1] top_b = sorted( [p for p in all_players if p.chosen_betJP == 'B'], key=lambda x: x.number_JP, reverse=True)[:1] secondchosen_a = [p for p in all_players if p not in top_a and p not in top_b] top_secondchosen_a = sorted(secondchosen_a, key=lambda x: x.number_JP, reverse=True)[:1] secondchosen_b = [p for p in all_players if p not in top_a and p not in top_b and p not in top_secondchosen_a] top_secondchosen_b = sorted(secondchosen_b, key=lambda x: x.number_JP, reverse=True)[:1] top_guessa1 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab1 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb1 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba1 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa1= sorted( [p for p in all_players if p not in top_guessa1 and p not in top_guessab1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab1= sorted( [p for p in all_players if p not in top_guessa1 and p not in top_guessab1 and p not in top_secondguessa1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb1= sorted( [p for p in all_players if p not in top_guessb1 and p not in top_guessba1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba1= sorted( [p for p in all_players if p not in top_guessb1 and p not in top_guessba1 and p not in top_secondguessb1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa2 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab2 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb2 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba2 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa2= sorted( [p for p in all_players if p not in top_guessa2 and p not in top_guessab2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab2= sorted( [p for p in all_players if p not in top_guessa2 and p not in top_guessab2 and p not in top_secondguessa2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb2= sorted( [p for p in all_players if p not in top_guessb2 and p not in top_guessba2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba2= sorted( [p for p in all_players if p not in top_guessb2 and p not in top_guessba2 and p not in top_secondguessb2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa3 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab3 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb3 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba3 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa3= sorted( [p for p in all_players if p not in top_guessa3 and p not in top_guessab3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab3= sorted( [p for p in all_players if p not in top_guessa3 and p not in top_guessab3 and p not in top_secondguessa3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb3= sorted( [p for p in all_players if p not in top_guessb3 and p not in top_guessba3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba3= sorted( [p for p in all_players if p not in top_guessb3 and p not in top_guessba3 and p not in top_secondguessb3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa4 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab4 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb4 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba4 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa4= sorted( [p for p in all_players if p not in top_guessa4 and p not in top_guessab4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab4= sorted( [p for p in all_players if p not in top_guessa4 and p not in top_guessab4 and p not in top_secondguessa4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb4= sorted( [p for p in all_players if p not in top_guessb4 and p not in top_guessba4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba4= sorted( [p for p in all_players if p not in top_guessb4 and p not in top_guessba4 and p not in top_secondguessb4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa5 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab5 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb5 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba5 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa5= sorted( [p for p in all_players if p not in top_guessa5 and p not in top_guessab5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab5= sorted( [p for p in all_players if p not in top_guessa5 and p not in top_guessab5 and p not in top_secondguessa5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb5= sorted( [p for p in all_players if p not in top_guessb5 and p not in top_guessba5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba5= sorted( [p for p in all_players if p not in top_guessb5 and p not in top_guessba5 and p not in top_secondguessb5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa6 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab6 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb6 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba6 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa6= sorted( [p for p in all_players if p not in top_guessa6 and p not in top_guessab6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab6= sorted( [p for p in all_players if p not in top_guessa6 and p not in top_guessab6 and p not in top_secondguessa6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb6= sorted( [p for p in all_players if p not in top_guessb6 and p not in top_guessba6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba6= sorted( [p for p in all_players if p not in top_guessb6 and p not in top_guessba6 and p not in top_secondguessb6], key=lambda x: x.number_JP, reverse=True)[:1] return { 'top_a': top_a, 'top_b': top_b, 'top_secondchosen_a': top_secondchosen_a, 'top_secondchosen_b': top_secondchosen_b, 'top_guessa1': top_guessa1, 'top_guessb1': top_guessb1, 'top_guessa2': top_guessa2, 'top_guessb2': top_guessb2, 'top_guessa3': top_guessa3, 'top_guessb3': top_guessb3, 'top_guessa4': top_guessa4, 'top_guessb4': top_guessb4, 'top_guessa5': top_guessa5, 'top_guessb5': top_guessb5, 'top_guessa6': top_guessa6, 'top_guessb6': top_guessb6, 'top_secondguessa1': top_secondguessa1, 'top_secondguessab1': top_secondguessab1, 'top_secondguessb1': top_secondguessb1, 'top_secondguessba1': top_secondguessba1, 'top_secondguessa2': top_secondguessa2, 'top_secondguessab2': top_secondguessab2, 'top_secondguessb2': top_secondguessb2, 'top_secondguessba2': top_secondguessba2, 'top_secondguessa3': top_secondguessa3, 'top_secondguessab3': top_secondguessab3, 'top_secondguessb3': top_secondguessb3, 'top_secondguessba3': top_secondguessba3, 'top_secondguessa4': top_secondguessa4, 'top_secondguessab4': top_secondguessab4, 'top_secondguessb4': top_secondguessb4, 'top_secondguessba4': top_secondguessba4, 'top_secondguessa5': top_secondguessa5, 'top_secondguessab5': top_secondguessab5, 'top_secondguessb5': top_secondguessb5, 'top_secondguessba5': top_secondguessba5, 'top_secondguessa6': top_secondguessa6, 'top_secondguessab6': top_secondguessab6, 'top_secondguessb6': top_secondguessb6, 'top_secondguessba6': top_secondguessba6, } pass class Results2nd(Page): @staticmethod def vars_for_template(player: Player): group = player.group all_players = group.get_players() top_a = sorted( [p for p in all_players if p.chosen_betJP == 'A'], key=lambda x: x.number_JP, reverse=True)[:1] top_b = sorted( [p for p in all_players if p.chosen_betJP == 'B'], key=lambda x: x.number_JP, reverse=True)[:1] secondchosen_a = [p for p in all_players if p not in top_a and p not in top_b] top_secondchosen_a = sorted(secondchosen_a, key=lambda x: x.number_JP, reverse=True)[:1] secondchosen_b = [p for p in all_players if p not in top_a and p not in top_b and p not in top_secondchosen_a] top_secondchosen_b = sorted(secondchosen_b, key=lambda x: x.number_JP, reverse=True)[:1] top_guessa1 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab1 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb1 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba1 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa1 = sorted( [p for p in all_players if p not in top_guessa1 and p not in top_guessab1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab1 = sorted( [p for p in all_players if p not in top_guessa1 and p not in top_guessab1 and p not in top_secondguessa1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb1 = sorted( [p for p in all_players if p not in top_guessb1 and p not in top_guessba1], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba1 = sorted( [p for p in all_players if p not in top_guessb1 and p not in top_guessba1 and p not in top_secondguessb1], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa2 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab2 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb2 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba2 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa2 = sorted( [p for p in all_players if p not in top_guessa2 and p not in top_guessab2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab2 = sorted( [p for p in all_players if p not in top_guessa2 and p not in top_guessab2 and p not in top_secondguessa2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb2 = sorted( [p for p in all_players if p not in top_guessb2 and p not in top_guessba2], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba2 = sorted( [p for p in all_players if p not in top_guessb2 and p not in top_guessba2 and p not in top_secondguessb2], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa3 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab3 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb3 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba3 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa3 = sorted( [p for p in all_players if p not in top_guessa3 and p not in top_guessab3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab3 = sorted( [p for p in all_players if p not in top_guessa3 and p not in top_guessab3 and p not in top_secondguessa3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb3 = sorted( [p for p in all_players if p not in top_guessb3 and p not in top_guessba3], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba3 = sorted( [p for p in all_players if p not in top_guessb3 and p not in top_guessba3 and p not in top_secondguessb3], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa4 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab4 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb4 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba4 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa4 = sorted( [p for p in all_players if p not in top_guessa4 and p not in top_guessab4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab4 = sorted( [p for p in all_players if p not in top_guessa4 and p not in top_guessab4 and p not in top_secondguessa4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb4 = sorted( [p for p in all_players if p not in top_guessb4 and p not in top_guessba4], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba4 = sorted( [p for p in all_players if p not in top_guessb4 and p not in top_guessba4 and p not in top_secondguessb4], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa5 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab5 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb5 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba5 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa5 = sorted( [p for p in all_players if p not in top_guessa5 and p not in top_guessab5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab5 = sorted( [p for p in all_players if p not in top_guessa5 and p not in top_guessab5 and p not in top_secondguessa5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb5 = sorted( [p for p in all_players if p not in top_guessb5 and p not in top_guessba5], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba5 = sorted( [p for p in all_players if p not in top_guessb5 and p not in top_guessba5 and p not in top_secondguessb5], key=lambda x: x.number_JP, reverse=True)[:1] top_guessa6 = sorted( [p for p in all_players if p.chosen_betJP == 'A' or p.id_in_group == 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessab6 = sorted( [p for p in all_players if p.chosen_betJP == 'B' and p.id_in_group != 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessb6 = sorted( [p for p in all_players if p.chosen_betJP == 'B' or p.id_in_group == 6], key=lambda x: x.number_JP, reverse=True)[:1] top_guessba6 = sorted( [p for p in all_players if p.chosen_betJP == 'A' and p.id_in_group != 6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessa6 = sorted( [p for p in all_players if p not in top_guessa6 and p not in top_guessab6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessab6 = sorted( [p for p in all_players if p not in top_guessa6 and p not in top_guessab6 and p not in top_secondguessa6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessb6 = sorted( [p for p in all_players if p not in top_guessb6 and p not in top_guessba6], key=lambda x: x.number_JP, reverse=True)[:1] top_secondguessba6 = sorted( [p for p in all_players if p not in top_guessb6 and p not in top_guessba6 and p not in top_secondguessb6], key=lambda x: x.number_JP, reverse=True)[:1] return { 'top_a': top_a, 'top_b': top_b, 'top_secondchosen_a': top_secondchosen_a, 'top_secondchosen_b': top_secondchosen_b, 'top_guessa1': top_guessa1, 'top_guessb1': top_guessb1, 'top_guessa2': top_guessa2, 'top_guessb2': top_guessb2, 'top_guessa3': top_guessa3, 'top_guessb3': top_guessb3, 'top_guessa4': top_guessa4, 'top_guessb4': top_guessb4, 'top_guessa5': top_guessa5, 'top_guessb5': top_guessb5, 'top_guessa6': top_guessa6, 'top_guessb6': top_guessb6, 'top_secondguessa1': top_secondguessa1, 'top_secondguessab1': top_secondguessab1, 'top_secondguessb1': top_secondguessb1, 'top_secondguessba1': top_secondguessba1, 'top_secondguessa2': top_secondguessa2, 'top_secondguessab2': top_secondguessab2, 'top_secondguessb2': top_secondguessb2, 'top_secondguessba2': top_secondguessba2, 'top_secondguessa3': top_secondguessa3, 'top_secondguessab3': top_secondguessab3, 'top_secondguessb3': top_secondguessb3, 'top_secondguessba3': top_secondguessba3, 'top_secondguessa4': top_secondguessa4, 'top_secondguessab4': top_secondguessab4, 'top_secondguessb4': top_secondguessb4, 'top_secondguessba4': top_secondguessba4, 'top_secondguessa5': top_secondguessa5, 'top_secondguessab5': top_secondguessab5, 'top_secondguessb5': top_secondguessb5, 'top_secondguessba5': top_secondguessba5, 'top_secondguessa6': top_secondguessa6, 'top_secondguessab6': top_secondguessab6, 'top_secondguessb6': top_secondguessb6, 'top_secondguessba6': top_secondguessba6, } pass class Payout(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 2 class Intro3(Page): form_model = 'player' class Belief(Page): form_model = 'player' form_fields = ['guess_a', 'guess_b', 'guess_n'] class Belief2(Page): form_model = 'player' form_fields = ['guess_b', 'guess_n'] class Pose(WaitPage): wait_for_all_groups = True @staticmethod def is_displayed(player: Player): if player.round_number == 1: return class Payout1(ResultsWaitPage): after_all_players_arrive = 'set_payoffs' page_sequence = [Intro1, Intro2, Introduction, Introduction2, GuessingA, GuessingB, ChoosingBet, ResultsWaitPage, Results, Results2nd, Pose]