Skip to content

Commit

Permalink
rounding the grades
Browse files Browse the repository at this point in the history
  • Loading branch information
Bahar-bn committed Oct 19, 2024
1 parent dfaaf87 commit 82c226b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/spz/administration/admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def edit_grade(course_id):

# ToDo: assign course ects when applicant registers for course
# temporary quickfix
import math

This comment has been minimized.

Copy link
@urvdp

urvdp Oct 20, 2024

Member

Style: import declarations are positioned at the beginning of the .py file

for applicant in course.course_list:
attendance = course.get_course_attendance(course.id, applicant.id)
if attendance.ects_points == 0:
Expand All @@ -268,7 +269,7 @@ def edit_grade(course_id):
attendance = course.get_course_attendance(course.id, applicant.id)
grade_field = getattr(form, f'grade_{applicant.id}', None)
if grade_field and grade_field.data != attendance.grade:
attendance.grade = grade_field.data
attendance.grade = math.ceil(grade_field.data)

This comment has been minimized.

Copy link
@urvdp

urvdp Oct 20, 2024

Member

Wow, you did it according to Frank's mail, which he sent some months ago 👍

changes = True

ects_field_name = f'ects_{applicant.id}'
Expand Down
6 changes: 4 additions & 2 deletions src/spz/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
from flask_wtf import FlaskForm, Form
from flask_login import current_user
from markupsafe import Markup
from wtforms import widgets, StringField, SelectField, SelectMultipleField, IntegerField, Label
from wtforms import widgets, StringField, SelectField, SelectMultipleField, IntegerField,FloatField, Label
from wtforms import TextAreaField, BooleanField, DecimalField, MultipleFileField, FieldList, FormField, HiddenField
from flask_ckeditor import CKEditorField


from wtforms.validators import DataRequired

from spz import app, models, token
Expand Down Expand Up @@ -1103,7 +1105,7 @@ class GradeForm(FlaskForm):
attendance = models.Attendance.query.filter_by(applicant_id=applicant.id, course_id=course_id).first()
field_name = f'grade_{applicant.id}'
setattr(GradeForm, field_name,
IntegerField("Note", validators=[validators.Optional(), validators.NumberRange(min=0, max=100)],
FloatField("Note", validators=[validators.Optional(), validators.NumberRange(min=0, max=100)],
default=attendance.grade))

return GradeForm
Expand Down
4 changes: 3 additions & 1 deletion src/spz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Manages the mapping between abstract entities and concrete database models.
"""
import enum
import math

This comment has been minimized.

Copy link
@urvdp

urvdp Oct 20, 2024

Member

is the math module used in this file?

from enum import Enum
from binascii import hexlify
from datetime import datetime, timedelta
Expand Down Expand Up @@ -104,7 +105,8 @@ class Attendance(db.Model):

ects_points = db.Column(db.Integer, nullable=False, default=0)
# internal representation of the grade is in %
grade = db.Column(db.Integer, nullable=True) # TODO store grade encrypted
grade = db.Column(db.Float, nullable=True) # TODO store grade encrypted

This comment has been minimized.

Copy link
@urvdp

urvdp Oct 20, 2024

Member

Probably python handles this on its own already, but as the grade is stored as a float, also in the conversion table in the full_grade function, the numbers on the left side should be declared as floats (models, line 164).
98 -> integer
98. or 98.0 -> float number


# if a student only wants 'bestanden' instead of the grade value, is set to true
hide_grade = db.Column(db.Boolean, nullable=False, default=False)

Expand Down

0 comments on commit 82c226b

Please sign in to comment.