oTree Forum >

group by gender

#1 by Clairon

Hi , 

In my projet, i have two applications [survey,compet]. In survey, i ask for the participant gender. 
In the app compet, i would like to do group of 6 with 3 men and 3 women. 
I've tried to design a waitingpage as first page of app compet and redefined the groups in the fonction after_all_players_arrive but so far i have a lot of errors.
The code i have for this function is at the end of the message

Best regards, 
Clairon

class test(WaitPage):  

    wait_for_all_groups = True

    @staticmethod
    def after_all_players_arrive(subsession : Subsession): 
        group_men=[]
        group_women=[]
        #Separate two groups men and women 
        for g in subsession.get_groups(): 
            for p in g.get_players():  
                if p.participant.gender == 'Male':
                    p.gender= 'Male'
                    group_men.append(p)
                else :
                    p.gender= 'Female'
                    group_women.append(p)   
        
        group = []

        # Déterminer la longueur de la liste la plus longue
        max_len = max(len(group_men), len(group_women))

        # Parcourir les deux listes simultanément
        for i in range(max_len):
            # Ajouter un élément de la liste des hommes si disponible
            if i < len(group_men):
                group.append(group_men[i])
            # Ajouter un élément de la liste des femmes si disponible
            if i < len(group_women):
                group.append(group_women[i]) 
        nb_group=int(len(group)/C.PLAYERS_PER_GROUP)  
        for i in range(1,2):
            for j in range(1,C.PLAYERS_PER_GROUP+1):
                player=group[(i-1)*C.PLAYERS_PER_GROUP+(j-1)]
                player.id_in_group=j
                player.group.id=i

#2 by ChristianK

Hi Clairon,

Would you mind posting the tracelog / errors you get?


Best,
Christian

Write a reply

Set forum username