Group by arrival time while preventing participants to be matched with group members from previous app

154 views
Skip to first unread message

tharg...@gmail.com

unread,
Feb 24, 2021, 12:53:16 PM2/24/21
to oTree help & discussion
Dear oTree community,

I have 2 applications where I want to group participants in groups of 3. In both apps, I need 2 participants who were assigned role A and 2 participants who were assigned role B per group.

Roles are assigned in the first app.

In the second app, I would like to rematch them with the same number of As and Bs per group, but I would like to prevent participants to be rematched with their fellow group members from the first app.

I have saved both participants' role and group number into participant.var in the first app like this:

code2.jpg

And this is the code I have so far in the new app:
code.jpg

I just don't know how to use the "group_TG" variable to prevent group member from the previous app to meet again... Any suggestion?

ps: Note that one way to go around it is to put both games in one app, create groups of 9 and then hard code 3 sub-groups for each game, which is something I already did, but then each sub-group has to wait for the two other ones. Hence, I am looking for a way to avoid this to make it more efficient.

Chris @ oTree

unread,
Feb 24, 2021, 2:44:18 PM2/24/21
to oTree help & discussion
The simplest way might be brute force, try different combinations until you find a match:

        if len(a_players) >= 2 and len(b_players) >= 1:
            for a1 in a_players:
                for a2 in a_players:
                    for b in b_players:
                        if a1 != a2:
                            possible_group = [a1, a2, b]
                            group_TGs = [p.participant.vars['group_TG'] for p in possible_group]
                            # set() eliminates duplicates
                            if len(group_TGs) == len(set(group_TGs)):
                                return possible_group
Reply all
Reply to author
Forward
0 new messages