<kaggle_start><code># # Project Assignment Problem Statement
# * There are S students, P projects, and each project should have at least R students ( R < S/P)
# * Each student rank orders at most K (K < P, for example K = 5) projects according to their preferences
# * After a student is assigned to a project, the quality of assignment from that student’s perspective is Q ( 1 <= Q <= K). Lower the Q, better it is for the student
# * We want low class-wise average Q so that the performance is good at the class lever
# * We also want a low variance in class wise Q so that the assignment is fairer
# local file path stuff (skip if need be)
import os

for dirname, _, filenames in os.walk("/kaggle/input"):
    for filename in filenames:
        # print(os.path.join(dirname, filename))
        pass

# ### Main Classroom obj to deal with manipulation
import collections


class Classroom:
    def __init__(self, P, S, R, K):
        self.P, self.S, self.K, self.R, self.Q = P, S, K, R, -1
        self.projects = collections.OrderedDict()
        self.students = collections.OrderedDict()

    def generate_data(self):
        """Generates mock project and random student preferences based on P,S,K values"""
        for i in range(0, self.P):
            proj_name = ""
            if i > 25:
                temp = i
                while temp >= 0:
                    proj_name = chr(ord("a") + (temp % 26)) + proj_name
                    temp = int(temp / 26) - 1
                print(proj_name)
            else:
                proj_name = chr(ord("a") + i)
            self.projects[proj_name] = []
        for i in range(0, self.S):
            sname = "s" + str(i)
            import random

            assignments = random.sample(range(self.P), self.K)
            items = list(self.projects.items())
            preferences = []
            for n in assignments:
                preferences.append(items[n][0])
            self.students[sname] = {"Preferences": preferences, "Q": -1}

    def pretty_print(self, only_projects=False):
        print("\nProjects and Assignments")
        for project in self.projects:
            print("project: %s %s" % (project, self.projects[project]))
        if not only_projects:
            print("\nStudents and Preferences")
            for student in self.students:
                print(
                    "%s, pref: %s, Q: %s"
                    % (
                        student,
                        self.students[student]["Preferences"],
                        self.students[student]["Q"],
                    )
                )

    def assign_1(self):
        # iterate through each project, for each project find best candidate student
        # check remaining projects to see if students fits with better project
        pass


# ## Approach 1
classroom = Classroom(P=13, S=65, R=5, K=5)
classroom.generate_data()
classroom.pretty_print()
<|endoftext|>
[{"Id": 42613117, "ScriptId": 11715103, "ParentScriptVersionId": NaN, "ScriptLanguageId": 9, "AuthorUserId": 1892767, "CreationDate": "09/13/2020 22:09:58", "VersionNumber": 1.0, "Title": "project assignment", "EvaluationDate": "09/13/2020", "IsChange": true, "TotalLines": 70.0, "LinesInsertedFromPrevious": 70.0, "LinesChangedFromPrevious": 0.0, "LinesUnchangedFromPrevious": 0.0, "LinesInsertedFromFork": NaN, "LinesDeletedFromFork": NaN, "LinesChangedFromFork": NaN, "LinesUnchangedFromFork": NaN, "TotalVotes": 1}]
# # Project Assignment Problem Statement
# * There are S students, P projects, and each project should have at least R students ( R < S/P)
# * Each student rank orders at most K (K < P, for example K = 5) projects according to their preferences
# * After a student is assigned to a project, the quality of assignment from that student’s perspective is Q ( 1 <= Q <= K). Lower the Q, better it is for the student
# * We want low class-wise average Q so that the performance is good at the class lever
# * We also want a low variance in class wise Q so that the assignment is fairer
# local file path stuff (skip if need be)
import os

for dirname, _, filenames in os.walk("/kaggle/input"):
    for filename in filenames:
        # print(os.path.join(dirname, filename))
        pass

# ### Main Classroom obj to deal with manipulation
import collections


class Classroom:
    def __init__(self, P, S, R, K):
        self.P, self.S, self.K, self.R, self.Q = P, S, K, R, -1
        self.projects = collections.OrderedDict()
        self.students = collections.OrderedDict()

    def generate_data(self):
        """Generates mock project and random student preferences based on P,S,K values"""
        for i in range(0, self.P):
            proj_name = ""
            if i > 25:
                temp = i
                while temp >= 0:
                    proj_name = chr(ord("a") + (temp % 26)) + proj_name
                    temp = int(temp / 26) - 1
                print(proj_name)
            else:
                proj_name = chr(ord("a") + i)
            self.projects[proj_name] = []
        for i in range(0, self.S):
            sname = "s" + str(i)
            import random

            assignments = random.sample(range(self.P), self.K)
            items = list(self.projects.items())
            preferences = []
            for n in assignments:
                preferences.append(items[n][0])
            self.students[sname] = {"Preferences": preferences, "Q": -1}

    def pretty_print(self, only_projects=False):
        print("\nProjects and Assignments")
        for project in self.projects:
            print("project: %s %s" % (project, self.projects[project]))
        if not only_projects:
            print("\nStudents and Preferences")
            for student in self.students:
                print(
                    "%s, pref: %s, Q: %s"
                    % (
                        student,
                        self.students[student]["Preferences"],
                        self.students[student]["Q"],
                    )
                )

    def assign_1(self):
        # iterate through each project, for each project find best candidate student
        # check remaining projects to see if students fits with better project
        pass


# ## Approach 1
classroom = Classroom(P=13, S=65, R=5, K=5)
classroom.generate_data()
classroom.pretty_print()
