1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-02 22:33:05 +00:00

Avoid rounding two times

This commit is contained in:
Mo 2022-08-18 17:39:40 +02:00
parent dd91e12fba
commit 7f3797719d

View file

@ -113,7 +113,7 @@ class PartStudent(db.Model):
Return True if final_part_mark changed, False otherwise.
"""
finalWeightingSum = 0
finalMark = 0
finalMarkSum = 0
groupExperiments = []
for experimentMark in self.experiment_marks:
@ -138,7 +138,11 @@ class PartStudent(db.Model):
finalWeighting = semesterExperiment.final_weighting
finalWeightingSum += finalWeighting
finalMark += finalWeighting * experimentMark.final_experiment_mark
# Not using final_experiment_mark to avoid rounding two times
finalMarkSum += finalWeighting * (
semesterExperiment.protocol_weighting * experimentMark.protocol_mark
+ semesterExperiment.oral_weighting * experimentMark.oral_mark
)
if set(groupExperiments) != set(self.group.group_experiments):
flash(f"{self} does not have an experiment mark for every group experiment in his group!", "warning")
@ -147,7 +151,7 @@ class PartStudent(db.Model):
oldFinalPartMark = self.final_part_mark
try:
self.final_part_mark = roundHalfUpToInt(finalMark / finalWeightingSum)
self.final_part_mark = roundHalfUpToInt(finalMarkSum / finalWeightingSum)
db.session.commit()
except Exception as ex: