diff --git a/advlabdb/models.py b/advlabdb/models.py index 3c9086b..8cfc3b5 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -210,6 +210,21 @@ class Experiment(db.Model): __table_args__ = (db.UniqueConstraint(number, program_id),) + def checkWeightings(self, roundWeightings=False): + roundedOralWeighting = round(self.oral_weighting, 2) + roundedProtocolWeighting = round(self.protocol_weighting, 2) + + weightingSum = round(roundedOralWeighting + roundedProtocolWeighting, 2) + + if weightingSum != 1: + raise DataBaseException( + f"Oral and protocol weighting (rounded to 2 decimal digits) sum to {weightingSum} and not 1.00!" + ) + + if roundWeightings: + self.oral_weighting = roundedOralWeighting + self.protocol_weighting = roundedProtocolWeighting + def repr(self): return f"{self.number} {self.program.repr()}" @@ -381,10 +396,18 @@ class ExperimentMark(db.Model): id = db.Column(db.Integer, primary_key=True) oral_mark = db.Column( - db.Integer, db.CheckConstraint("oral_mark > -1"), db.CheckConstraint("oral_mark < 16"), nullable=True + db.Integer, + db.CheckConstraint("oral_mark > -1"), + db.CheckConstraint("oral_mark < 16"), + default=0.5, + nullable=True, ) protocol_mark = db.Column( - db.Integer, db.CheckConstraint("protocol_mark > -1"), db.CheckConstraint("protocol_mark < 16"), nullable=True + db.Integer, + db.CheckConstraint("protocol_mark > -1"), + db.CheckConstraint("protocol_mark < 16"), + default=0.5, + nullable=True, ) edited_by_admin = db.Column(db.Boolean, default=False, nullable=False)