Batches never split a postcode 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-07 11:59:07 +00:00
parent 80c474b37b
commit 2dd948259f

View file

@ -16,4 +16,18 @@ def pack_postcode_batches(
"""Pack *properties* into batches of ~*batch_size*, never splitting a
postcode across batches. A single postcode larger than *batch_size*
becomes its own oversized batch."""
raise NotImplementedError
groups: dict[str, list[FilteredProperty]] = {}
for prop in properties:
groups.setdefault(prop.postcode or "", []).append(prop)
batches: list[list[FilteredProperty]] = []
current: list[FilteredProperty] = []
for group in groups.values():
if current and len(current) + len(group) > batch_size:
batches.append(current)
current = list(group)
else:
current.extend(group)
if current:
batches.append(current)
return batches