smarter groups

This commit is contained in:
sebastien committed 2026-10-06 11:44:37 +02:00
1 parent ec1645a952
commit 261a50a7d2
2 files changed
+27 -16

No files matched your search

+10 -16
View File
@@ -275,15 +275,7 @@ def _existing_group_state(
def split_batches(rendered):
batches = []
current = []
current_height = 0
def flush() -> None:
nonlocal current, current_height
if current:
batches.append(current)
current = []
current_height = 0
heights = []
index = 0
while index < len(rendered):
@@ -302,15 +294,17 @@ def split_batches(rendered):
f"maximum group height is {MAX_HEIGHT_PX} px."
)
# Consider the student's complete block before adding its first image.
# Otherwise later images from that same student could overflow the batch.
if current and current_height + student_height > MAX_HEIGHT_PX:
flush()
current.extend(student_items)
current_height += student_height
# Reuse space in earlier groups, keeping each student's block intact.
for batch_index, height in enumerate(heights):
if height + student_height <= MAX_HEIGHT_PX:
batches[batch_index].extend(student_items)
heights[batch_index] += student_height
break
else:
batches.append(list(student_items))
heights.append(student_height)
index = end
flush()
return batches