def _check_init_params(transcript_id, group_id, name, surname, patronymic): if group_id is not None: if len(transcript_id) != 6: raise LoadCsvError("The transcript number must be equal to 6.") if len(group_id) > 5: raise LoadCsvError("The group id cannot contain more than 5 characters.") if len(name) > 24: raise LoadCsvError("The name cannot contain more than 24 characters.") if len(surname) > 27: raise LoadCsvError("The surname cannot contain more than 27 characters.") if len(patronymic) > 20: raise LoadCsvError("The patronymic cannot contain more than 20 characters.")
def _covert_variables(self): try: self._total_points = int(self._total_points) self._mark = int(self._mark) self._exam_points = int(self._exam_points) except ValueError: raise LoadCsvError( "Some of the fields can't be converted in .csv file.")
def _check_points_type(total_points, mark, exam_points): try: int(total_points) int(mark) int(exam_points) except ValueError: raise LoadCsvError( "The subject mark, total points, and exam points must be an integer." )
def _check_points(total_points, mark, exam_points): Subject._check_points_type(total_points, mark, exam_points) semester_points = total_points - exam_points if not (0 <= mark <= 5): raise LoadCsvError( "The subject mark cannot be out of range (0, 5).") if not (0 <= semester_points <= 60): raise LoadCsvError( "The number of subject semester points cannot be out of range (0, 60)." ) if not (24 <= exam_points <= 40): if exam_points == 0 and mark > 2: raise LoadCsvError( "The subject mark cannot be higher than 2 when the subject exam points equal to 0." ) else: raise LoadCsvError( "The number of subject exam points cannot be out of range (24, 40) " "or not be equal to 0.") mark_correct = Subject._convert_points2mark(total_points) if mark not in mark_correct: raise LoadCsvError( "The number of subject points and subject mark match each other." )
def _process_current_line(self): if len(self._line) != 0: if len(self._line) != 9: raise LoadCsvError( "The .csv file contains an invalid number of fields.") else: self._transcript_id = self._line[0] self._mark = self._line[1] self._subject_name = self._line[2] self._patronymic = self._line[3] self._exam_points = self._line[4] self._surname = self._line[5] self._name = self._line[6] self._total_points = self._line[7] self._group_id = self._line[8] self._covert_variables()
class Information: """ This class contains a list of students and some additional information about them Attributes: mark_sum (int): marks sum excellent_count (int): number of "excellent" marks """ def __init__(self): self._students = [] self._mark_sum = 0 self._excellent_count = 0 def load(self, transcript_id, group_id, name, surname, patronymic, subject_name, total_points, mark, exam_points): """ Load information about the student and subject Parameters: transcript_id (str): transcript number group_id (str): student group name (str): student name surname (str): student surname patronymic (str): student patronymic subject_name (str): name of the subject total_points (int): subject points (max - 100) mark (int): subject mark (max - 5) exam_points (int): subject exam points (max - 40) """ if (student := self.find(transcript_id)) is None: student = self.add(transcript_id, group_id, name, surname, patronymic) elif not (student.group_id == group_id and student.name == name and student.surname == surname and student.patronymic == patronymic): raise LoadCsvError("Inconsistent information in .csv file.")
def _check_subject_name(subject_name): if len(subject_name) > 53: raise LoadCsvError( "The subject name cannot contain more than 53 characters.")