def __readAssignments(self):
     '''
     Class method to read the assignments from the text file
     and return a list of elements of their type.
     '''
     file = open(self.__fileName, "r")
     content = file.readlines()
     assignments = IterableStructure()
     for line in content:
         line.strip()
         line = line.replace('\n', '')
         line = line.split(';')
         assignments.append(Assignment(int(line[0]), line[1], line[2]))
     file.close()
     return assignments
 def __readStudents(self):
     '''
     Class method to read the students from a file. 
     This method will form a list of objects of type Student and return it.
     '''
     file = open(self.__fileName, "r")
     content = file.readlines()
     students = IterableStructure()
     for line in content:
         line.strip()
         line = line.replace('\n', '')
         line = line.split(';')
         students.append(Student(int(line[0]), line[1], line[2]))
     file.close()
     return students
Ejemplo n.º 3
0
 def __readGrades(self):
     '''
     Class method that reads the grades from the text file
     '''
     file = open(self.__fileName, "r")
     content = file.readlines()
     grades = IterableStructure()
     for line in content:
         line.strip()
         line = line.replace('\n', '')
         line = line.split(';')
         student = self.__fileRepoStudents.searchByID(int(line[1]))
         assignment = self.__fileRepoAssignments.searchByID(int(line[0]))
         grades.append(Grade(assignment, student, float(line[2])))
     file.close()
     return grades
Ejemplo n.º 4
0
 def __init__(self):
     '''
     class init for the repository
     '''
     self.__grades = IterableStructure()
Ejemplo n.º 5
0
class RepoGrades(object):
    '''
    Class for the grades repository
    '''
    def __init__(self):
        '''
        class init for the repository
        '''
        self.__grades = IterableStructure()

    def __len__(self):
        '''
        returns the length (number of grades) of grades
        '''
        return len(self.__grades)

    def add(self, element):
        '''
        class function for adding an element into the repository
        in - element - element to be added
        out: - 
        raises: RepoError if the element already exists
        '''
        if element in self.__grades:
            raise RepoError("Element already exists!")
        self.__grades.append(element)

    def search(self, element):
        '''
        class function to search for an element in grades
        in - element - element which is being searched 
        out: element if it's found 
        raises: RepoError otherwise, if the element doesn't exist
        '''
        if element not in self.__grades:
            raise RepoError("Element doesn't exist!")
        for grades in self.__grades:
            if element == grades:
                return element

    def update(self, element):
        '''
        class function to update an element in grades
        in: element- element which is being updated
        out: NoneType if that happens
        raises: RepoError otherwise, if it doesn't exist
        '''
        if element not in self.__grades:
            raise RepoError("Element doesn't exist!")
        for i in range(len(self.__grades)):
            if self.__grades[i] == element:
                self.__grades[i] = element
                return

    def remove(self, element):
        '''
        class function to remove an element from grades
        in : element- element which is being deleted
        out- NoneType if that happens
        raises: RepoError otherwise, if it doesn't exist
        '''
        if element not in self.__grades:
            raise RepoError("Element doesn't exist!")
        for i in range(len(self.__grades)):
            if self.__grades[i] == element:
                del self.__grades[i]
                return

    def removeStudentID(self, studentID):
        '''
        Class function to remove the element with the student id = studentID from the grades repository
        '''
        for i in range(len(self.__grades)):
            if self.__grades[i].getStudentID() == studentID:
                del self.__grades[i]
                return

    def removeAssignmentID(self, assignmentID):
        '''
        Class function to remove the element with the assignment id = assignmentID from the grades repository
        '''
        for i in range(len(self.__grades)):
            if self.__grades[i].getAssignmentID() == assignmentID:
                del self.__grades[i]
                return

    def getAll(self):
        '''
        class function to get all the grades
        '''
        returnList = []
        for i in range(0, len(self.__grades)):
            returnList.append(self.__grades[i])
        return returnList[:]
class RepoStudents(object):
    '''
    Class for the student repository
    '''
    def __init__(self):
        '''
        class init for the repository
        '''
        self.__students = IterableStructure()

    def __len__(self):
        '''
        returns the length (number of students) of students
        '''
        return len(self.__students)

    def add(self, element):
        '''
        class function for adding an element into the repository
        in - element - element to be added
        out: - 
        raises: RepoError if the element already exists
        '''
        if element in self.__students:
            raise RepoError("Element already exists!")
        self.__students.append(element)

    def searchByID(self, id):
        '''
        class function to search for an element in students
        in - element - element which is being searched 
        out: element if it's found 
        raises: RepoError otherwise, if the element doesn't exist
        '''
        for students in self.__students:
            if students.getID() == id:
                return students
        raise RepoError("ELement doesnt exist!")

    def update(self, element):
        '''
        class function to update an element in students
        in: element- element which is being updated
        out: NoneType if that happens
        raises: RepoError otherwise, if it doesn't exist
        '''
        if element not in self.__students:
            raise RepoError("Element doesn't exist!")
        for i in range(len(self.__students)):
            if self.__students[i] == element:
                self.__students[i] = element
                return

    def remove(self, element):
        '''
        class function to remove an element from students
        in : element- element which is being deleted
        out- NoneType if that happens
        raises: RepoError otherwise, if it doesn't exist
        '''
        if element not in self.__students:
            raise RepoError("Element doesn't exist!")
        for i in range(len(self.__students)):
            if self.__students[i] == element:
                del self.__students[i]
                return

    def getAll(self):
        '''
        class function to get all the students
        '''
        returnList = []
        for i in range(0, len(self.__students)):
            returnList.append(self.__students[i])
        return returnList[:]