Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def add_score(stud_id, score, subject) -> Score:
    student = Student.objects(id=stud_id).first()
    mscore = Score()
    mscore.name = subject
    mscore.score = score
    mscore.save()
    student.scores_ids.append(mscore.id)
    student.save()
Ejemplo n.º 3
0
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
help(hello.upper)

# Evaluate python code in String format.
print()
command = 'print("Hello")'
eval(command)

# Execute python code in String format (ideal for multiple lines of code).
print()
command = 'print("Hello")'
exec(command)

# Changing data types.
print()
a = 1
print(str(a) + str(a))
print(float(a) + float(a))
print(int(a) + int(a))
print(str(a))
""" OBJECT-ORIENTED PROGRAMMING """
# Class and object
print("\nOBJECT-ORIENTED PROGRAMMING:")
p = Person("Joseph", "Grech", 29)
print("%s %s is %d years old." %
      (p.getFirstName(), p.getLastName(), p.getAge()))

# Inheritance
s = Student("Joseph", "Grech", 29, "Python")
print("%s %s is %d years old, and is reading a %s course." %
      (s.getFirstName(), s.getLastName(), s.getAge(), s.getCourse()))
Ejemplo n.º 5
0
def update_aver_score_student(stud_id) -> Student:

    Student.objects(id=stud_id).update(
        avg_score=get_average_score_for_student(stud_id))
Ejemplo n.º 6
0
def add_district(stud_id) -> Student:
    Student.objects(id=stud_id).update(district=generator.generate_distr())
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
def get_average_score_for_student(student_id: bson.ObjectId):
    my_student = Student.objects(id=student_id).first()
    avg = Score.objects(id__in=my_student.scores_ids).average('score')
    return avg
Ejemplo n.º 9
0
def get_scores_for_student(student_id: bson.ObjectId) -> List[Score]:
    my_student = Student.objects(id=student_id).first()
    scores = Score.objects(id__in=my_student.scores_ids).all()

    return list(scores)
Ejemplo n.º 10
0
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)