Skip to content
Snippets Groups Projects
Commit e0801c1f authored by Lorenzo Conti's avatar Lorenzo Conti
Browse files

Merge branch 'feature/encapsulate_discretization_choice' into 'main'

Encapsulate discretization in Event::discretize_timeslots

See merge request !7
parents aee5627c f1d4a9ee
No related branches found
No related tags found
5 merge requests!262[WIP] compatibility with koma solver import/export,!261[WIP] compatibility with koma solver import/export,!260[WIP] import/export merge,!237Draft: add tests on json export,!235Merge fork for interoperability of KoMa solver
This commit is part of merge request !235. Comments created here will be created in the context of that merge request.
...@@ -382,6 +382,23 @@ class Event(models.Model): ...@@ -382,6 +382,23 @@ class Event(models.Model):
constraints=category_constraints, constraints=category_constraints,
) )
def discretize_timeslots(self, *, slots_in_an_hour: float = 1.0) -> Iterable[TimeslotBlock]:
""""Choose discretization scheme.
Uses default_time_slots if the event has any DefaultSlot, otherwise uniform_time_slots.
:param slots_in_an_hour: The percentage of an hour covered by a single slot.
Determines the discretization granularity.
:yield: Block of optimizer timeslots as the discretization result.
:ytype: list of TimeslotBlock
"""
if DefaultSlot.objects.filter(event=self).exists():
# discretize default slots if they exists
yield from merge_blocks(self.default_time_slots(slots_in_an_hour=slots_in_an_hour))
else:
yield from self.uniform_time_slots(slots_in_an_hour=slots_in_an_hour)
def schedule_from_json(self, schedule: str) -> None: def schedule_from_json(self, schedule: str) -> None:
"""Load AK schedule from a json string. """Load AK schedule from a json string.
...@@ -396,7 +413,7 @@ class Event(models.Model): ...@@ -396,7 +413,7 @@ class Event(models.Model):
timeslot_dict = { timeslot_dict = {
timeslot.idx: timeslot timeslot.idx: timeslot
for block in merge_blocks(self.default_time_slots(slots_in_an_hour=slots_in_an_hour)) for block in self.discretize_timeslots(slots_in_an_hour=slots_in_an_hour)
for timeslot in block for timeslot in block
} }
......
...@@ -9,7 +9,7 @@ from django.views.generic import ListView, DetailView ...@@ -9,7 +9,7 @@ from django.views.generic import ListView, DetailView
from AKModel.availability.models import Availability from AKModel.availability.models import Availability
from AKModel.metaviews.admin import AdminViewMixin, FilterByEventSlugMixin, EventSlugMixin, IntermediateAdminView, \ from AKModel.metaviews.admin import AdminViewMixin, FilterByEventSlugMixin, EventSlugMixin, IntermediateAdminView, \
IntermediateAdminActionView IntermediateAdminActionView
from AKModel.models import AKRequirement, AKSlot, DefaultSlot, Event, AKOrgaMessage, AK, Room, AKOwner, merge_blocks from AKModel.models import AKRequirement, AKSlot, Event, AKOrgaMessage, AK, Room, AKOwner
class AKRequirementOverview(AdminViewMixin, FilterByEventSlugMixin, ListView): class AKRequirementOverview(AdminViewMixin, FilterByEventSlugMixin, ListView):
...@@ -114,11 +114,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView): ...@@ -114,11 +114,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
if (values := AKSlot.objects.select_related().filter(ak__pk=ak_id, fixed=True)).exists() if (values := AKSlot.objects.select_related().filter(ak__pk=ak_id, fixed=True)).exists()
} }
if DefaultSlot.objects.filter(event=self.event).exists(): blocks = self.event.discretize_timeslots(slots_in_an_hour=SLOTS_IN_AN_HOUR)
# discretize default slots if they exists
blocks = merge_blocks(self.event.default_time_slots(slots_in_an_hour=SLOTS_IN_AN_HOUR))
else:
blocks = self.event.uniform_time_slots(slots_in_an_hour=SLOTS_IN_AN_HOUR)
for block in blocks: for block in blocks:
current_block = [] current_block = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment