From 3e950346df4299138ec6f31b0ec67055963af109 Mon Sep 17 00:00:00 2001 From: Felix Blanke <info@fblanke.de> Date: Wed, 22 Jan 2025 16:53:15 +0100 Subject: [PATCH] Add error check for scheduled duration --- AKModel/models.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/AKModel/models.py b/AKModel/models.py index 8831be9..5fc04ff 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -404,18 +404,29 @@ class Event(models.Model): slots_updated = 0 for scheduled_slot in schedule["scheduled_aks"]: scheduled_slot["timeslot_ids"] = list(map(int, scheduled_slot["timeslot_ids"])) + slot = AKSlot.objects.get(id=int(scheduled_slot["ak_id"])) + start_timeslot = timeslot_dict[min(scheduled_slot["timeslot_ids"])].avail end_timeslot = timeslot_dict[max(scheduled_slot["timeslot_ids"])].avail + solver_duration = (end_timeslot.end - start_timeslot.start).total_seconds() / 3600.0 + + if solver_duration + 1e-4 < slot.duration: + raise ValueError( + _( + "Duration of AK {ak_name} assigned by solver ({solver_duration} hours) " + "is less than the duration required by the slot ({slot_duration} hours)" + ).format( + ak_name=slot.ak.name, + solver_duration=solver_duration, + slot_duration=slot.duration, + ) + ) - slot = AKSlot.objects.get(id=int(scheduled_slot["ak_id"])) slot.room = Room.objects.get(id=int(scheduled_slot["room_id"])) slot.start = start_timeslot.start - - solver_duration = (end_timeslot.end - start_timeslot.start).total_seconds() / 3600.0 - assert solver_duration + 1e-4 >= slot.duration - slot.save() slots_updated += 1 + return slots_updated class AKOwner(models.Model): -- GitLab