oTree Forum >

WaitPage waiting for wrong players

#1 by hdstudent

Hello everyone,

I have created an experiment with multiple apps. Players get grouped by arrival time on the second app and then have another waitpage on the third app. However, on this page they no longer wait for the players they were grouped with, but instead wait for the two players that would march if you grouped by player ids (id 1,2 and 3 or 4,5,6 would be grouped, without grouping by arrival time).

Does someone know how I can let them wait for the players they were grouped with?

Thank you a lot for your help!

#2 by Chris_oTree

See gbat_keep_same_groups in otree-snippets: https://www.otreehub.com/projects/?featured=1

#3 by lindaaldehoff

I tried this, but I think tree doesn't recognize group.id 

I get this error message:

IntegrityError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (sqlite3.IntegrityError) FOREIGN KEY constraint failed [SQL: UPDATE "Endogen_part3_player" SET group_id=? WHERE "Endogen_part3_player".id = ?] [parameters: (28, 58)] (Background on this error at: http://sqlalche.me/e/13/gkpj)

How do I correctly define group id? I did it like this:

class Grouping(WaitPage):
   group_by_arrival_time = True
   	 def after_all_players_arrive(self):
        for player in self.group.get_players():
            participant = player.participant
            group = player.group
            participant.vars['group_id'] = group.id

class ResultsWaitPage2(WaitPage):
	group_by_arrival_time = True
	def vars_for_template(self):
    	self.player.group_id = self.player.participant.vars['group_id']	
class Subsession(BaseSubsession):    
	def group_by_arrival_time_method(self, waiting_players):
        d = {}
        for player in waiting_players:
            group_id = player.participant.vars['group_id']
            # print(f'''Current waiting player has group_id: {group_id}''')
            if group_id not in d:
                d[group_id] = []
            players_in_my_group = d[group_id]
            # print(f'''Players in my group: {players_in_my_group}''')
            # print(f'''Players in my group 3: {players_in_my_group}''')
            if len(players_in_my_group) == 3:
                return players_in_my_group
 Thank you!

#4 by lindaaldehoff

Hi again,

thank you Chris, the grouping method worked! However, the participants don't keep their id in group which is crucial for my experiment. Do you or does anyone else know how to group by arrival time with fixed ids in group when the last group is from a previous app?
I know that you can do it with group randomly, but I don't want players to be waiting too long.

Thank you for your help!

#5 by Daniel_Frey

Maybe you can use the participant-IDs in the session instead of the id in the group? They don't change, I think.

Write a reply

Set forum username