Skip to content
Snippets Groups Projects

Expand block info in JSON export

Merged Felix Blanke requested to merge feature/block-info-json-export into main
2 files
+ 150
64
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -248,7 +248,7 @@ class JSONExportTest(TestCase):
@@ -248,7 +248,7 @@ class JSONExportTest(TestCase):
)
)
self.assertEqual(
self.assertEqual(
self.export_dict["timeslots"]["info"].keys(),
self.export_dict["timeslots"]["info"].keys(),
{"duration"},
{"duration", "blocknames"},
"timeslot info keys not as expected",
"timeslot info keys not as expected",
)
)
self._check_type(
self._check_type(
@@ -257,6 +257,21 @@ class JSONExportTest(TestCase):
@@ -257,6 +257,21 @@ class JSONExportTest(TestCase):
"info/duration",
"info/duration",
item=item,
item=item,
)
)
 
self._check_lst(
 
self.export_dict["timeslots"]["info"]["blocknames"],
 
"info/blocknames",
 
item=item,
 
contained_type=list,
 
)
 
for blockname in self.export_dict["timeslots"]["info"]["blocknames"]:
 
self.assertEqual(len(blockname), 2)
 
self._check_lst(
 
blockname,
 
"info/blocknames/entry",
 
item=item,
 
contained_type=str,
 
)
 
self._check_lst(
self._check_lst(
self.export_dict["timeslots"]["blocks"],
self.export_dict["timeslots"]["blocks"],
"blocks",
"blocks",
@@ -710,72 +725,120 @@ class JSONExportTest(TestCase):
@@ -710,72 +725,120 @@ class JSONExportTest(TestCase):
self.set_up_event(event=event)
self.set_up_event(event=event)
cat_avails = self._get_cat_availability()
cat_avails = self._get_cat_availability()
for timeslot in chain.from_iterable(
num_blocks = len(self.export_dict["timeslots"]["blocks"])
 
for block_idx, block in enumerate(
self.export_dict["timeslots"]["blocks"]
self.export_dict["timeslots"]["blocks"]
):
):
start, end = self._get_timeslot_start_end(timeslot)
for timeslot in block:
timeslot_avail = Availability(
start, end = self._get_timeslot_start_end(timeslot)
event=self.event, start=start, end=end
timeslot_avail = Availability(
)
event=self.event, start=start, end=end
)
fulfilled_time_constraints = set()
# reso deadline
fulfilled_time_constraints = set()
if self.event.reso_deadline is not None:
# timeslot ends before deadline
# reso deadline
if end < self.event.reso_deadline.astimezone(
if self.event.reso_deadline is not None:
self.event.timezone
# timeslot ends before deadline
):
if end < self.event.reso_deadline.astimezone(
fulfilled_time_constraints.add("resolution")
self.event.timezone
):
# add category constraints
fulfilled_time_constraints.add("resolution")
fulfilled_time_constraints |= (
AKCategory.create_category_constraints(
# add category constraints
[
fulfilled_time_constraints |= (
cat
AKCategory.create_category_constraints(
for cat in AKCategory.objects.filter(
[
event=self.event
cat
).all()
for cat in AKCategory.objects.filter(
if timeslot_avail.is_covered(cat_avails[cat.name])
event=self.event
]
).all()
 
if timeslot_avail.is_covered(cat_avails[cat.name])
 
]
 
)
)
)
)
# add owner constraints
# add owner constraints
fulfilled_time_constraints |= {
fulfilled_time_constraints |= {
f"availability-person-{owner.id}"
f"availability-person-{owner.id}"
for owner in AKOwner.objects.filter(event=self.event).all()
for owner in AKOwner.objects.filter(event=self.event).all()
if self._is_restricted_and_contained_slot(
if self._is_restricted_and_contained_slot(
timeslot_avail,
timeslot_avail,
Availability.union(owner.availabilities.all()),
Availability.union(owner.availabilities.all()),
 
)
 
}
 
 
# add room constraints
 
fulfilled_time_constraints |= {
 
f"availability-room-{room.id}"
 
for room in self.rooms
 
if self._is_restricted_and_contained_slot(
 
timeslot_avail,
 
Availability.union(room.availabilities.all()),
 
)
 
}
 
 
# add ak constraints
 
fulfilled_time_constraints |= {
 
f"availability-ak-{ak.id}"
 
for ak in AK.objects.filter(event=event)
 
if self._is_restricted_and_contained_slot(
 
timeslot_avail,
 
Availability.union(ak.availabilities.all()),
 
)
 
}
 
fulfilled_time_constraints |= {
 
f"fixed-akslot-{slot.id}"
 
for slot in self.ak_slots
 
if self._is_ak_fixed_in_slot(slot, timeslot_avail)
 
}
 
 
fulfilled_time_constraints |= {
 
f"notblock{idx}"
 
for idx in range(num_blocks)
 
if idx != block_idx
 
}
 
 
self.assertEqual(
 
fulfilled_time_constraints,
 
set(timeslot["fulfilled_time_constraints"]),
)
)
}
def test_timeslots_info(self):
# add room constraints
"""Test timeslots info dict"""
fulfilled_time_constraints |= {
for event in Event.objects.all():
f"availability-room-{room.id}"
with self.subTest(event=event):
for room in self.rooms
self.set_up_event(event=event)
if self._is_restricted_and_contained_slot(
timeslot_avail,
self.assertAlmostEqual(
Availability.union(room.availabilities.all()),
self.export_dict["timeslots"]["info"]["duration"],
 
float(self.event.export_slot),
 
)
 
 
block_names = []
 
for block in self.export_dict["timeslots"]["blocks"]:
 
if not block:
 
continue
 
 
block_start, _ = self._get_timeslot_start_end(block[0])
 
_, block_end = self._get_timeslot_start_end(block[-1])
 
 
start_day = block_start.strftime("%A, %d. %b")
 
if block_start.date() == block_end.date():
 
# same day
 
time_str = (
 
block_start.strftime("%H:%M")
 
+ ""
 
+ block_end.strftime("%H:%M")
)
)
}
else:
# different days
# add ak constraints
time_str = (
fulfilled_time_constraints |= {
block_start.strftime("%a %H:%M")
f"availability-ak-{ak.id}"
+ ""
for ak in AK.objects.filter(event=event)
+ block_end.strftime("%a %H:%M")
if self._is_restricted_and_contained_slot(
timeslot_avail, Availability.union(ak.availabilities.all())
)
)
}
block_names.append([start_day, time_str])
fulfilled_time_constraints |= {
self.assertEqual(
f"fixed-akslot-{slot.id}"
block_names, self.export_dict["timeslots"]["info"]["blocknames"]
for slot in self.ak_slots
)
if self._is_ak_fixed_in_slot(slot, timeslot_avail)
}
self.assertEqual(
fulfilled_time_constraints,
set(timeslot["fulfilled_time_constraints"]),
)
Loading