mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Added final_part_mark calculation in adminSpace
This commit is contained in:
parent
03edae883f
commit
e998839bf1
2 changed files with 53 additions and 1 deletions
|
@ -344,6 +344,8 @@ class PartStudentView(SecureAdminModelView):
|
|||
|
||||
form = EditForm
|
||||
|
||||
column_list = ["student", "part", "group", "final_part_mark", "experiment_marks"]
|
||||
|
||||
column_filters = ["part", "student", "group"]
|
||||
|
||||
def queryFilter(self):
|
||||
|
@ -736,7 +738,14 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
):
|
||||
model.edited_by_admin = True
|
||||
|
||||
return super().update_model(form, model)
|
||||
ret = super().update_model(form, model)
|
||||
|
||||
model.part_student.checkThenSetFinalPartMark()
|
||||
|
||||
return ret
|
||||
else:
|
||||
# Nothing changed
|
||||
return True
|
||||
|
||||
|
||||
class ProgramView(SecureAdminModelView):
|
||||
|
|
|
@ -9,6 +9,7 @@ https://flask-sqlalchemy.palletsprojects.com/en/2.x/models/
|
|||
# Imports
|
||||
from flask import flash, has_request_context
|
||||
from flask_security.models.fsqla_v2 import FsRoleMixin, FsUserMixin
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
# Importing the database instance
|
||||
from advlabdb import db
|
||||
|
@ -74,6 +75,48 @@ class PartStudent(db.Model):
|
|||
self.group = group
|
||||
self.final_part_mark = final_part_mark
|
||||
|
||||
def checkThenSetFinalPartMark(self):
|
||||
finalWeightingSum = 0
|
||||
finalMark = 0
|
||||
groupExperiments = []
|
||||
|
||||
for experimentMark in self.experiment_marks:
|
||||
if not (experimentMark.oral_mark and experimentMark.protocol_mark):
|
||||
return
|
||||
|
||||
groupExperiment = experimentMark.group_experiment
|
||||
groupExperiments.append(groupExperiment)
|
||||
|
||||
experiment = groupExperiment.semester_experiment.experiment
|
||||
|
||||
finalWeighting = experiment.final_weighting
|
||||
finalWeightingSum += finalWeighting
|
||||
|
||||
finalMark += finalWeighting * (
|
||||
experiment.oral_weighting * experimentMark.oral_mark
|
||||
+ experiment.protocol_weighting * experimentMark.protocol_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")
|
||||
return
|
||||
|
||||
oldFinalPartMark = self.final_part_mark
|
||||
|
||||
try:
|
||||
self.final_part_mark = int(
|
||||
Decimal(finalMark / finalWeightingSum).quantize(Decimal(0), rounding=ROUND_HALF_UP)
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
except Exception as ex:
|
||||
flash(str(ex), "error")
|
||||
|
||||
self.session.rollback()
|
||||
else:
|
||||
if oldFinalPartMark != self.final_part_mark:
|
||||
flash(f"Final part mark changed for {self} from {oldFinalPartMark} to {self.final_part_mark}.")
|
||||
|
||||
def repr(self):
|
||||
return f"{self.student.repr()} {self.part.repr()}"
|
||||
|
||||
|
|
Loading…
Reference in a new issue