oTree Forum >

waitpage is getting executed for allplayer

#1 by rajib_jnu (edited )

waitpage is getting executed for all players but not for the last player.  I am creating an app for match between two groups. Firsly in the subsession, I am creating groups and then trying to randomly match two groups at a time in each subsesion and find out the winner. As my code gave no error but the create_match() was not getting executed properly. Checking, I got the following error (the waitpage is not getting excited for the last player but in all player's URL, it is showing that no more pages left. My full code is:

class C(BaseConstants):
    NAME_IN_URL = 'tullock_group_contest_com_info_NEW'
    PLAYERS_PER_GROUP = 3
    # GROUP_SIZE = 3  # Fixed group size of 3 players
    NUM_ROUNDS = 1
    ENDOWMENT = 60
    PAYOFF_WIN = 100
    PAYOFF_LOSS = 0
    ROLE = ["EGGROLE", "MUTTONROLE"]
    COST_LOW = round(1 / 3, 2)
    COST_HIGH = 1
    VALUE_LOW = 50
    VALUE_HIGH = 100
    UNIT_COST_EFFORT = random.choice([10, 15])
    MULTIPY_FACTOR = 2


class Subsession(BaseSubsession):
    def creating_session(self):
        print(f"DEBUG: creating_session called for round {self.round_number}")
        if self.round_number == 1:
            self.group_randomly(fixed_id_in_group=True)
            print(f"DEBUG: Groups created: {[g.id_in_subsession for g in self.get_groups()]}")
        else:
            self.group_like_round(1)

        self.create_matches()

    def create_matches(self):
        print(f"DEBUG: create_matches called for round {self.round_number}")
        groups = self.get_groups()
        num_groups = len(groups)
        # Randomly shuffle the groups to ensure randomness
        random.shuffle(groups)

        # Now split the groups into matches of 2 groups each
        matches = []
        for i in range(0, len(groups), 2):
            matches.append(groups[i:i + 2])

        # Initialize or update session variable
        self.session.vars['matches'] = {self.round_number: matches}

        # Assign match numbers
        for match_number, match_groups in enumerate(matches, start=1):
            for group in match_groups:
                for player in group.get_players():
                    player.match_number = match_number
                    player.match_groups = [g.id_in_subsession for g in
                                           match_groups]  # Store group IDs for this match


class Group(BaseGroup):
    pass
    
class Player(BasePlayer):
    p_group_type = models.StringField()
    match_number = models.IntegerField()
    match_groups = models.StringField()
    
class Welcome3(Page):
    @staticmethod
    def is_displayed(player: Player):
        print(f"DEBUG: Welcome3 is_displayed for Player {player.id_in_group}")
        return player.round_number == 1
        
class ResultsWaitPage0(WaitPage):
    wait_for_all_groups = True

    @staticmethod
    def before_next_page(subsession: Subsession):
        print("DEBUG: ResultsWaitPage0 - before_next_page method called.")
        subsession.create_matches()
        
page_sequence = [Welcome3,
                 ResultsWaitPage0]                


I think create_match() is not getting executed for this error. Why is this strange error happening? I am attaching a screenshot of the monitor tab settings.

Rajib

#2 by rajib_jnu

Instead of self , I used subsession, but the same problem persists.

#3 by Daniel_Frey

before_next_page does not work on a WaitPage, use after_all_players_arrive instead: https://otree.readthedocs.io/en/latest/multiplayer/waitpages.html#after-all-players-arrive

Write a reply

Set forum username