Example #1
0
def generate_students(number_of_students=None):
    if number_of_students is None:
        number_of_students = random.randint(1, School.MAX_STUDENTS_NUMBER)

    students = []
    for student_number in range(number_of_students):
        first_name = f"Student-{student_number +1}"
        last_name = "Smith"
        student = Student(first_name, last_name)
        students.append(student)
        for _ in range(Config.RANDOM_FINAL_GRADES_NUMBER):
            final_grade = random.randint(Config.MIN_RANDOM_GRADE, Config.MAX_RANDOM_GRADE)
            student.add_final_grade(final_grade)
    return students
def generate_students(number_of_students=None):
    if number_of_students is None:
        number_of_students = random.randint(1, School.MAX_STUDENTS_NUMBER)

    students = []
    for student_number in range(number_of_students):
        first_name, last_name = generate_random_name()
        student = Student(first_name, last_name)
        students.append(student)
        subjects = ["Matematyka", "Fizyka", "Biologia", "Chemia", "Historia"]
        for subject in subjects:
            final_grade = random.randint(MIN_RANDOM_GRADE, MAX_RANDOM_GRADE)
            student.add_final_grade(final_grade, subject)
    return students
Example #3
0
    def create_school_with_students(cls, school_name):
        number_of_students = random.randint(1, cls.MAX_STUDENTS_NUMBER)
        school = School(school_name, students=[])

        for student_number in range(number_of_students):
            first_name = f"Student-{student_number}"
            last_name = "Smith"
            student = Student(first_name, last_name)
            school.assign_student(student)
            for _ in range(Config.RANDOM_FINAL_GRADES_NUMBER):
                final_grade = random.randint(Config.MIN_RANDOM_GRADE,
                                             Config.MAX_RANDOM_GRADE)
                student.add_final_grade(final_grade)

        return school
Example #4
0
 def generate_students(self):
     students = []
     for student_number in range(self.number_of_students):
         first_name = f"Student-{student_number}"
         last_name = "Smith"
         student = Student(first_name, last_name)
         students.append(student)
         subjects = [
             "Matematyka", "Fizyka", "Biologia", "Chemia", "Historia"
         ]
         for subject in subjects:
             final_grade = random.randint(Config.MIN_RANDOM_GRADE,
                                          Config.MAX_RANDOM_GRADE)
             student.add_final_grade(final_grade, subject)
     return students
Example #5
0
    def generate_students(self):
        if self.min_grade is None or self.max_grade is None:
            return "ERROR"

        students = []
        for student_number in range(self.number_of_students):
            first_name = f"Student-{student_number}"
            last_name = "Smith"
            student = Student(first_name, last_name)
            students.append(student)
            subjects = [
                "Matematyka", "Fizyka", "Biologia", "Chemia", "Historia"
            ]
            for subject in subjects:
                final_grade = random.randint(self.min_grade, self.max_grade)
                student.add_final_grade(final_grade, subject)
        return students
Example #6
0
def test_add_final_grades():
    parameters = [
        (5, "Matematyka", None, True),
        (5, "Historia", None, True),
        (1, "Matematyka", None, True),
        (5, "Matematyka", GradeCalculator.normal_promotion_policy, True),
        (2, "Matematyka", GradeCalculator.strict_promotion_policy, False),
    ]

    for params in parameters:
        grade, subject, promotion_policy, promoted = params
        student = Student("Bob", "Kowalski")
        student.add_final_grade(grade, subject, promotion_policy)

        if student.promoted == promoted:
            print("OK")
        else:
            print(f"Błąd! Dla parametrów: {params} wynik promocji to {student.promoted} zamiast {promoted}")
Example #7
0
def create_school_with_students(school_name):
    number_of_students = random.randint(1, 20)
    students = []
    for student_number in range(number_of_students):
        first_name = f"Student-{student_number}"
        last_name = "Smith"
        students.append(Student(first_name, last_name))

    school = School(school_name, students)
    return school
Example #8
0
def run_example():
    school = School.create_school_with_students("Hogwart")
    harry = Student(first_name="Harry", last_name="Potter")
    school.assign_student(harry)
    print(school)

    new_school = school.create_school_with_students("New School")

    print(school.MAX_STUDENTS_NUMBER)
    print(new_school.MAX_STUDENTS_NUMBER)
Example #9
0
def load_students_from_csv(file_name="students.csv"):
    with open(file_name, newline="") as students_file:
        csv_reader = csv.reader(students_file)
        next(csv_reader)
        return [
            Student.from_csv(
                first_name=row[0],
                last_name=row[1],
                promoted=str_to_bool(row[2]),
                grades_values=[int(value) for value in row[3].split(",")])
            for row in csv_reader
        ]
Example #10
0
    def load_students(self, use_cache=True):
        if use_cache and self.cached_students:
            return self.cached_students
        else:
            with open(self.file_name, mode="r") as students_file:
                students_data = json.load(students_file).get("students", [])

                self.cached_students = [
                    Student.from_json(**student_data, )
                    for student_data in students_data
                ]
                return self.cached_students
Example #11
0
 def load_students(self, use_cache=True):
     if use_cache and self.cached_students:
         return self.cached_students
     else:
         with open(self.file_name, newline="") as students_file:
             csv_reader = csv.reader(students_file)
             self.cached_headers = next(csv_reader)
             self.cached_students = [
                 Student.from_csv(first_name=row[0],
                                  last_name=row[1],
                                  promoted=conversion.str_to_bool(row[2]),
                                  grades_values=[
                                      int(value)
                                      for value in row[3].split(",")
                                  ]) for row in csv_reader
             ]
             return self.cached_students
Example #12
0
 def load_students(self, use_cache=True):
     if use_cache and self.cached_students:
         return self.cached_students
     else:
         with open(self.file_name, newline="") as students_file:
             csv_reader = csv.DictReader(students_file)
             self.cached_headers = csv_reader.fieldnames
             self.cached_students = [
                 Student.from_csv(
                     first_name=row["first_name"],
                     last_name=row["last_name"],
                     promoted=conversion.str_to_bool(row["promoted"]),
                     grades_values=[
                         int(value)
                         for value in row["final_grades"].split(",")
                     ]) for row in csv_reader
             ]
             return self.cached_students