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 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): 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 ) accept = models.StringField() school_accepted = models.StringField() student1 = models.CharField( choices=[['Student 1', 'Student 1']], widget=widgets.RadioSelect, blank=True, ) student2 = models.CharField( choices=[['Student 2', 'Student 2']], widget=widgets.RadioSelect, blank=True, ) Percentage = models.IntegerField(min=0, max=100) 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() # FUNCTIONS def creating_session(subsession: Subsession): subsession.group_randomly(fixed_id_in_group=True) def set_payoffs(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] if group.subsession.round_number + 1 == Constants.chosen_round: for player in top_a: player.payoff = 10 for player in top_secondchosen_a: player.payoff = 10 for player in top_b: player.payoff = 7 for player in top_secondchosen_b: player.payoff = 7 elif group.subsession.round_number + 20 == Constants.chosen_round: for player in all_players: if player.id_in_group == 1 and player in top_guessa1: player.payoff = player.guess_aa elif player.id_in_group == 1 and player in top_secondguessa1: player.payoff = player.guess_aa elif player.id_in_group == 1 and player in top_secondguessab1: player.payoff = player.guess_ab elif player.id_in_group == 2 and player in top_guessa2: player.payoff = player.guess_aa elif player.id_in_group == 2 and player in top_secondguessa2: player.payoff = player.guess_aa elif player.id_in_group == 2 and player in top_secondguessab2: player.payoff = player.guess_ab elif player.id_in_group == 3 and player in top_guessa3: player.payoff = player.guess_aa elif player.id_in_group == 3 and player in top_secondguessa3: player.payoff = player.guess_aa elif player.id_in_group == 3 and player in top_secondguessab3: player.payoff = player.guess_ab elif player.id_in_group == 4 and player in top_guessa4: player.payoff = player.guess_aa elif player.id_in_group == 4 and player in top_secondguessa4: player.payoff = player.guess_aa elif player.id_in_group == 4 and player in top_secondguessab4: player.payoff = player.guess_ab elif player.id_in_group == 5 and player in top_guessa5: player.payoff = player.guess_aa elif player.id_in_group == 5 and player in top_secondguessa5: player.payoff = player.guess_aa elif player.id_in_group == 5 and player in top_secondguessab5: player.payoff = player.guess_ab elif player.id_in_group == 6 and player in top_guessa6: player.payoff = player.guess_aa elif player.id_in_group == 6 and player in top_secondguessa6: player.payoff = player.guess_aa elif player.id_in_group == 6 and player in top_secondguessab6: player.payoff = player.guess_ab else: player.payoff = player.guess_am_JP elif group.subsession.round_number + 40 == Constants.chosen_round: for player in all_players: if player.id_in_group == 1 and player in top_guessb1: player.payoff = player.guess_bb elif player.id_in_group == 1 and player in top_secondguessba1: player.payoff = player.guess_ba elif player.id_in_group == 1 and player in top_secondguessb1: player.payoff = player.guess_bb elif player.id_in_group == 2 and player in top_guessb2: player.payoff = player.guess_bb elif player.id_in_group == 2 and player in top_secondguessba2: player.payoff = player.guess_ba elif player.id_in_group == 2 and player in top_secondguessb2: player.payoff = player.guess_bb elif player.id_in_group == 3 and player in top_guessb3: player.payoff = player.guess_bb elif player.id_in_group == 3 and player in top_secondguessba3: player.payoff = player.guess_ba elif player.id_in_group == 3 and player in top_secondguessb3: player.payoff = player.guess_bb elif player.id_in_group == 4 and player in top_guessb4: player.payoff = player.guess_bb elif player.id_in_group == 4 and player in top_secondguessba4: player.payoff = player.guess_ba elif player.id_in_group == 4 and player in top_secondguessb4: player.payoff = player.guess_bb elif player.id_in_group == 5 and player in top_guessb5: player.payoff = player.guess_bb elif player.id_in_group == 5 and player in top_secondguessba5: player.payoff = player.guess_ba elif player.id_in_group == 5 and player in top_secondguessb5: player.payoff = player.guess_bb elif player.id_in_group == 6 and player in top_guessb6: player.payoff = player.guess_bb elif player.id_in_group == 6 and player in top_secondguessba6: player.payoff = player.guess_ba elif player.id_in_group == 6 and player in top_secondguessb6: player.payoff = player.guess_bb else: player.payoff = player.guess_bm_JP for player in all_players: if player in top_a or player in top_b: player.accept_JP = 'accepted' else: player.accept_JP = 'rejected' for player in all_players: if player in top_secondchosen_a: player.school_accepted = 'assigned to school A' elif player in top_secondchosen_b: player.school_accepted = 'assigned to school B' else: player.school_accepted = 'no seats assigned' # PAGES class Introduction(Page): pass class Introduction2(Page): pass class Intro1(Page): pass class Intro2(Page): form_model = 'player' form_fields = ['student1','student2'] pass class Intro4(Page): form_model = 'player' form_fields = ['Percentage'] pass class Intro5(Page): pass 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_payoffs' 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 page_sequence = [Intro1, Intro2, Introduction2, Intro4, Intro5, GuessingA, GuessingB, ChoosingBet, ResultsWaitPage, Results, Results2nd, Pose]