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

Add export slot length to event

parent ab8a0014
No related branches found
No related tags found
4 merge requests!262[WIP] compatibility with koma solver import/export,!261[WIP] compatibility with koma solver import/export,!260[WIP] import/export merge,!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.
# Generated by Django 4.2.13 on 2025-02-06 16:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("AKModel", "0060_orga_message_resolved"),
]
operations = [
migrations.AddField(
model_name="event",
name="export_slot",
field=models.DecimalField(
decimal_places=2,
default=1,
help_text="Slot duration in hours that is used in the timeslot discretization, when this event is exported for the solver.",
max_digits=4,
verbose_name="Export Slot Length",
),
),
]
...@@ -151,6 +151,12 @@ class Event(models.Model): ...@@ -151,6 +151,12 @@ class Event(models.Model):
wiki_export_template_name = models.CharField(verbose_name=_("Wiki Export Template Name"), blank=True, max_length=50) wiki_export_template_name = models.CharField(verbose_name=_("Wiki Export Template Name"), blank=True, max_length=50)
default_slot = models.DecimalField(max_digits=4, decimal_places=2, default=2, verbose_name=_('Default Slot Length'), default_slot = models.DecimalField(max_digits=4, decimal_places=2, default=2, verbose_name=_('Default Slot Length'),
help_text=_('Default length in hours that is assumed for AKs in this event.')) help_text=_('Default length in hours that is assumed for AKs in this event.'))
export_slot = models.DecimalField(max_digits=4, decimal_places=2, default=1, verbose_name=_('Export Slot Length'),
help_text=_(
'Slot duration in hours that is used in the timeslot discretization, when this event '
'is exported for the solver.'
))
contact_email = models.EmailField(verbose_name=_("Contact email address"), blank=True, contact_email = models.EmailField(verbose_name=_("Contact email address"), blank=True,
help_text=_("An email address that is displayed on every page " help_text=_("An email address that is displayed on every page "
...@@ -336,7 +342,7 @@ class Event(models.Model): ...@@ -336,7 +342,7 @@ class Event(models.Model):
return slot_index return slot_index
def uniform_time_slots(self, *, slots_in_an_hour: float = 1.0) -> Iterable[TimeslotBlock]: def uniform_time_slots(self, *, slots_in_an_hour: float) -> Iterable[TimeslotBlock]:
"""Uniformly discretize the entire event into blocks of timeslots. """Uniformly discretize the entire event into blocks of timeslots.
Discretizes entire event uniformly. May not necessarily result in a single block Discretizes entire event uniformly. May not necessarily result in a single block
...@@ -358,7 +364,7 @@ class Event(models.Model): ...@@ -358,7 +364,7 @@ class Event(models.Model):
constraints=all_category_constraints, constraints=all_category_constraints,
) )
def default_time_slots(self, *, slots_in_an_hour: float = 1.0) -> Iterable[TimeslotBlock]: def default_time_slots(self, *, slots_in_an_hour: float) -> Iterable[TimeslotBlock]:
"""Discretize all default slots into blocks of timeslots. """Discretize all default slots into blocks of timeslots.
In the discretization each default slot corresponds to one block. In the discretization each default slot corresponds to one block.
...@@ -384,7 +390,7 @@ class Event(models.Model): ...@@ -384,7 +390,7 @@ class Event(models.Model):
constraints=category_constraints, constraints=category_constraints,
) )
def discretize_timeslots(self, *, slots_in_an_hour: float = 1.0) -> Iterable[TimeslotBlock]: def discretize_timeslots(self, *, slots_in_an_hour: float | None = None) -> Iterable[TimeslotBlock]:
""""Choose discretization scheme. """"Choose discretization scheme.
Uses default_time_slots if the event has any DefaultSlot, otherwise uniform_time_slots. Uses default_time_slots if the event has any DefaultSlot, otherwise uniform_time_slots.
...@@ -395,6 +401,9 @@ class Event(models.Model): ...@@ -395,6 +401,9 @@ class Event(models.Model):
:ytype: list of TimeslotBlock :ytype: list of TimeslotBlock
""" """
if slots_in_an_hour is None:
slots_in_an_hour = float(self.export_slot)
if DefaultSlot.objects.filter(event=self).exists(): if DefaultSlot.objects.filter(event=self).exists():
# discretize default slots if they exists # discretize default slots if they exists
yield from merge_blocks(self.default_time_slots(slots_in_an_hour=slots_in_an_hour)) yield from merge_blocks(self.default_time_slots(slots_in_an_hour=slots_in_an_hour))
...@@ -1007,10 +1016,9 @@ class AKSlot(models.Model): ...@@ -1007,10 +1016,9 @@ class AKSlot(models.Model):
ceil_offet_eps = decimal.Decimal(1e-4) ceil_offet_eps = decimal.Decimal(1e-4)
# self.slots_in_an_hour is set in AKJSONExportView
data = { data = {
"id": str(self.pk), "id": str(self.pk),
"duration": math.ceil(self.duration * self.slots_in_an_hour - ceil_offet_eps), "duration": math.ceil(self.duration * self.event.export_slot - ceil_offet_eps),
"properties": { "properties": {
"conflicts": "conflicts":
[str(conflict.pk) for conflict in conflict_slots.all()] [str(conflict.pk) for conflict in conflict_slots.all()]
......
...@@ -91,17 +91,11 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView): ...@@ -91,17 +91,11 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
rooms = Room.objects.filter(event=self.event) rooms = Room.objects.filter(event=self.event)
context["rooms"] = rooms context["rooms"] = rooms
# TODO: Configure magic number in event
SLOTS_IN_AN_HOUR = 1
timeslots = { timeslots = {
"info": {"duration": (1.0 / SLOTS_IN_AN_HOUR), }, "info": {"duration": (1.0 / float(self.event.export_slot)), },
"blocks": [], "blocks": [],
} }
for slot in context["slots"]:
slot.slots_in_an_hour = SLOTS_IN_AN_HOUR
ak_availabilities = { ak_availabilities = {
ak.pk: Availability.union(ak.availabilities.all()) ak.pk: Availability.union(ak.availabilities.all())
for ak in AK.objects.filter(event=self.event).all() for ak in AK.objects.filter(event=self.event).all()
...@@ -115,7 +109,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView): ...@@ -115,7 +109,7 @@ class AKJSONExportView(AdminViewMixin, FilterByEventSlugMixin, ListView):
for person in AKOwner.objects.filter(event=self.event) for person in AKOwner.objects.filter(event=self.event)
} }
blocks = self.event.discretize_timeslots(slots_in_an_hour=SLOTS_IN_AN_HOUR) blocks = self.event.discretize_timeslots()
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