Skip to content
Snippets Groups Projects
Commit e8412515 authored by Felix Blanke's avatar Felix Blanke
Browse files

Add checks for fixed AKs and empty timeslots

parent 3e950346
No related branches found
No related tags found
1 merge request!8Avoid setting the slot duration at import
Pipeline #269232 passed
...@@ -406,6 +406,11 @@ class Event(models.Model): ...@@ -406,6 +406,11 @@ class Event(models.Model):
scheduled_slot["timeslot_ids"] = list(map(int, scheduled_slot["timeslot_ids"])) scheduled_slot["timeslot_ids"] = list(map(int, scheduled_slot["timeslot_ids"]))
slot = AKSlot.objects.get(id=int(scheduled_slot["ak_id"])) slot = AKSlot.objects.get(id=int(scheduled_slot["ak_id"]))
if not scheduled_slot["timeslot_ids"]:
raise ValueError(
_("AK {ak_name} is not assigned any timeslot by the solver").format(ak_name=slot.ak.name)
)
start_timeslot = timeslot_dict[min(scheduled_slot["timeslot_ids"])].avail start_timeslot = timeslot_dict[min(scheduled_slot["timeslot_ids"])].avail
end_timeslot = timeslot_dict[max(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 solver_duration = (end_timeslot.end - start_timeslot.start).total_seconds() / 3600.0
...@@ -422,10 +427,35 @@ class Event(models.Model): ...@@ -422,10 +427,35 @@ class Event(models.Model):
) )
) )
slot.room = Room.objects.get(id=int(scheduled_slot["room_id"])) if slot.fixed:
slot.start = start_timeslot.start solver_room = Room.objects.get(id=int(scheduled_slot["room_id"]))
slot.save() if slot.room != solver_room:
slots_updated += 1 raise ValueError(
_(
"Fixed AK {ak_name} assigned by solver to room {solver_room} "
"is fixed to room {slot_room}"
).format(
ak_name=slot.ak.name,
solver_room=solver_room.name,
slot_room=slot.room.name,
)
)
if slot.start != start_timeslot.start:
raise ValueError(
_(
"Fixed AK {ak_name} assigned by solver to start at {solver_start} "
"is fixed to start at {slot_start}"
).format(
ak_name=slot.ak.name,
solver_start=start_timeslot.start,
slot_start=slot.start,
)
)
else:
slot.room = Room.objects.get(id=int(scheduled_slot["room_id"]))
slot.start = start_timeslot.start
slot.save()
slots_updated += 1
return slots_updated return slots_updated
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment