def add_form(school_dbn, name) -> Form:

    form = Form()
    form.name = name

    form.save()

    school = Schools.objects(dbn=school_dbn).first()
    school.Form_ids.append(form.id)
    school.save()

    return form
def get_rated_forms_for_school(school_dbn, count) -> List[Form]:
    my_school = Schools.objects(dbn=school_dbn).first()
    print(my_school)
    forms = Form.objects(
        id__in=my_school.Form_ids).all().order_by("-" +
                                                  "avg_score").limit(count)
    return list(forms)
def get_rated_students_for_class(form_id: bson.ObjectId,
                                 count) -> List[Student]:
    my_class = Form.objects(id=form_id).first()
    students = Student.objects(
        id__in=my_class.Student_ids).all().order_by("-" +
                                                    "avg_score").limit(count)
    return list(students)
def add_student(form_id, full_name, sex) -> Student:

    student = Student()
    student.full_name = full_name
    student.sex = sex

    student.save()

    form = Form.objects(id=form_id).first()
    form.Student_ids.append(student.id)
    form.save()

    return student
def update_aver_score_form(form_id) -> Form:

    Form.objects(id=form_id).update(
        avg_score=get_average_score_for_form(form_id))
def get_forms_for_school(school_dbn: bson.ObjectId) -> List[Form]:
    my_school = Schools.objects(dbn=school_dbn).first()
    forms = Form.objects(id__in=my_school.Form_ids).all()

    return forms
def get_average_score_for_school(school_dbn: bson.ObjectId):
    my_school = Schools.objects(dbn=school_dbn).first()
    avg = Form.objects(id__in=my_school.Form_ids).average('avg_score')
    return avg
def get_average_score_for_form(form_id: bson.ObjectId):
    my_form = Form.objects(id=form_id).first()
    avg = Student.objects(id__in=my_form.Student_ids).average('avg_score')
    return avg
def get_students_for_class(class_id: bson.ObjectId) -> List[Student]:
    my_class = Form.objects(id=class_id).first()
    students = Student.objects(id__in=my_class.Student_ids).all()

    return list(students)