vendredi 17 avril 2020

Assigning people from a list to groups depending on their semester

Heads up, I'm a bloody beginner: This may sound quite trivial to most of you, but I haven't figured out an efficient solution yet. I wanted to write a randomization script to facilitate the process of assigning groups as I have to do this quite often. It should be able to form groups from the participant list that should be random but "evenly distributed", meaning that participants from different semesters should be as equally present in every group as possible.

I had two different ideas to approach this so far: 1) I thought of creating a dictionary containing the participant name and the semester this participant is in. Then I would create groups and append the participants depending on conditions (each group has a max. group number of 5 and should include not more than 2 participants from each semester) and if the condition is not met, the participant is assigned to the next group until every group is full.

2) I thought about creating a list with the names and a number as a combined string (e.g. "2Tom") and shuffle that list while splitting it into subgroups of five that have the conditions to not contain more than two participants of the same semester (which I would check with .startswith("2",0)).

Both of these solutions seem unnecessarily complicated to me. And I have not come very far yet. I've started with the second idea (even though the first one is better, but I'm not familiar with dictionaries yet). I created a list, managed to shuffle it and to split it into groups, but I could not build in the condition with the semesters.

Also, I searched quite a bit already to see if there are already similar questions/solutions on the web, but could not find any that helped me. If you find a solution, please share the link!

Any help is greatly appreciated! I wanted to make my life easier with this script, but so far it has made it only harder haha.

Thank you very much in advance!

This is what I have so far for the second idea:

participants = #list of participants that I do not want to disclose here

def check(participants):

    for people in participants:
        if people.startswith("2",0) == True:
            print("2ndsemester")
        if people.startswith("4",0) == True:
            print("4thsemester")
        if people.startswith("6",0) == True:
            print("6thsemester")

while check(participants):
    np.random.shuffle(participants)

myarray = np.asarray(participants)
groups = np.split(myarray, 5)
print(groups)

The function "check" should ultimately be able to check if the list is equally distributed, but I do not know hot to do that. I was thinking about checking if the consecutive three items contain the same semesters and if so, shuffle. But this solution is not smart, as it would only work if every semester is represented equally in the list, which is not the case.

To simplify the requirements: I want to create a function that can split a list of participants into a desired number of groups and each group should consist of the same amount of participants from each semester (so there is no group that has all the 6th semesters only). I think it might be wiser to use a dictionary than a list.




Aucun commentaire:

Enregistrer un commentaire